-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Simple Items for Civilizations #104
- sword of pain
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package net.torocraft.toroquest.item; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.block.model.ModelResourceLocation; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemSword; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.event.entity.living.LivingHurtEvent; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.registry.GameRegistry; | ||
import net.torocraft.toroquest.ToroQuest; | ||
|
||
public class ItemSwordOfPain extends ItemSword { | ||
|
||
public static ItemSwordOfPain INSTANCE; | ||
|
||
public static final String NAME = "sword_of_pain"; | ||
|
||
public static void init() { | ||
INSTANCE = new ItemSwordOfPain(); | ||
GameRegistry.register(INSTANCE, new ResourceLocation(ToroQuest.MODID, NAME)); | ||
MinecraftForge.EVENT_BUS.register(INSTANCE); | ||
} | ||
|
||
public static void registerRenders() { | ||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(INSTANCE, 0, | ||
new ModelResourceLocation("minecraft:iron_sword", "inventory")); | ||
} | ||
|
||
public ItemSwordOfPain() { | ||
super(ToolMaterial.IRON); | ||
setUnlocalizedName(NAME); | ||
} | ||
|
||
@SubscribeEvent | ||
public void onHurt(LivingHurtEvent event) { | ||
if (thisToolWasUsed(event)) { | ||
alterDamage(event); | ||
} | ||
} | ||
|
||
private boolean thisToolWasUsed(LivingHurtEvent event) { | ||
if (event.getSource() == null || !(event.getSource().getEntity() instanceof EntityPlayer)) { | ||
return false; | ||
} | ||
EntityPlayer player = (EntityPlayer) event.getSource().getEntity(); | ||
return player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() == INSTANCE; | ||
} | ||
|
||
private void alterDamage(LivingHurtEvent event) { | ||
float amount = event.getAmount(); | ||
event.setAmount(amount * 2); | ||
event.getSource().getEntity().attackEntityFrom(event.getSource(), amount / 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters