- 60
- 1
- 2
Как создать куст ягод как в Biomes 'O Plenty?
Не через мету, а через проперти. Абстракции - лучший друг программистачерез мету
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
if(state == СТЕЙТ с ягодами)
{
world.setBlockState(pos, стейт без ягод);
world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ягода)));
return true;
}
return false;
}
public class BlockRaspberryBush extends BlockBush implements IGrowable, IHasModel
{
protected static final AxisAlignedBB BUSH_AABB = new AxisAlignedBB(0.30000001192092896D, 0.0D, 0.30000001192092896D, 0.699999988079071D, 0.6000000238418579D, 0.699999988079071D);
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 3);
public BlockRaspberryBush(String name, Material material)
{
super(Material.LEAVES);
setCreativeTab(TheScraGullWorld.BLOCKS);
setUnlocalizedName(name);
setRegistryName(name);
this.setTickRandomly(true);
setSoundType(SoundType.PLANT);
BlockInit.BLOCKS.add(this);
ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
if(state == BlockInit.RASPBERRY_BUSH)
{
world.setBlockState(pos, (IBlockState) BlockInit.RASPBERRY_BUSHP);
world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ItemInit.COAL)));
return true;
}
return false;
}
@Override
public void registerModels()
{
TheScraGullWorld.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
}
public boolean isMaxAge(IBlockState state)
{
return state.getValue(AGE).intValue() >= 3;
}
@Override
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
{
return !this.isMaxAge(state);
}
@Override
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
return true;
}
@Override
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
}
}
public class BlockRaspberryBush extends BlockBush implements IGrowable, IHasModel
{
protected static final AxisAlignedBB BUSH_AABB = new AxisAlignedBB(0.30000001192092896D, 0.0D, 0.30000001192092896D, 0.699999988079071D, 0.6000000238418579D, 0.699999988079071D);
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 3);
public BlockRaspberryBush(String name, Material material)
{
super(Material.LEAVES);
setCreativeTab(TheScraGullWorld.BLOCKS);
setUnlocalizedName(name);
setRegistryName(name);
this.setTickRandomly(true);
setSoundType(SoundType.PLANT);
BlockInit.BLOCKS.add(this);
ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
if(state == BlockInit.RASPBERRY_BUSH.getDefaultState().withProperty(AGE, 3))
{
world.setBlockState(pos, BlockInit.RASPBERRY_BUSH.getDefaultState().withProperty(AGE, 1));
world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ItemInit.COAL)));
return true;
}
return false;
}
@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] { AGE });
}
@Override
public void registerModels()
{
TheScraGullWorld.proxy.registerModel(Item.getItemFromBlock(this), 0);
}
public boolean isMaxAge(IBlockState state)
{
return state.getValue(AGE).intValue() >= 3;
}
@Override
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
{
return !this.isMaxAge(state);
}
@Override
public int getMetaFromState(IBlockState state)
{
return state.getValue(AGE).intValue();
}
@Override
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(AGE, Integer.valueOf(meta));
}
@Override
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
return true;
}
@Override
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
}
}
А почему этот метод пустой? Он же вроде и должен выполняться, судя по названию.@Override public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) {
}