Search in sources :

Example 86 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.

the class TileRenderSampleDrill method render.

@Override
public void render(TileEntitySampleDrill tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    if (tile.isDummy() || !tile.getWorld().isBlockLoaded(tile.getPos(), false))
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    IBlockState state = tile.getWorld().getBlockState(tile.getPos());
    BlockPos blockPos = tile.getPos();
    IBakedModel model = blockRenderer.getModelForState(state);
    if (state.getBlock() != IEContent.blockMetalDevice1)
        return;
    // .getModelFromBlockState(state, getWorld(), blockPos);
    if (state instanceof IExtendedBlockState)
        state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(Lists.newArrayList("drill"), true));
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldRenderer = tessellator.getBuffer();
    bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled())
        GlStateManager.shadeModel(7425);
    else
        GlStateManager.shadeModel(7424);
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    // float rot = 360*tile.rotation-(!tile.canTurn||tile.rotation==0||tile.rotation-tile.prevRotation<4?0:tile.facing.getAxis()==Axis.X?-f:f);
    // GlStateManager.rotate(rot, 0,0,1);
    int max = IEConfig.Machines.coredrill_time;
    if (tile.process > 0 && tile.process < max) {
        GlStateManager.rotate(((tile.process + partialTicks) * 22.5f) % 360f, 0, 1, 0);
        float push = tile.process / (float) max;
        if (tile.process > max / 2)
            push = 1 - push;
        GlStateManager.translate(0, -2.8f * push, 0);
    }
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5 - blockPos.getX(), -.5 - blockPos.getY(), -.5 - blockPos.getZ());
    worldRenderer.color(255, 255, 255, 255);
    blockRenderer.getBlockModelRenderer().renderModel(tile.getWorld(), model, state, tile.getPos(), worldRenderer, true);
    worldRenderer.setTranslation(0.0D, 0.0D, 0.0D);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) 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 87 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel 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 88 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.

the class ConveyorChute method modifyQuads.

