Jump to content

GXyon

Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by GXyon

  1. Thanks for the lead! Asked around a little bit how to properly use it, and seems to be working like a charm! Here's the code for anyone else that could find use in it: package gxyon.gyrmod.items; import net.minecraft.block.Block; import net.minecraft.block.BlockCrops; import net.minecraft.block.BlockDirt; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; public class GyrScytheProperties extends ItemSword{ public GyrScytheProperties(Item.ToolMaterial material) { super(material); } @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn) { IBlockState blockState = worldIn.getBlockState(pos); if(!worldIn.isRemote){ boolean result = true; if (blockState.getBlock() == Blocks.wheat && (Integer)blockState.getValue(BlockCrops.AGE) >= 6) { worldIn.spawnEntityInWorld(new EntityItem(worldIn, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, new ItemStack(Items.wheat, 5))); worldIn.spawnEntityInWorld(new EntityItem(worldIn, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, new ItemStack(Items.wheat_seeds, 1))); worldIn.destroyBlock(pos, false); } else { result = super.onBlockDestroyed(stack, worldIn, blockIn, pos, playerIn); } return result; } return false; } [snip: hoe functions] } Thanks for the help!
  2. Right, sorry! I want the condition to be applied when the item breaks a fully matute wheat block. I'm looking to find a way to get the blockstate and add it to the preexisting condition.
  3. I suppose that'd be a good start! I've tried to use IBlockState before, but I'll be honest as have no idea how to work with it, as most tutorials I've seen around are either somewhat vague or are simply over my head; I've reverted the code to somewhat working order which is why there's no trace of it now. Apologies if these things are supposed to be obvious from a standpoint.
  4. Hey all! I'll admit I'm relatively new to modding MC as well as learning Java as I go, so do please excuse if I fumble about. I'm attempting to use a condition only if the Blockstate of a crop hits "7" (messing around with Wheat specifically, wanting it to only work when it's full-grown). I managed to get the Wheat part down and got the condition to work without the comparison, however I've no idea how to implement Blockstates into comparisons as it always errors me out. package gxyon.gyrmod.items; import net.minecraft.block.Block; import net.minecraft.block.BlockCrops; import net.minecraft.block.BlockDirt; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; public class GyrScytheProperties extends ItemSword{ public GyrScytheProperties(Item.ToolMaterial material) { super(material); } public boolean canHarvestBlock(Block blockIn) { return blockIn == Blocks.wheat; } @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn) { if(!worldIn.isRemote){ boolean result = true; if (blockIn == Blocks.wheat) //Here's where I want to insert the second part of the comparison { worldIn.spawnEntityInWorld(new EntityItem(worldIn, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, new ItemStack(Items.wheat, 5))); worldIn.spawnEntityInWorld(new EntityItem(worldIn, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, new ItemStack(Items.wheat_seeds, 1))); worldIn.destroyBlock(pos, false); } else { result = super.onBlockDestroyed(stack, worldIn, blockIn, pos, playerIn); } return result; } return false; } public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { if (!playerIn.canPlayerEdit(pos.offset(side), side, stack)) { return false; } else { int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(stack, playerIn, worldIn, pos); if (hook != 0) return hook > 0; IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (side != EnumFacing.DOWN && worldIn.isAirBlock(pos.up())) { if (block == Blocks.grass) { return this.useHoe(stack, playerIn, worldIn, pos, Blocks.farmland.getDefaultState()); } if (block == Blocks.dirt) { switch (GyrScytheProperties.SwitchDirtType.TYPE_LOOKUP[((BlockDirt.DirtType)iblockstate.getValue(BlockDirt.VARIANT)).ordinal()]) { case 1: return this.useHoe(stack, playerIn, worldIn, pos, Blocks.farmland.getDefaultState()); case 2: return this.useHoe(stack, playerIn, worldIn, pos, Blocks.dirt.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT)); } } } return false; } } protected boolean useHoe(ItemStack stack, EntityPlayer player, World worldIn, BlockPos target, IBlockState newState) { worldIn.playSoundEffect((double)((float)target.getX() + 0.5F), (double)((float)target.getY() + 0.5F), (double)((float)target.getZ() + 0.5F), newState.getBlock().stepSound.getStepSound(), (newState.getBlock().stepSound.getVolume() + 1.0F) / 2.0F, newState.getBlock().stepSound.getFrequency() * 0.8F); if (worldIn.isRemote) { return true; } else { worldIn.setBlockState(target, newState); stack.damageItem(1, player); return true; } } static final class SwitchDirtType { static final int[] TYPE_LOOKUP = new int[blockDirt.DirtType.values().length]; private static final String __OBFID = "CL_00002179"; static { try { TYPE_LOOKUP[blockDirt.DirtType.DIRT.ordinal()] = 1; } catch (NoSuchFieldError var2) { ; } try { TYPE_LOOKUP[blockDirt.DirtType.COARSE_DIRT.ordinal()] = 2; } catch (NoSuchFieldError var1) { ; } } } I tried to muck around with AGE from the BlockCrops class file, but no dice either; the item works just as intended otherwise. Any help would be appreciated! Thanks!
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.