Posted July 11, 201510 yr Hello, I am having a little bit of trouble with the following code, I am trying to make a seed plantable on farmland which works fine if I specify which block is suppose to be placed directly in the main seedPlacement class however I would like to use this class as a reference for future seeds and so I wish to use a variable to assign the block. However the variable is never assigned because it is never called in my constructor. And I am currently out of ideas what to try. Any help will be much appreciated! Regards, Venomous The seed item class: public class ItemLettuceSeeds extends seedPlacement{ public ItemLettuceSeeds() { super(0, 0.3f, RealismMod.blockLettuceCrop, Blocks.farmland); } } The main seed class: public class seedPlacement extends ItemFood implements IPlantable { private final Block theBlockPlant; private final Block soilId; public seedPlacement(int parHealAmount, float parSaturationModifier, Block parBlockPlant, Block parSoilBlock) { super(parHealAmount, parSaturationModifier, false); theBlockPlant = parBlockPlant; //not getting assigned soilId = parSoilBlock; //not getting assigned } //constructor isn't even being called @Override public boolean onItemUse(ItemStack parItemStack, EntityPlayer parPlayer, World parWorld, int parX, int parY, int parZ, int par7, float par8, float par9, float par10) { // not sure what this parameter does, copied it from the potato class if (par7 != 1) { return false; } else if (parPlayer.canPlayerEdit(parX, parY+1, parZ, par7, parItemStack)) { System.out.println("Result: " + theBlockPlant + " and " + soilId); //Result: Null and Null if (parWorld.getBlock(parX, parY, parZ).canSustainPlant(parWorld, parX, parY, parZ, ForgeDirection.UP, this) && parWorld .isAirBlock(parX, parY+1, parZ)) { //crashes cause null pointer exception since theBlockPlant is never assigned. //parWorld.setBlock(parX, parY+1, parZ, theBlockPlant); --parItemStack.stackSize; return true; } else { return false; } } else { return false; } } When in doubt, use brute force.
July 11, 201510 yr Author Oh wow, you're right.. It works now. I didn't think it would affect it, thanks! [solved] When in doubt, use brute force.
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.