@Override
@SideOnly(Side.CLIENT)
public List<BakedQuad> modifyQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing) {
    if (!initTextures) {
        for (BlockTypes_MetalsAll metal : BlockTypes_MetalsAll.values()) TEXTURE_GETTERS[metal.getMeta()] = rl -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("immersiveengineering:blocks/sheetmetal_" + metal.getName());
        initTextures = true;
    }
    if (this.sheetmetalType < 0 || this.sheetmetalType >= TEXTURE_GETTERS.length)
        return baseModel;
    Function<ResourceLocation, TextureAtlasSprite> textureGetter = TEXTURE_GETTERS[this.sheetmetalType];
    if (chuteModel[this.sheetmetalType] == null)
        try {
            IModel iModel = ModelLoaderRegistry.getModel(new ResourceLocation("immersiveengineering:block/metal_device/chute.obj"));
            chuteModel[this.sheetmetalType] = new IBakedModel[] { iModel.bake(new OBJState(ImmutableList.of("base"), true, ModelRotation.X0_Y180), DefaultVertexFormats.ITEM, textureGetter), iModel.bake(new OBJState(ImmutableList.of("base"), true, ModelRotation.X0_Y0), DefaultVertexFormats.ITEM, textureGetter), iModel.bake(new OBJState(ImmutableList.of("base"), true, ModelRotation.X0_Y90), DefaultVertexFormats.ITEM, textureGetter), iModel.bake(new OBJState(ImmutableList.of("base"), true, ModelRotation.X0_Y270), DefaultVertexFormats.ITEM, textureGetter) };
        } catch (Exception ignored) {
        }
    float[] colour = { 1, 1, 1, 1 };
    Matrix4 matrix = new Matrix4(facing);
    baseModel.clear();
    if (diagonal) {
        IBlockState bs = tile != null && tile.getWorld() != null ? tile.getWorld().getBlockState(tile.getPos()) : IEContent.blockConveyor.getDefaultState();
        if (chuteModel[this.sheetmetalType] != null && facing.ordinal() >= 2)
            baseModel.addAll(chuteModel[this.sheetmetalType][facing.ordinal() - 2].getQuads(bs, null, 0));
    } else {
        Function<EnumFacing, TextureAtlasSprite> getSprite = f -> textureGetter.apply(null);
        baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, 0, 0), new Vector3f(.0625f, 1, .0625f), matrix, facing, getSprite, colour));
        baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, 0, .9375f), new Vector3f(.0625f, 1, 1), matrix, facing, getSprite, colour));
        baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, 0, 0), new Vector3f(1, 1, .0625f), matrix, facing, getSprite, colour));
        baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, 0, .9375f), new Vector3f(1, 1, 1), matrix, facing, getSprite, colour));
        if (renderWall(tile, EnumFacing.NORTH, facing))
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.0625f, 0, 0), new Vector3f(.9375f, 1, .0625f), matrix, facing, getSprite, colour));
        if (renderWall(tile, EnumFacing.SOUTH, facing))
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.0625f, 0, .9375f), new Vector3f(.9375f, 1, 1), matrix, facing, getSprite, colour));
        if (renderWall(tile, EnumFacing.WEST, facing))
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, 0, .0625f), new Vector3f(.0625f, 1, .9375f), matrix, facing, getSprite, colour));
        if (renderWall(tile, EnumFacing.EAST, facing))
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, 0, .0625f), new Vector3f(1, 1, .9375f), matrix, facing, getSprite, colour));
    }
    return baseModel;
}
Also used : IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) IEContent(blusunrize.immersiveengineering.common.IEContent) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumHand(net.minecraft.util.EnumHand) Function(java.util.function.Function) ClientUtils(blusunrize.immersiveengineering.client.ClientUtils) ArrayList(java.util.ArrayList) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) IConveyorTile(blusunrize.immersiveengineering.api.tool.ConveyorHandler.IConveyorTile) BlockTypes_MetalsAll(blusunrize.immersiveengineering.common.blocks.BlockTypes_MetalsAll) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) SoundCategory(net.minecraft.util.SoundCategory) ConveyorHandler(blusunrize.immersiveengineering.api.tool.ConveyorHandler) Nullable(javax.annotation.Nullable) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EntityItem(net.minecraft.entity.item.EntityItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Entity(net.minecraft.entity.Entity) IESounds(blusunrize.immersiveengineering.common.util.IESounds) Utils(blusunrize.immersiveengineering.common.util.Utils) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState) ModelLoaderRegistry(net.minecraftforge.client.model.ModelLoaderRegistry) EnumFacing(net.minecraft.util.EnumFacing) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IModel(net.minecraftforge.client.model.IModel) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) Vector3f(org.lwjgl.util.vector.Vector3f) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) ModelRotation(net.minecraft.client.renderer.block.model.ModelRotation) Collections(java.util.Collections) IModel(net.minecraftforge.client.model.IModel) IBlockState(net.minecraft.block.state.IBlockState) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) BlockTypes_MetalsAll(blusunrize.immersiveengineering.common.blocks.BlockTypes_MetalsAll) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) ResourceLocation(net.minecraft.util.ResourceLocation) Vector3f(org.lwjgl.util.vector.Vector3f) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 89 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.

the class ConveyorCovered method addCoverToQuads.

