Posted December 27, 20159 yr I am working on a mod and I wan't a plant to drop both the seeds and the fruit Here is my code for the get item dropped [embed=425,349]@Override public Item getItemDropped(int parMetadata, Random parRand, int parFortune) { return (RA_Items.itemSpinachSeeds); } [/embed] How would I make it return the itemSpinachSeeds and an ItemSpinach?
December 27, 20159 yr Author I replaced the previous code with @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> drops = new ArrayList<ItemStack>(); drops.add(new ItemStack(RA_Items.itemSpinachSeeds, world.rand.nextInt(3) + 1)); drops.add(new ItemStack(RA_Items.itemSpinach, 1)); return drops; } however now it doesn't drop anything. I am missing something?
December 27, 20159 yr Author public class BlockSpinachPlant extends BlockCrops { public String name = "BlockSpinachPlant"; //basic block properties public BlockSpinachPlant() { this.setBlockName(name); } @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> drops = new ArrayList<ItemStack>(); drops.add(new ItemStack(RA_Items.itemSpinachSeeds, world.rand.nextInt(3) + 1)); drops.add(new ItemStack(RA_Items.itemSpinach, 1)); return drops; } @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister parIIconRegister) { iIcon = new IIcon[maxGrowthStage+1]; // seems that crops like to have 8 growth icons, but okay to repeat actual texture if you want // to make generic should loop to maxGrowthStage iIcon[0] = parIIconRegister.registerIcon("ra:Coffee_stage_0"); iIcon[1] = parIIconRegister.registerIcon("ra:Coffee_stage_1"); iIcon[2] = parIIconRegister.registerIcon("ra:Coffee_stage_2"); iIcon[3] = parIIconRegister.registerIcon("ra:Coffee_stage_3"); iIcon[4] = parIIconRegister.registerIcon("ra:Coffee_stage_4"); iIcon[5] = parIIconRegister.registerIcon("ra:Coffee_stage_5"); iIcon[6] = parIIconRegister.registerIcon("ra:Coffee_stage_6"); iIcon[7] = parIIconRegister.registerIcon("ra:Coffee_stage_7"); } } and here is the BlockCrops class it implements public class BlockCrops extends BlockBush implements IGrowable { protected int maxGrowthStage = 7; @SideOnly(Side.CLIENT) protected IIcon[] iIcon; public BlockCrops() { // Basic block setup setTickRandomly(true); float f = 0.5F; setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f); setCreativeTab(null); setHardness(0.0F); setStepSound(soundTypeGrass); disableStats(); } public boolean isOpaqueCube() { return false; // stops x-ray vision } //is the block grass, dirt or farmland @Override protected boolean canPlaceBlockOn(Block parBlock) { return parBlock == Blocks.farmland; } public void incrementGrowStage(World parWorld, Random parRand, int parX, int parY, int parZ) { int growStage = parWorld.getBlockMetadata(parX, parY, parZ) + MathHelper.getRandomIntegerInRange(parRand, 2, 5); if (growStage > maxGrowthStage) { growStage = maxGrowthStage; } parWorld.setBlockMetadataWithNotify(parX, parY, parZ, growStage, 2); } @Override public Item getItemDropped(int metadata, Random parRand, int parFortune) { return Item.getItemFromBlock(this); } // The type of render function that is called for this block @Override public int getRenderType() { return 1; // Cross like flowers } //Gets the block's texture. Args: side, meta @Override @SideOnly(Side.CLIENT) public IIcon getIcon(int parSide, int parGrowthStage) { return iIcon[parGrowthStage]; } //grows automatically after a random amount of ticks @Override public void updateTick(World parWorld, int parX, int parY, int parZ, Random parRand) { super.updateTick(parWorld, parX, parY, parZ, parRand); int growStage = parWorld.getBlockMetadata(parX, parY, parZ) + 1; if (growStage > 7) { growStage = 7; } parWorld.setBlockMetadataWithNotify(parX, parY, parZ, growStage, 2); } // checks if finished growing (a grow stage of 7 is final stage) @Override public boolean func_149851_a(World world, int parX, int parY, int parZ, boolean allowed) { return world.getBlockMetadata(parX, parY, parZ) != 7; //checks if bonemeal is allowed } @Override public boolean func_149852_a(World world, Random parRand, int parX, int parY, int parZ) { return true; } @Override public void func_149853_b(World world, Random rand, int parX, int parY, int parZ) { incrementGrowStage(world, rand, parX, parY, parZ); } /* func_149851_a returns true if bonemeal is allowed, false otherwise. func_149852_a returns true at the same time bonemeal is used if conditions for a growth-tick are acceptable. func_149853_b processes the actual growth-tick logic, which is usually increasing metadata or replacing the block. */ @Override public boolean canBlockStay (World world, int x, int y, int z) { Block soil = world.getBlock(x, y - 1, z); return (world.getFullBlockLightValue(x, y, z) >= 8 || world.canBlockSeeTheSky(x, y, z)) && (soil != null && soil.canSustainPlant(world, x, y - 1, z, ForgeDirection.UP, (IPlantable) RA_Items.itemCoffeeBeans)); } }
December 27, 20159 yr Author I am. Here is the code. public final class RA_Blocks { public static final Block blockCoffeePlant = new BlockCoffeePlant(); public static final Block blockSpinachPlant = new BlockSpinachPlant(); public static void initBlocks() { GameRegistry.registerBlock(blockCoffeePlant, blockCoffeePlant.getUnlocalizedName().substring(5)); GameRegistry.registerBlock(blockSpinachPlant, blockSpinachPlant.getUnlocalizedName().substring(5)); } }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.