Search in sources :

Example 1 with IPlantHandler

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

the class TileRenderBelljar method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityBelljar tile, double x, double y, double z, float partialTicks, int destroyStage) {
    if (tile.dummy != 0 || !tile.getWorld().isBlockLoaded(tile.getPos(), false))
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos blockPos = tile.getPos();
    if (!quads.containsKey(tile.getFacing())) {
        IBlockState state = getWorld().getBlockState(blockPos);
        if (state.getBlock() != IEContent.blockMetalDevice1)
            return;
        state = state.getActualState(getWorld(), blockPos);
        IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
        if (state instanceof IExtendedBlockState)
            state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(Arrays.asList("glass"), true));
        quads.put(tile.getFacing(), model.getQuads(state, null, 0));
    }
    ClientUtils.bindAtlas();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled())
        GlStateManager.shadeModel(7425);
    else
        GlStateManager.shadeModel(7424);
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    VertexBuffer worldRenderer = Tessellator.getInstance().getBuffer();
    GlStateManager.enableCull();
    IPlantHandler plantHandler = tile.getCurrentPlantHandler();
    if (plantHandler != null) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(0, 1.0625, 0);
        GlStateManager.color(1, 1, 1, 1);
        float scale = plantHandler.getRenderSize(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile);
        GlStateManager.translate((1 - scale) / 2, 0, (1 - scale) / 2);
        GlStateManager.scale(scale, scale, scale);
        if (!plantHandler.overrideRender(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile, blockRenderer)) {
            IBlockState[] states = plantHandler.getRenderedPlant(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile);
            if (states == null || states.length < 1)
                return;
            for (IBlockState s : states) {
                List<BakedQuad> plantQuadList = plantQuads.get(s);
                if (plantQuadList == null) {
                    IBakedModel plantModel = blockRenderer.getModelForState(s);
                    plantQuadList = plantModel.getQuads(s, null, 0);
                    for (EnumFacing f : EnumFacing.values()) plantQuadList.addAll(plantModel.getQuads(s, f, 0));
                    plantQuads.put(s, plantQuadList);
                }
                if (plantQuadList != null) {
                    GlStateManager.pushMatrix();
                    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
                    ClientUtils.renderModelTESR(plantQuadList, worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
                    Tessellator.getInstance().draw();
                    GlStateManager.popMatrix();
                    GlStateManager.translate(0, 1, 0);
                }
            }
        }
        GlStateManager.popMatrix();
    }
    GlStateManager.depthMask(false);
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    ClientUtils.renderModelTESR(quads.get(tile.getFacing()), worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
    Tessellator.getInstance().draw();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.disableBlend();
    GlStateManager.depthMask(true);
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) IPlantHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Example 2 with IPlantHandler

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

the class TileRenderBelljar method render.

@Override
public void render(TileEntityBelljar tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    if (tile.dummy != 0 || !tile.getWorld().isBlockLoaded(tile.getPos(), false))
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos blockPos = tile.getPos();
    if (!quads.containsKey(tile.getFacing())) {
        IBlockState state = getWorld().getBlockState(blockPos);
        if (state.getBlock() != IEContent.blockMetalDevice1)
            return;
        state = state.getActualState(getWorld(), blockPos);
        IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
        if (state instanceof IExtendedBlockState)
            state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(Arrays.asList("glass"), true));
        quads.put(tile.getFacing(), model.getQuads(state, null, 0));
    }
    ClientUtils.bindAtlas();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled())
        GlStateManager.shadeModel(7425);
    else
        GlStateManager.shadeModel(7424);
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    BufferBuilder worldRenderer = Tessellator.getInstance().getBuffer();
    GlStateManager.enableCull();
    IPlantHandler plantHandler = tile.getCurrentPlantHandler();
    if (plantHandler != null) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(0, 1.0625, 0);
        GlStateManager.color(1, 1, 1, 1);
        NonNullList<ItemStack> inventory = tile.getInventory();
        float scale = plantHandler.getRenderSize(inventory.get(1), inventory.get(0), tile.renderGrowth, tile);
        GlStateManager.translate((1 - scale) / 2, 0, (1 - scale) / 2);
        GlStateManager.scale(scale, scale, scale);
        if (!plantHandler.overrideRender(inventory.get(1), inventory.get(0), tile.renderGrowth, tile, blockRenderer)) {
            IBlockState[] states = plantHandler.getRenderedPlant(inventory.get(1), inventory.get(0), tile.renderGrowth, tile);
            if (states == null || states.length < 1)
                return;
            for (IBlockState s : states) {
                List<BakedQuad> plantQuadList = plantQuads.get(s);
                if (plantQuadList == null) {
                    IBakedModel plantModel = blockRenderer.getModelForState(s);
                    plantQuadList = new ArrayList<BakedQuad>(plantModel.getQuads(s, null, 0));
                    for (EnumFacing f : EnumFacing.values()) plantQuadList.addAll(plantModel.getQuads(s, f, 0));
                    plantQuads.put(s, plantQuadList);
                }
                if (plantQuadList != null) {
                    GlStateManager.pushMatrix();
                    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
                    ClientUtils.renderModelTESRFancy(plantQuadList, worldRenderer, tile.getWorld(), blockPos, false);
                    Tessellator.getInstance().draw();
                    GlStateManager.popMatrix();
                    GlStateManager.translate(0, 1, 0);
                }
            }
        }
        GlStateManager.popMatrix();
    }
    GlStateManager.depthMask(false);
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    ClientUtils.renderModelTESRFast(quads.get(tile.getFacing()), worldRenderer, tile.getWorld(), blockPos);
    Tessellator.getInstance().draw();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.disableBlend();
    GlStateManager.depthMask(true);
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) IPlantHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IPlantHandler

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

