Fix incorrect drops and shearing on BOP double plants

This commit is contained in:
Cheeserolls 2015-05-23 22:21:50 +01:00
parent 41f28506e1
commit 4f8fde74ef
2 changed files with 36 additions and 28 deletions

View file

@ -18,8 +18,10 @@ import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState; import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
import net.minecraft.util.IStringSerializable; import net.minecraft.util.IStringSerializable;
import net.minecraft.world.ColorizerFoliage; import net.minecraft.world.ColorizerFoliage;
@ -208,31 +210,35 @@ public class BlockBOPDoublePlant extends BlockDoubleDecoration implements IShear
// get the items dropped when you bash the bush // get the items dropped when you bash the bush
@Override @Override
public List<ItemStack> getLowerDrops(IBlockAccess world, BlockPos lowerPos, IBlockState lowerState, int fortune) public List<ItemStack> getLowerDrops(IBlockAccess world, BlockPos lowerPos, IBlockState lowerState, int fortune)
{ {
Random rand = world instanceof World ? ((World)world).rand : RANDOM; Random rand = world instanceof World ? ((World)world).rand : RANDOM;
// start with an empty stack // start with an empty stack
List<ItemStack> ret = new java.util.ArrayList<ItemStack>(); List<ItemStack> ret = new java.util.ArrayList<ItemStack>();
// add items based on the VARIANT - default is to return nothing (require shears to collect the block) // add items based on the VARIANT - default is to drop (lower) block
switch ((DoublePlantType) lowerState.getValue(VARIANT)) DoublePlantType type = (DoublePlantType) lowerState.getValue(VARIANT);
switch (type)
{ {
case FLAX: case FLAX:
if (rand.nextInt(8) == 0) // drop flax plant and also 1 in 8 chance of getting a seed
{ ret.add(this.getVariantItem(type));
// 1 in 8 chance of getting a seed from this grass if (rand.nextInt(8) == 0) {ret.add(ForgeHooks.getGrassSeed(rand));}
ret.add(ForgeHooks.getGrassSeed(rand));
} case TALL_CATTAIL:
default:
break; break;
case EYEBULB: default:
// drop self
ret.add(this.getVariantItem(type));
} }
return ret; return ret;
} }
@Override @Override
public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos) { public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos)
{
return true; return true;
} }
@ -242,12 +248,17 @@ public class BlockBOPDoublePlant extends BlockDoubleDecoration implements IShear
List<ItemStack> ret = new java.util.ArrayList<ItemStack>(); List<ItemStack> ret = new java.util.ArrayList<ItemStack>();
// add items based on the VARIANT // add items based on the VARIANT
// note that the sheared items are dropped in addition to regular drops
// since the default in getLowerDrops is to drop the (lower) block, the default here is to drop nothing (so we don't have a duplicate)
// at the moment, this code is pretty useless, but if in the future we add a double block which can't be collected except with shears
// then a case will need to be inserted for it in the switch below
DoublePlantType type = (DoublePlantType) lowerState.getValue(VARIANT); DoublePlantType type = (DoublePlantType) lowerState.getValue(VARIANT);
switch (type) switch (type)
{ {
default: case TALL_CATTAIL:
// default is to get the (lower) block unaltered
ret.add(this.getVariantItem(type)); ret.add(this.getVariantItem(type));
default:
break;
} }
return ret; return ret;
} }

View file

@ -115,7 +115,7 @@ public class BlockDoubleDecoration extends BlockDecoration {
// drop block as item if it cannot remain here - return whether on not it could stay // drop block as item if it cannot remain here - return whether on not it could stay
@Override @Override
protected boolean checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state) protected boolean checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state)
{ {
if (this.isValidDoubleBlock(worldIn, pos) && this.canBlockStay(worldIn, this.getLowerPos(worldIn, pos), state)) if (this.isValidDoubleBlock(worldIn, pos) && this.canBlockStay(worldIn, this.getLowerPos(worldIn, pos), state))
{ {
return true; return true;
@ -187,14 +187,17 @@ public class BlockDoubleDecoration extends BlockDecoration {
// handle drops from UPPER and LOWER separately // handle drops from UPPER and LOWER separately
@Override @Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{ {
// note it is important to use the state as provided and NOT world.getBlockState(pos)
// because when this function is called, the block may have already been turned to air
// the state provided is the state before the block was destroyed
if (state.getValue(HALF) == Half.UPPER) if (state.getValue(HALF) == Half.UPPER)
{ {
return this.getUpperDrops(world, this.getUpperPos(world, pos), this.getUpperState(world, pos), fortune); return this.getUpperDrops(world, pos, state, fortune);
} }
else else
{ {
return this.getLowerDrops(world, this.getLowerPos(world, pos), this.getLowerState(world, pos), fortune); return this.getLowerDrops(world, pos, state, fortune);
} }
} }
@ -209,27 +212,21 @@ public class BlockDoubleDecoration extends BlockDecoration {
} }
// if a child class chooses to implement IShearable make shearing the upper or lower block act as shearing both // if a child class chooses to implement IShearable make shearing the upper or lower block act as shearing both
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) { public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
List<ItemStack> drops = new java.util.ArrayList<ItemStack>(); List<ItemStack> drops = new java.util.ArrayList<ItemStack>();
if (!this.isValidDoubleBlock(world, pos)) {return drops;} if (!this.isValidDoubleBlock(world, pos)) {return drops;}
drops.addAll( this.getUpperShearDrops(item, world, this.getUpperPos(world, pos), this.getUpperState(world, pos), fortune) ); drops.addAll( this.getUpperShearDrops(item, world, this.getUpperPos(world, pos), this.getUpperState(world, pos), fortune) );
drops.addAll( this.getLowerShearDrops(item, world, this.getLowerPos(world, pos), this.getLowerState(world, pos), fortune) ); drops.addAll( this.getLowerShearDrops(item, world, this.getLowerPos(world, pos), this.getLowerState(world, pos), fortune) );
// whichever half was sheared, turn the other to air (to prevent it dropping an additional item when it pops)
if (world instanceof World)
{
((World)world).setBlockToAir( pos.add(0, world.getBlockState(pos).getValue(HALF) == Half.UPPER ? -1 : 1, 0) );
}
return drops; return drops;
} }
// default behavior is that UPPER drops nothing, and LOWER drops the default item // default behavior is that UPPER drops nothing, and LOWER drops the default item
public List<ItemStack> getUpperShearDrops(ItemStack item, IBlockAccess world, BlockPos upperPos, IBlockState upperState, int fortune) { public List<ItemStack> getUpperShearDrops(ItemStack item, IBlockAccess world, BlockPos upperPos, IBlockState upperState, int fortune)
{
return new java.util.ArrayList<ItemStack>(); return new java.util.ArrayList<ItemStack>();
} }
public List<ItemStack> getLowerShearDrops(ItemStack item, IBlockAccess world, BlockPos lowerPos, IBlockState lowerState, int fortune) { public List<ItemStack> getLowerShearDrops(ItemStack item, IBlockAccess world, BlockPos lowerPos, IBlockState lowerState, int fortune)
{
return super.getDrops(world, lowerPos, lowerState, fortune); return super.getDrops(world, lowerPos, lowerState, fortune);
} }