Кусты ягод

Версия Minecraft
1.12.2
7,099
324
1,510
Не через мету, а через проперти. Абстракции - лучший друг программиста

@Nikko Mwordlling у тебя получилось сделать просто блок? Начни с этого. Т.е. упрости задачу до создания просто блока. Потом наращивай сложность: добавь блоку модель и текстуру как у куста; потом механику дачи ягод по пкм; потом доработай механику, чтобы ягоды давались только если стэйт куста имеет определенное значение пропери(вот тут смотришь в код Натуры) и чтобы куст со временем рост(изменялось значение проперти)
 
1,057
50
234
Java:
@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;
}
В рандомтиках делаешь "созревание" ягод путем замены стейта блока.
 
Последнее редактирование:
Что здесь не так
Java:
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)
    {
        
    }


}
 
Ничего не растёт
Java:
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)
    {
        
    }

}
 
3,005
192
592
Сверху