Search in sources :

Example 1 with DefaultPlantHandler

use of blusunrize.immersiveengineering.api.tool.BelljarHandler.DefaultPlantHandler in project ImmersiveEngineering by BluSunrize.

the class ExtraUtilsHelper method registerXUPlant.

static void registerXUPlant(ItemStack seed, Block block, ItemStack soil, ItemStack[] output, final int maxAge, final float growthStep, final boolean useFertilizer) {
    IProperty propGrowth = null;
    final IBlockState state = block.getDefaultState();
    for (IProperty prop : state.getPropertyNames()) if ("growth".equals(prop.getName()))
        propGrowth = prop;
    if (propGrowth != null) {
        IProperty finalPropGrowth = propGrowth;
        DefaultPlantHandler handler = new DefaultPlantHandler() {

            private HashSet<ComparableItemStack> validSeeds = new HashSet<>();

            @Override
            protected HashSet<ComparableItemStack> getSeedSet() {
                return validSeeds;
            }

            @Override
            public float getGrowthStep(ItemStack seed, ItemStack soil, float growth, TileEntity tile, float fertilizer, boolean render) {
                return !useFertilizer ? growthStep : (growthStep * fertilizer);
            }

            @Override
            @SideOnly(Side.CLIENT)
            public IBlockState[] getRenderedPlant(ItemStack seed, ItemStack soil, float growth, TileEntity tile) {
                return new IBlockState[] { state.withProperty(finalPropGrowth, Math.min(maxAge, Math.round(maxAge * growth))) };
            }
        };
        handler.register(seed, output, soil, state);
        BelljarHandler.registerHandler(handler);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) DefaultPlantHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.DefaultPlantHandler) ComparableItemStack(blusunrize.immersiveengineering.api.ComparableItemStack) IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) ComparableItemStack(blusunrize.immersiveengineering.api.ComparableItemStack) ItemStack(net.minecraft.item.ItemStack) HashSet(java.util.HashSet)

Aggregations

ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)1 DefaultPlantHandler (blusunrize.immersiveengineering.api.tool.BelljarHandler.DefaultPlantHandler)1 HashSet (java.util.HashSet)1 IProperty (net.minecraft.block.properties.IProperty)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1