Search in sources :

Example 81 with IBlockState

use of net.minecraft.block.state.IBlockState 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 82 with IBlockState

use of net.minecraft.block.state.IBlockState in project ImmersiveEngineering by BluSunrize.

the class TileRenderBottlingMachine method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityBottlingMachine te, double x, double y, double z, float partialTicks, int destroyStage) {
    if (!te.formed || te.isDummy() || !te.getWorld().isBlockLoaded(te.getPos(), false))
        return;
    //Grab model + correct eextended state
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos blockPos = te.getPos();
    IBlockState state = getWorld().getBlockState(blockPos);
    if (state.getBlock() != IEContent.blockMetalMultiblock)
        return;
    state = state.getBlock().getActualState(state, getWorld(), blockPos);
    state = state.withProperty(IEProperties.DYNAMICRENDER, true);
    IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
    //Initialize Tesselator and VertexBuffer
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer worldRenderer = tessellator.getBuffer();
    //Outer GL Wrapping, initial translation
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    if (te.mirrored)
        GlStateManager.scale(te.facing.getFrontOffsetX() == 0 ? -1 : 1, 1, te.facing.getFrontOffsetZ() == 0 ? -1 : 1);
    //Item Displacement
    float[][] itemDisplays = new float[te.bottlingProcessQueue.size()][];
    //Animations
    float lift = 0;
    for (int i = 0; i < itemDisplays.length; i++) {
        BottlingProcess process = te.bottlingProcessQueue.get(i);
        if (process == null || process.processTick == process.maxProcessTick)
            continue;
        //+partialTicks
        float processTimer = ((float) process.processTick) / process.maxProcessTick * 120;
        //-1;
        float itemX = -1.5f;
        // -.34375f;
        float itemY = -.15625f;
        //-.9375f;
        float itemZ = 1;
        //ClientUtils.mc().thePlayer.ticksExisted%100; //0f;
        float itemFill = 0;
        if (//slide
        processTimer <= 35) {
            itemX += processTimer / 35f * 1.5;
        } else if (//slide
        processTimer <= 85) {
            itemX = 0;
            if (processTimer <= 55)
                lift = (processTimer - 35) / 20f * .125f;
            else if (processTimer <= 65) {
                lift = .125f;
                itemFill = (processTimer - 55) / 10f;
            } else {
                lift = (85 - processTimer) / 20f * .125f;
                itemFill = 1;
            }
            itemY += lift;
            lift += .0625;
        } else {
            itemX = (processTimer - 85) / 35f * 1.5f;
            itemFill = 1;
        }
        itemDisplays[i] = new float[] { processTimer, itemX, itemY, itemZ, itemFill };
    }
    ClientUtils.bindAtlas();
    GlStateManager.pushMatrix();
    GlStateManager.translate(0, lift, 0);
    renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "lift");
    GlStateManager.translate(0, -lift, 0);
    RenderHelper.enableStandardItemLighting();
    GlStateManager.popMatrix();
    switch(te.facing) {
        case NORTH:
            break;
        case SOUTH:
            GlStateManager.rotate(180, 0, 1, 0);
            break;
        case WEST:
            GlStateManager.rotate(90, 0, 1, 0);
            break;
        case EAST:
            GlStateManager.rotate(-90, 0, 1, 0);
            break;
    }
    float scale = .0625f;
    FluidStack fs = te.tanks[0].getFluid();
    if (fs != null) {
        GlStateManager.pushMatrix();
        float level = fs.amount / (float) te.tanks[0].getCapacity();
        GlStateManager.translate(-.21875, .376, 1.21875);
        GlStateManager.scale(scale, scale, scale);
        float h = level * 9;
        ClientUtils.drawRepeatedFluidSprite(fs, 0, 0, 7, h);
        GlStateManager.rotate(90, 0, 1, 0);
        ClientUtils.drawRepeatedFluidSprite(fs, 0, 0, 7, h);
        GlStateManager.rotate(90, 0, 1, 0);
        GlStateManager.translate(-7, 0, 7);
        ClientUtils.drawRepeatedFluidSprite(fs, 0, 0, 7, h);
        GlStateManager.rotate(90, 0, 1, 0);
        ClientUtils.drawRepeatedFluidSprite(fs, 0, 0, 7, h);
        GlStateManager.rotate(90, 1, 0, 0);
        ClientUtils.drawRepeatedFluidSprite(fs, 0, 0, 7, 7);
        GlStateManager.translate(0, 0, -h);
        ClientUtils.drawRepeatedFluidSprite(fs, 0, 0, 7, 7);
        GlStateManager.scale(1 / scale, 1 / scale, 1 / scale);
        GlStateManager.translate(0, -1, -1);
        GlStateManager.popMatrix();
    }
    //DRAW ITEMS HERE
    for (int i = 0; i < itemDisplays.length; i++) if (itemDisplays[i] != null) {
        BottlingProcess process = te.bottlingProcessQueue.get(i);
        if (process == null)
            continue;
        ItemStack display = itemDisplays[i][4] == 0 || process.items[1] == null ? process.items[0] : process.items[1];
        scale = .4375f;
        GlStateManager.translate(itemDisplays[i][1], itemDisplays[i][2], itemDisplays[i][3]);
        GlStateManager.scale(scale, scale, scale);
        if (itemDisplays[i][4] == 0)
            ClientUtils.mc().getRenderItem().renderItem(process.items[0], ItemCameraTransforms.TransformType.FIXED);
        else if (itemDisplays[i][4] == 1)
            ClientUtils.mc().getRenderItem().renderItem(display, ItemCameraTransforms.TransformType.FIXED);
        else {
            float h0 = -.5f;
            float h1 = h0 + itemDisplays[i][4];
            VertexBuffer worldrenderer = tessellator.getBuffer();
            GL11.glEnable(GL11.GL_STENCIL_TEST);
            GlStateManager.colorMask(false, false, false, false);
            GlStateManager.depthMask(false);
            GL11.glStencilFunc(GL11.GL_NEVER, 1, 0xFF);
            GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_KEEP, GL11.GL_KEEP);
            GL11.glStencilMask(0xFF);
            GlStateManager.clear(GL11.GL_STENCIL_BUFFER_BIT);
            GlStateManager.rotate(90.0F - ClientUtils.mc().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
            GlStateManager.disableTexture2D();
            worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
            ClientUtils.renderBox(worldrenderer, -.5, h0, -.5, .5, h1, .5);
            tessellator.draw();
            GlStateManager.enableTexture2D();
            GlStateManager.rotate(-(90.0F - ClientUtils.mc().getRenderManager().playerViewY), 0.0F, 1.0F, 0.0F);
            GlStateManager.colorMask(true, true, true, true);
            GlStateManager.depthMask(true);
            GL11.glStencilMask(0x00);
            GL11.glStencilFunc(GL11.GL_EQUAL, 0, 0xFF);
            ClientUtils.mc().getRenderItem().renderItem(process.items[0], ItemCameraTransforms.TransformType.FIXED);
            GL11.glStencilFunc(GL11.GL_EQUAL, 1, 0xFF);
            ClientUtils.mc().getRenderItem().renderItem(display, ItemCameraTransforms.TransformType.FIXED);
            GL11.glDisable(GL11.GL_STENCIL_TEST);
        }
        GlStateManager.scale(1 / scale, 1 / scale, 1 / scale);
        GlStateManager.translate(-itemDisplays[i][1], -itemDisplays[i][2], -itemDisplays[i][3]);
    }
    GlStateManager.popMatrix();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BottlingProcess(blusunrize.immersiveengineering.common.blocks.metal.TileEntityBottlingMachine.BottlingProcess) FluidStack(net.minecraftforge.fluids.FluidStack) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemStack(net.minecraft.item.ItemStack)

