Search in sources :

Example 1 with PropertyInteger

use of net.minecraft.block.properties.PropertyInteger in project ImmersiveEngineering by BluSunrize.

the class AttainedDropsHelper method init.

@Override
public void init() {
    Block blockPlant = Block.REGISTRY.getObject(new ResourceLocation("attaineddrops:plant"));
    final Item itemSeed = Item.REGISTRY.getObject(new ResourceLocation("attaineddrops:itemseed"));
    if (blockPlant == null || itemSeed == null)
        return;
    final IBlockState blockstatePlant = blockPlant.getDefaultState();
    IProperty propertyAge = null;
    for (IProperty prop : blockstatePlant.getPropertyNames()) if ("age".equals(prop.getName()) && prop instanceof PropertyInteger)
        propertyAge = prop;
    final IProperty propertyAge_final = propertyAge;
    addType("slimeball", new ItemStack(Items.SLIME_BALL));
    addType("bone", new ItemStack(Items.BONE));
    addType("string", new ItemStack(Items.STRING));
    addType("rottenflesh", new ItemStack(Items.ROTTEN_FLESH));
    addType("ghasttear", new ItemStack(Items.GHAST_TEAR));
    addType("spidereye", new ItemStack(Items.SPIDER_EYE));
    addType("prismarine", new ItemStack(Items.PRISMARINE_SHARD));
    addType("blaze", new ItemStack(Items.BLAZE_ROD));
    addType("gunpowder", new ItemStack(Items.GUNPOWDER));
    addType("witherskull", new ItemStack(Items.SKULL, 1, 1));
    addType("enderpearl", new ItemStack(Items.ENDER_PEARL));
    BelljarHandler.registerHandler(new IPlantHandler() {

        @Override
        public boolean isCorrectSoil(ItemStack seed, ItemStack soil) {
            return soil != null && soilOutputMap.containsKey(new ComparableItemStack(soil));
        }

        @Override
        public float getGrowthStep(ItemStack seed, ItemStack soil, float growth, TileEntity tile, float fertilizer, boolean render) {
            return (growth < .5 ? .003125f : .0015625f) * fertilizer;
        }

        @Override
        public float resetGrowth(ItemStack seed, ItemStack soil, float growth, TileEntity tile, boolean render) {
            return .5f;
        }

        @Override
        public ItemStack[] getOutput(ItemStack seed, ItemStack soil, TileEntity tile) {
            ItemStack[] out = soilOutputMap.get(new ComparableItemStack(soil));
            if (out == null)
                return new ItemStack[0];
            return out;
        }

        @Override
        public boolean isValid(ItemStack seed) {
            return seed != null && seed.getItem() == itemSeed;
        }

        @Override
        @SideOnly(Side.CLIENT)
        public IBlockState[] getRenderedPlant(ItemStack seed, ItemStack soil, float growth, TileEntity tile) {
            return new IBlockState[0];
        }

        @Override
        @SideOnly(Side.CLIENT)
        public float getRenderSize(ItemStack seed, ItemStack soil, float growth, TileEntity tile) {
            return .875f;
        }

        @Override
        @SideOnly(Side.CLIENT)
        public boolean overrideRender(ItemStack seed, ItemStack soil, float growth, TileEntity tile, BlockRendererDispatcher blockRenderer) {
            IBlockState state = blockstatePlant.withProperty(propertyAge_final, growth >= .5 ? 7 : Math.min(7, Math.round(7 * growth * 2)));
            IBakedModel model = blockRenderer.getModelForState(state);
            GlStateManager.pushMatrix();
            blockRenderer.getBlockModelRenderer().renderModelBrightness(model, state, 1, true);
            GlStateManager.popMatrix();
            if (growth >= .5) {
                state = bulbMap.get(new ComparableItemStack(soil));
                model = blockRenderer.getModelForState(state);
                GlStateManager.pushMatrix();
                float scale = (growth - .5f) * 2f;
                GlStateManager.translate(.5 - scale / 2, 1, -.5 + scale / 2);
                GlStateManager.scale(scale, scale, scale);
                blockRenderer.getBlockModelRenderer().renderModelBrightness(model, state, 1, true);
                GlStateManager.popMatrix();
            }
            return true;
        }
    });
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) PropertyInteger(net.minecraft.block.properties.PropertyInteger) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) IPlantHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler) TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) ComparableItemStack(blusunrize.immersiveengineering.api.ComparableItemStack) IProperty(net.minecraft.block.properties.IProperty) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ComparableItemStack(blusunrize.immersiveengineering.api.ComparableItemStack) ItemStack(net.minecraft.item.ItemStack) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Aggregations

ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)1 IPlantHandler (blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler)1 Block (net.minecraft.block.Block)1 IProperty (net.minecraft.block.properties.IProperty)1 PropertyInteger (net.minecraft.block.properties.PropertyInteger)1 IBlockState (net.minecraft.block.state.IBlockState)1 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1