static void addCoverToQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing, Supplier<ItemStack> coverGet, ConveyorDirection conDir, boolean[] walls) {
    ItemStack cover = !coverGet.get().isEmpty() ? coverGet.get() : defaultCover;
    Block b = Block.getBlockFromItem(cover.getItem());
    IBlockState state = !cover.isEmpty() ? b.getStateFromMeta(cover.getMetadata()) : Blocks.STONE.getDefaultState();
    IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(state);
    if (model != null) {
        TextureAtlasSprite sprite = model.getParticleTexture();
        HashMap<EnumFacing, TextureAtlasSprite> sprites = new HashMap<>();
        for (EnumFacing f : EnumFacing.VALUES) for (BakedQuad q : model.getQuads(state, f, 0)) if (q != null && q.getSprite() != null)
            sprites.put(f, q.getSprite());
        for (BakedQuad q : model.getQuads(state, null, 0)) if (q != null && q.getSprite() != null && q.getFace() != null)
            sprites.put(q.getFace(), q.getSprite());
        Function<EnumFacing, TextureAtlasSprite> getSprite = f -> sprites.containsKey(f) ? sprites.get(f) : sprite;
        Function<EnumFacing, TextureAtlasSprite> getSpriteHorizontal = f -> f.getAxis() == Axis.Y ? null : sprites.containsKey(f) ? sprites.get(f) : sprite;
        float[] colour = { 1, 1, 1, 1 };
        Matrix4 matrix = new Matrix4(facing);
        Function<Vector3f[], Vector3f[]> vertexTransformer = conDir == ConveyorDirection.HORIZONTAL ? vertices -> vertices : vertices -> {
            Vector3f[] ret = new Vector3f[vertices.length];
            for (int i = 0; i < ret.length; i++) ret[i] = new Vector3f(vertices[i].x, vertices[i].y + (vertices[i].z == (conDir == ConveyorDirection.UP ? 0 : 1) ? 1 : 0), vertices[i].z);
            return ret;
        };
        baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .75f, 0), new Vector3f(1, 1, 1), matrix, facing, vertexTransformer, getSprite, colour));
        if (walls[0])
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, 0), new Vector3f(.0625f, .75f, 1), matrix, facing, vertexTransformer, getSpriteHorizontal, colour));
        else {
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, 0), new Vector3f(.0625f, .75f, .0625f), matrix, facing, getSpriteHorizontal, colour));
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, .9375f), new Vector3f(.0625f, .75f, 1), matrix, facing, getSpriteHorizontal, colour));
        }
        if (walls[1])
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, 0), new Vector3f(1, .75f, 1), matrix, facing, vertexTransformer, getSpriteHorizontal, colour));
        else {
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, 0), new Vector3f(1, .75f, .0625f), matrix, facing, getSpriteHorizontal, colour));
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, .9375f), new Vector3f(1, .75f, 1), matrix, facing, getSpriteHorizontal, colour));
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) IEContent(blusunrize.immersiveengineering.common.IEContent) Blocks(net.minecraft.init.Blocks) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumHand(net.minecraft.util.EnumHand) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ClientUtils(blusunrize.immersiveengineering.client.ClientUtils) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) OreDictionary(net.minecraftforge.oredict.OreDictionary) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nullable(javax.annotation.Nullable) BlockTypes_WoodenDecoration(blusunrize.immersiveengineering.common.blocks.wooden.BlockTypes_WoodenDecoration) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EntityItem(net.minecraft.entity.item.EntityItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Entity(net.minecraft.entity.Entity) Utils(blusunrize.immersiveengineering.common.util.Utils) ConveyorDirection(blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection) EnumFacing(net.minecraft.util.EnumFacing) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Consumer(java.util.function.Consumer) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) Vector3f(org.lwjgl.util.vector.Vector3f) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntity(net.minecraft.tileentity.TileEntity) BlockTypes_MetalDecoration1(blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration1) Axis(net.minecraft.util.EnumFacing.Axis) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) Vector3f(org.lwjgl.util.vector.Vector3f) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemStack(net.minecraft.item.ItemStack)

Example 90 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method getSideTexture.

public static ResourceLocation getSideTexture(@Nonnull IBlockState state, EnumFacing side) {
    IBakedModel model = mc().getBlockRendererDispatcher().getModelForState(state);
    List<BakedQuad> quads = model.getQuads(state, side, 0);
    if (// no quads for the specified side D:
    quads == null || quads.isEmpty())
        quads = model.getQuads(state, null, 0);
    if (// no quads at all D:
    quads == null || quads.isEmpty())
        return null;
    return new ResourceLocation(quads.get(0).getSprite().getIconName());
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Aggregations

IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)197 IBlockState (net.minecraft.block.state.IBlockState)94 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)42 BlockPos (net.minecraft.util.math.BlockPos)40 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)38 EnumFacing (net.minecraft.util.EnumFacing)38 ResourceLocation (net.minecraft.util.ResourceLocation)36 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)30 ItemStack (net.minecraft.item.ItemStack)27 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)24 Block (net.minecraft.block.Block)23 IModel (net.minecraftforge.client.model.IModel)22 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)22 ArrayList (java.util.ArrayList)20 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)17 Minecraft (net.minecraft.client.Minecraft)15 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)15 List (java.util.List)14 ItemOverride (net.minecraft.client.renderer.block.model.ItemOverride)14 ImmutableList (com.google.common.collect.ImmutableList)13