Skip to content

Commit

Permalink
New Simple Items for Civilizations #104
Browse files Browse the repository at this point in the history
- sword of pain
  • Loading branch information
frodare committed Feb 1, 2017
1 parent dfec68f commit 899a689
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
56 changes: 56 additions & 0 deletions java/net/torocraft/toroquest/item/ItemSwordOfPain.java
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);
}
}
2 changes: 2 additions & 0 deletions java/net/torocraft/toroquest/item/ToroQuestItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static final void init() {
ItemSamuraiArmor.init();
ItemBattleAxe.init();
ItemPickaxeOfGreed.init();
ItemSwordOfPain.init();
}

@SideOnly(Side.CLIENT)
Expand All @@ -32,6 +33,7 @@ public static final void registerRenders() {
ItemFireSword.registerRenders();
ItemBattleAxe.registerRenders();
ItemPickaxeOfGreed.registerRenders();
ItemSwordOfPain.registerRenders();
}

}
1 change: 1 addition & 0 deletions resources/assets/toroquest/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ item.toro_armor_chestplate.name=Toro Chestplate
item.toro_leather.name=Toro Leather
item.torch_arrow.name=Torch Arrow
item.pickaxe_of_greed.name=Pickaxe of Greed
item.sword_of_pain.name=Sword of Pain

effect.toroquest\:royalty=Royalty
potion.effect.toroquest\:royalty=Potion of Royalty
Expand Down

0 comments on commit 899a689

Please sign in to comment.