From 897ce41ac24a014173089b5c184d6eabf250dae9 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 19 Oct 2018 23:11:50 +0200 Subject: [PATCH] make the hoe give you seeds randomly --- .../naturesaura/items/tools/ItemHoeNA.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemHoeNA.java b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemHoeNA.java index 02759445..582452a6 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemHoeNA.java +++ b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemHoeNA.java @@ -1,9 +1,20 @@ package de.ellpeck.naturesaura.items.tools; +import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModelProvider; import de.ellpeck.naturesaura.reg.ModRegistry; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; import net.minecraft.item.ItemHoe; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @@ -18,6 +29,33 @@ public class ItemHoeNA extends ItemHoe implements IModItem, IModelProvider { ModRegistry.addItemOrBlock(this); } + @Override + public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + EnumActionResult result = super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); + if (!worldIn.isRemote && result == EnumActionResult.SUCCESS && this == ModItems.INFUSED_HOE) { + ItemStack seed = ItemStack.EMPTY; + + if (worldIn.rand.nextInt(5) == 0) { + seed = ForgeHooks.getGrassSeed(worldIn.rand, 0); + } else if (worldIn.rand.nextInt(10) == 0) { + int rand = worldIn.rand.nextInt(3); + if (rand == 0) { + seed = new ItemStack(Items.MELON_SEEDS); + } else if (rand == 1) { + seed = new ItemStack(Items.PUMPKIN_SEEDS); + } else if (rand == 2) { + seed = new ItemStack(Items.BEETROOT_SEEDS); + } + } + + if (!seed.isEmpty()) { + EntityItem item = new EntityItem(worldIn, pos.getX() + worldIn.rand.nextFloat(), pos.getY() + 1F, pos.getZ() + worldIn.rand.nextFloat(), seed); + worldIn.spawnEntity(item); + } + } + return result; + } + @Override public String getBaseName() { return this.baseName;