Example 83 with IBlockState

use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.

the class BlockCompostSoilTilled method updateTick.

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random r) {
    if (!world.isRemote) {
        BlockPos posU = new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ());
        IBlockState s = world.getBlockState(posU);
        Block b = s.getBlock();
        int deg = state.getValue(BlockCompostSoil.DEGRADATION);
        boolean flag = false;
        if (b != null && (b instanceof IPlantable || b instanceof IGrowable)) {
            if (b instanceof IGrowable)
                flag = ((IGrowable) b).canGrow(world, posU, s, false);
            //trigger growth tick
            b.updateTick(world, posU, world.getBlockState(posU), r);
            //degradation: 0-10
            int i = deg;
            if (//if random number(0-23) is bigger than degradation
            r.nextInt(24) > i)
                b.updateTick(world, posU, world.getBlockState(posU), r);
            i++;
            if (r.nextInt(24) > i)
                b.updateTick(world, posU, world.getBlockState(posU), r);
            i++;
            if (r.nextInt(24) > i)
                b.updateTick(world, posU, world.getBlockState(posU), r);
            i++;
            if (r.nextInt(24) > i)
                b.updateTick(world, posU, world.getBlockState(posU), r);
        }
        if (r.nextInt(5 + (flag ? 3 : 0)) == 0) {
            if (deg < 10)
                world.setBlockState(pos, state.withProperty(BlockCompostSoil.DEGRADATION, deg + 1));
            else
                world.setBlockState(pos, Blocks.FARMLAND.getDefaultState().withProperty(BlockFarmland.MOISTURE, 7));
        }
        if (s.getMaterial().isSolid())
            world.setBlockState(pos, ModBlocks.compostSoilBlock.getDefaultState().withProperty(BlockCompostSoil.DEGRADATION, deg), 2);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IGrowable(net.minecraft.block.IGrowable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) CABlock(convenientadditions.base.block.CABlock) ItemBlock(net.minecraft.item.ItemBlock) BlockPos(net.minecraft.util.math.BlockPos)

Example 84 with IBlockState

use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.

the class ComposterItemStackHandler method insertItem.

@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
    int simulate_content = composter.getContentValue(stack);
    stack = stack.copy();
    while (!stack.isEmpty()) {
        if (!(composter.content < ModConfigMisc.composter_capacity && composter.getContentValue(stack) > 0) || (simulate && simulate_content > ModConfigMisc.composter_capacity))
            return stack;
        if (!simulate) {
            composter.content += composter.getContentValue(stack);
            composter.processing = (composter.content >= ModConfigMisc.composter_progressContent);
            if (stack.getItem() instanceof ICompostable && ((ICompostable) stack.getItem()).hasShroomSpores(stack))
                composter.spores = true;
            else if (stack.getItem() == Items.MUSHROOM_STEW || stack.getItem() == ItemBlock.getItemFromBlock(Blocks.RED_MUSHROOM) || stack.getItem() == ItemBlock.getItemFromBlock(Blocks.BROWN_MUSHROOM))
                composter.spores = true;
            composter.markDirty();
            IBlockState state = composter.getWorld().getBlockState(composter.getPos());
            composter.getWorld().notifyBlockUpdate(composter.getPos(), state, state, 2);
        } else {
            simulate_content += composter.getContentValue(stack);
        }
        stack.shrink(1);
    }
    return stack;
}
Also used : ICompostable(convenientadditions.api.item.ICompostable) IBlockState(net.minecraft.block.state.IBlockState)