the class AttainedDropsHelper method init.

@Override
public void init() {
    seed = ForgeRegistries.ITEMS.getValue(new ResourceLocation(AD_MODID, "seed"));
    plant = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(AD_MODID, "plant"));
    bulb = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(AD_MODID, "bulb"));
    soil = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(AD_MODID, "soil"));
    soilItem = Item.getItemFromBlock(soil);
    addTypes();
    BelljarHandler.registerHandler(new IPlantHandler() {

        @Override
        public boolean isCorrectSoil(ItemStack seed, ItemStack soil) {
            return soil.getItem() == AttainedDropsHelper.this.soilItem && soil.getMetadata() > 0 && soil.getMetadata() <= 15;
        }

        @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 = outputMap.get(soil.getMetadata());
            if (out == null)
                return new ItemStack[0];
            return out;
        }

        @Override
        public boolean isValid(ItemStack seed) {
            return seed.getItem() == AttainedDropsHelper.this.seed;
        }

        @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 = plant.getDefaultState().withProperty(BlockCrops.AGE, growth >= .5 ? 7 : Math.min(7, Math.round(7 * growth * 2)));
            IBakedModel model = blockRenderer.getModelForState(state);
            GlStateManager.pushMatrix();
            GlStateManager.translate(0, 0, 1);
            blockRenderer.getBlockModelRenderer().renderModelBrightness(model, state, 1, true);
            GlStateManager.popMatrix();
            if (growth >= .5) {
                state = bulbMap.get(soil.getMetadata());
                model = blockRenderer.getModelForState(state);
                if (model == null)
                    return false;
                GlStateManager.pushMatrix();
                GlStateManager.translate(0, 0, 1);
                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 : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) ResourceLocation(net.minecraft.util.ResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) IPlantHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemStack(net.minecraft.item.ItemStack) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Example 4 with IPlantHandler

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

the class TileEntityBelljar method update.

@Override
public void update() {
    ApiUtils.checkForNeedlessTicking(this);
    if (dummy != 0 || world.getRedstonePowerFromNeighbors(getPos()) > 0)
        return;
    ItemStack soil = inventory.get(SLOT_SOIL);
    ItemStack seed = inventory.get(SLOT_SEED);
    if (getWorld().isRemote) {
        if (energyStorage.getEnergyStored() > IEConfig.Machines.belljar_consumption && fertilizerAmount > 0 && renderActive) {
            IPlantHandler handler = getCurrentPlantHandler();
            if (handler != null && handler.isCorrectSoil(seed, soil) && fertilizerAmount > 0) {
                if (renderGrowth < 1) {
                    renderGrowth += belljar_growth_mod * handler.getGrowthStep(seed, soil, renderGrowth, this, fertilizerMod, true);
                    fertilizerAmount--;
                } else
                    renderGrowth = handler.resetGrowth(seed, soil, renderGrowth, this, true);
                if (Utils.RAND.nextInt(8) == 0) {
                    double partX = getPos().getX() + .5;
                    double partY = getPos().getY() + 2.6875;
                    double partZ = getPos().getZ() + .5;
                    ImmersiveEngineering.proxy.spawnRedstoneFX(getWorld(), partX, partY, partZ, .25, .25, .25, 1f, .55f, .1f, .1f);
                }
            }
        }
    } else {
        if (!seed.isEmpty()) {
            IPlantHandler handler = getCurrentPlantHandler();
            if (handler != null && handler.isCorrectSoil(seed, soil) && fertilizerAmount > 0 && energyStorage.extractEnergy(IEConfig.Machines.belljar_consumption, true) == IEConfig.Machines.belljar_consumption) {
                boolean consume = false;
                if (growth >= 1) {
                    ItemStack[] outputs = handler.getOutput(seed, soil, this);
                    int canFit = 0;
                    boolean[] emptySlotsUsed = new boolean[4];
                    for (ItemStack output : outputs) if (!output.isEmpty())
                        for (int j = 3; j < 7; j++) {
                            ItemStack existing = inventory.get(j);
                            if ((existing.isEmpty() && !emptySlotsUsed[j - 3]) || (ItemHandlerHelper.canItemStacksStack(existing, output) && existing.getCount() + output.getCount() <= existing.getMaxStackSize())) {
                                canFit++;
                                if (existing.isEmpty())
                                    emptySlotsUsed[j - 3] = true;
                                break;
                            }
                        }
                    if (canFit >= outputs.length) {
                        for (ItemStack output : outputs) for (int j = 3; j < 7; j++) {
                            ItemStack existing = inventory.get(j);
                            if (existing.isEmpty()) {
                                inventory.set(j, output.copy());
                                break;
                            } else if (ItemHandlerHelper.canItemStacksStack(existing, output) && existing.getCount() + output.getCount() <= existing.getMaxStackSize()) {
                                existing.grow(output.getCount());
                                break;
                            }
                        }
                        growth = handler.resetGrowth(seed, soil, growth, this, false);
                        consume = true;
                    }
                } else if (growth < 1) {
                    growth += belljar_growth_mod * handler.getGrowthStep(seed, soil, growth, this, fertilizerMod, false);
                    consume = true;
                    if (world.getTotalWorldTime() % 32 == ((getPos().getX() ^ getPos().getZ()) & 31))
                        sendSyncPacket(0);
                }
                if (consume) {
                    energyStorage.extractEnergy(IEConfig.Machines.belljar_consumption, false);
                    fertilizerAmount--;
                    if (!renderActive) {
                        renderActive = true;
                        sendSyncPacket(0);
                    }
                } else if (renderActive) {
                    renderActive = false;
                    sendSyncPacket(0);
                }
            } else
                growth = 0;
            if (fertilizerAmount <= 0 && tank.getFluidAmount() >= IEConfig.Machines.belljar_fluid) {
                FluidFertilizerHandler fluidFert = BelljarHandler.getFluidFertilizerHandler(tank.getFluid());
                if (fluidFert != null) {
                    fertilizerMod = fluidFert.getGrowthMultiplier(tank.getFluid(), seed, soil, this);
                    tank.drain(IEConfig.Machines.belljar_fluid, true);
                    ItemStack fertilizer = inventory.get(SLOT_FERTILIZER);
                    if (!fertilizer.isEmpty()) {
                        ItemFertilizerHandler itemFert = BelljarHandler.getItemFertilizerHandler(fertilizer);
                        if (itemFert != null)
                            fertilizerMod *= itemFert.getGrowthMultiplier(fertilizer, seed, soil, this);
                        fertilizer.shrink(1);
                        if (fertilizer.getCount() <= 0)
                            inventory.set(2, ItemStack.EMPTY);
                    }
                    fertilizerAmount = IEConfig.Machines.belljar_fertilizer;
                    sendSyncPacket(1);
                }
            }
        } else
            growth = 0;
        if (world.getTotalWorldTime() % 8 == 0) {
            BlockPos outputPos = getPos().up().offset(facing.getOpposite());
            TileEntity outputTile = Utils.getExistingTileEntity(world, outputPos);
            if (outputTile != null)
                for (int j = 3; j < 7; j++) {
                    ItemStack outStack = inventory.get(j);
                    if (!outStack.isEmpty()) {
                        int outCount = Math.min(outStack.getCount(), 16);
                        ItemStack stack = Utils.copyStackWithAmount(outStack, outCount);
                        stack = Utils.insertStackIntoInventory(outputTile, stack, facing);
                        if (!stack.isEmpty())
                            outCount -= stack.getCount();
                        outStack.shrink(outCount);
                        if (outStack.getCount() <= 0)
                            this.inventory.set(j, ItemStack.EMPTY);
                    }
                }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidFertilizerHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.FluidFertilizerHandler) ItemFertilizerHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.ItemFertilizerHandler) BlockPos(net.minecraft.util.math.BlockPos) IPlantHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler) ItemStack(net.minecraft.item.ItemStack) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)

Aggregations

IPlantHandler (blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler)4 IBlockState (net.minecraft.block.state.IBlockState)3 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)3 ItemStack (net.minecraft.item.ItemStack)3 BlockPos (net.minecraft.util.math.BlockPos)3 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 OBJState (net.minecraftforge.client.model.obj.OBJModel.OBJState)2 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)2 FluidFertilizerHandler (blusunrize.immersiveengineering.api.tool.BelljarHandler.FluidFertilizerHandler)1 ItemFertilizerHandler (blusunrize.immersiveengineering.api.tool.BelljarHandler.ItemFertilizerHandler)1 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1