1

NEED HELP: Changing a block to another

DovydasAL 1/11/15 5:17 pm
218
Hey guys so I've got an item that on right click should change grass to farmland, and put wheat on top. On further right clicks, it should add 1 metadata to the wheat until it is fully grown. Here is my code. My problem is this: It does not work. The grass is not changing and the wheat does not grow if I plant it by hand.

public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
SoundHandler.onEntityPlay("earthgem", world, entityplayer, 1.0F, 1.0F);
itemstack.damageItem(1, entityplayer);



for (int c = -2; c < 4; c++) {
for (int a = -3; a < 3; a++) {
for (int b = -3; b < 3; b++)
{
BlockPos blockpos1 = new BlockPos((int)(entityplayer.posX + a), (int)(entityplayer.posY - 2.0D + c), (int)(entityplayer.posZ + b));
BlockPos blockpos2 = new BlockPos((int)(entityplayer.posX + a), (int)(entityplayer.posY - 1.0D + c), (int)(entityplayer.posZ + b));
Block crop = world.getBlockState(blockpos1).getBlock();
Block cropAbove = world.getBlockState(blockpos1).getBlock();
if (((crop == Blocks.dirt) || (crop == Blocks.grass)) && (random.nextInt(5) == 0) && (cropAbove == Blocks.air))
{
world.setBlockState(blockpos1, Blocks.farmland.getDefaultState());
world.setBlockState(blockpos2, Blocks.wheat.getDefaultState());
}
int l = world.getBlockState(blockpos2).getBlock().getMetaFromState(world.getBlockState(blockpos2));
if ((l < 7) && ((crop == Blocks.wheat) || (crop == Blocks.farmland))) {
world.setBlockState(blockpos2, world.getBlockState(blockpos2), l + 1);
}
}
}
}
return itemstack;
}


Posted by
DovydasAL
Level 34 : Artisan Droid
44

  Have something to say?

JoinSign in

Welcome