Example 85 with IBlockState

use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.

the class TileEntityComposter method update.

@Override
public void update() {
    if (!getWorld().isRemote) {
        for (EntityItem e : getWorld().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos.getX(), pos.getY() + 1, pos.getZ(), pos.getX() + 1, pos.getY() + 1.5d, pos.getZ() + 1))) {
            if (!e.isDead && !e.getEntityItem().isEmpty()) {
                ItemStack i = e.getEntityItem();
                i.setCount(stackHandler.insertItem(0, i, false).getCount());
                if (i.isEmpty())
                    e.setDead();
            }
        }
    }
    IBlockState state = getWorld().getBlockState(pos);
    Random rnd = new Random();
    if (!getWorld().isRemote) {
        if (content >= ModConfigMisc.composter_progressContent) {
            progress++;
            if (progress >= ModConfigMisc.composter_progressPeriod) {
                progress = 0;
                content -= ModConfigMisc.composter_progressContent;
                if (getWorld().rand.nextFloat() < ModConfigMisc.composter_compostChance)
                    Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemCompost, 1, this.spores ? 1 : 0));
                if (getWorld().rand.nextFloat() < ModConfigMisc.composter_extraCompostChance)
                    Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemCompost, 1, this.spores ? 1 : 0));
                if (getWorld().rand.nextFloat() < ModConfigMisc.composter_dirtChunkChance)
                    Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemDirtChunk));
                if (getWorld().rand.nextFloat() < ModConfigMisc.composter_fertilizerChance)
                    Helper.spawnItemInPlace(getWorld(), (double) pos.getX() + .5, (double) pos.getY() + 1.2, (double) pos.getZ() + .5, new ItemStack(ModItems.itemFertilizer));
            }
            if (content >= ModConfigMisc.composter_capacity && ModConfigMisc.composter_overflowSmell) {
                List<EntityPlayer> players = getWorld().getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.getX() - 2, pos.getY() - 2, pos.getZ() - 2, pos.getX() + 3, pos.getY() + 3, pos.getZ() + 3));
                for (EntityPlayer p : players) {
                    switch(rnd.nextInt(120)) {
                        case 0:
                            p.addPotionEffect(new PotionEffect(Potion.getPotionById(9), 200, 0));
                            break;
                        default:
                            break;
                    }
                }
            }
            this.markDirty();
            this.getWorld().notifyBlockUpdate(pos, state, state, 3);
        } else {
            this.progress = 0;
            if (this.content == 0)
                this.spores = false;
            if (processing) {
                this.processing = false;
                this.markDirty();
                this.getWorld().notifyBlockUpdate(pos, state, state, 3);
            }
        }
    } else if (processing) {
        if (rnd.nextInt(10) == 0)
            getWorld().spawnParticle(EnumParticleTypes.SPELL_MOB, pos.getX() + .5 - ((double) (rnd.nextInt(9) - 4) / 10D), pos.getY() + .2 + (double) content / (double) ModConfigMisc.composter_capacity * .75, pos.getZ() + .5 + ((double) (rnd.nextInt(9) - 4) / 10D), 0, 0.6, 0);
        if (content >= ModConfigMisc.composter_capacity)
            getWorld().spawnParticle(EnumParticleTypes.SPELL_MOB, pos.getX() + .5 - ((double) (rnd.nextInt(9) - 4) / 10D), pos.getY() + .2 + (double) content / (double) ModConfigMisc.composter_capacity * .75, pos.getZ() + .5 + ((double) (rnd.nextInt(9) - 4) / 10D), 0, 0.6, 0);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) Random(java.util.Random) PotionEffect(net.minecraft.potion.PotionEffect) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)2979 BlockPos (net.minecraft.util.math.BlockPos)1194 Block (net.minecraft.block.Block)797 ItemStack (net.minecraft.item.ItemStack)517 EnumFacing (net.minecraft.util.EnumFacing)420 TileEntity (net.minecraft.tileentity.TileEntity)339 World (net.minecraft.world.World)255 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)171 EntityPlayer (net.minecraft.entity.player.EntityPlayer)136 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)126 ArrayList (java.util.ArrayList)125 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)121 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)95 Entity (net.minecraft.entity.Entity)94 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)93 ItemBlock (net.minecraft.item.ItemBlock)89 BlockPos (net.minecraft.util.BlockPos)84 Random (java.util.Random)82 Vec3d (net.minecraft.util.math.Vec3d)81 RayTraceResult (net.minecraft.util.math.RayTraceResult)76