From e513f22afbf2a19734482489f64241f1b10ec385 Mon Sep 17 00:00:00 2001 From: Charles Howard Date: Tue, 31 Jan 2017 21:22:12 -0500 Subject: [PATCH] New Simple Items for Civilizations #104 - pickaxe of greed --- .../toroquest/item/ItemPickaxeOfGreed.java | 76 +++++++++++++++++++ .../toroquest/item/ToroQuestItems.java | 2 + resources/assets/toroquest/lang/en_US.lang | 2 + 3 files changed, 80 insertions(+) create mode 100644 java/net/torocraft/toroquest/item/ItemPickaxeOfGreed.java diff --git a/java/net/torocraft/toroquest/item/ItemPickaxeOfGreed.java b/java/net/torocraft/toroquest/item/ItemPickaxeOfGreed.java new file mode 100644 index 0000000..2fe84af --- /dev/null +++ b/java/net/torocraft/toroquest/item/ItemPickaxeOfGreed.java @@ -0,0 +1,76 @@ +package net.torocraft.toroquest.item; + +import java.util.List; +import java.util.Random; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemPickaxe; +import net.minecraft.item.ItemStack; +import net.minecraft.stats.Achievement; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.registry.GameRegistry; +import net.torocraft.toroquest.ToroQuest; + +public class ItemPickaxeOfGreed extends ItemPickaxe { + + public static Achievement JACKPOT_ACHIEVEMNT = new Achievement("jackpot", "jackpot", 0, 0, Items.IRON_PICKAXE, null).registerStat(); + + public static ItemPickaxeOfGreed INSTANCE; + public static final String NAME = "pickaxe_of_greed"; + + public static void init() { + INSTANCE = new ItemPickaxeOfGreed(); + 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_pickaxe", "inventory")); + } + + public ItemPickaxeOfGreed() { + super(Item.ToolMaterial.IRON); + setUnlocalizedName(NAME); + } + + @SubscribeEvent + public void onHarvest(HarvestDropsEvent event) { + if (thisToolWasUsed(event)) { + alterDrops(event.getWorld().rand, event.getDrops(), event.getHarvester()); + } + } + + private boolean thisToolWasUsed(HarvestDropsEvent event) { + return event.getHarvester() != null && event.getHarvester().getHeldItemMainhand() != null + && event.getHarvester().getHeldItemMainhand().getItem() == INSTANCE && !event.getWorld().isRemote; + } + + private void alterDrops(Random rand, List drops, EntityPlayer player) { + + if (drops.size() < 1) { + return; + } + + ItemStack stack = drops.get(0); + int count = stack.getCount(); + + if (rand.nextInt(2) == 0) { + player.addStat(JACKPOT_ACHIEVEMNT); + stack.setCount(stack.getMaxStackSize()); + } else if (rand.nextInt(10) == 0) { + stack.setCount(count + (rand.nextInt(3) + 3)); + } else { + drops.clear(); + drops.add(new ItemStack(Items.COAL, count)); + } + } + +} diff --git a/java/net/torocraft/toroquest/item/ToroQuestItems.java b/java/net/torocraft/toroquest/item/ToroQuestItems.java index 98a56c2..f066a4b 100644 --- a/java/net/torocraft/toroquest/item/ToroQuestItems.java +++ b/java/net/torocraft/toroquest/item/ToroQuestItems.java @@ -18,6 +18,7 @@ public static final void init() { ItemReinforcedDiamondArmor.init(); ItemSamuraiArmor.init(); ItemBattleAxe.init(); + ItemPickaxeOfGreed.init(); } @SideOnly(Side.CLIENT) @@ -30,6 +31,7 @@ public static final void registerRenders() { ItemObsidianSword.registerRenders(); ItemFireSword.registerRenders(); ItemBattleAxe.registerRenders(); + ItemPickaxeOfGreed.registerRenders(); } } diff --git a/resources/assets/toroquest/lang/en_US.lang b/resources/assets/toroquest/lang/en_US.lang index 839b983..7b6049a 100644 --- a/resources/assets/toroquest/lang/en_US.lang +++ b/resources/assets/toroquest/lang/en_US.lang @@ -7,6 +7,7 @@ achievement.bounty_hunter=Bounty Hunter achievement.bastion=Bastion Slayer achievement.mage=Mage Slayer achievement.village_lord=King Slayer +achievement.jackpot=Jackpot! item.obsidian_sword.name=Obsidian Sword item.fire_sword.name=Fire Sword item.diamond_battle_axe.name=Diamond Battle Axe @@ -28,6 +29,7 @@ item.toro_armor_leggings.name=Toro Leggings 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 effect.toroquest\:royalty=Royalty potion.effect.toroquest\:royalty=Potion of Royalty