Skip to content

Commit

Permalink
New Simple Items for Civilizations #104
Browse files Browse the repository at this point in the history
- pickaxe of greed
  • Loading branch information
frodare committed Feb 1, 2017
1 parent e35dc81 commit e513f22
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
76 changes: 76 additions & 0 deletions java/net/torocraft/toroquest/item/ItemPickaxeOfGreed.java
Original file line number Diff line number Diff line change
@@ -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<ItemStack> 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));
}
}

}
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 @@ -18,6 +18,7 @@ public static final void init() {
ItemReinforcedDiamondArmor.init();
ItemSamuraiArmor.init();
ItemBattleAxe.init();
ItemPickaxeOfGreed.init();
}

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

}
2 changes: 2 additions & 0 deletions resources/assets/toroquest/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e513f22

Please sign in to comment.