ReyMagos
Тег-бомбастер
- 412
- 7
- 121
Это палки для растений, они должны работать, так, чтобы при нажатии на них определённым растением меняли своё свойство на указанный номер типа (помидор - тип 1). Но при нажатии вылетает minecraft. Подскажите, что делать. :mc_e_2:
Java:
public class BlockPlantsSticks extends Block {
public static final PropertyInteger TYPE = PropertyInteger.create("type", 0, 1);
private static final AxisAlignedBB[] PLANTS_STICKS_AABB = new AxisAlignedBB[]
{
new AxisAlignedBB(0.0625, 0.125, 0.875, 0.125, 1.0, 0.9375),
new AxisAlignedBB(0.875, 0.125, 0.875, 0.9375, 1.0, 0.9375),
new AxisAlignedBB(0.875, 0.125, 0.0625, 0.9375, 1.0, 0.125),
new AxisAlignedBB(0.0625, 0.125, 0.0625, 0.125, 1.0, 0.125)
};
public BlockPlantsSticks(String name) {
super(Material.WOOD);
this.setRegistryName(name);
this.setUnlocalizedName(name);
this.setCreativeTab(RedModMain.Test);
this.setHardness(0.01f);
this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, Integer.valueOf(0)));
}
@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, PLANTS_STICKS_AABB[0]);
addCollisionBoxToList(pos, entityBox, collidingBoxes, PLANTS_STICKS_AABB[1]);
addCollisionBoxToList(pos, entityBox, collidingBoxes, PLANTS_STICKS_AABB[2]);
addCollisionBoxToList(pos, entityBox, collidingBoxes, PLANTS_STICKS_AABB[3]);
}
public AxisAlignedBB getBoundingBox(IBlockState blockState, IBlockAccess source, BlockPos position) {
return FULL_BLOCK_AABB;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack itemstack = player.getHeldItem(hand);
Item item = itemstack.getItem();
if (!itemstack.isEmpty()) {
if (item == ItemsRegister.Tomato) {
setType(world, pos, state, 1);
player.sendMessage(new TextComponentString("Event Activated!"));
return true;
}
}
return false;
}
public void setType(World worldIn, BlockPos pos, IBlockState state, int type)
{
worldIn.setBlockState(pos, state.withProperty(TYPE, Integer.valueOf(MathHelper.clamp(type, 0, 3))),1);
}
}