Search in sources :

Example 1 with SimpleBakedModel

use of pl.asie.charset.lib.render.model.SimpleBakedModel in project Charset by CharsetMC.

the class RendererWire method bake.

@Override
public IBakedModel bake(Wire wire, boolean isItem, BlockRenderLayer layer) {
    SimpleBakedModel model = new SimpleBakedModel(this);
    if (wire != null) {
        WireSheet sheet = sheetMap.get(wire.getFactory());
        if (sheet != null) {
            model.setParticle(sheet.particle);
            addWire(wire, sheet, model.getQuads(null, null, 0));
        }
    }
    return model;
}
Also used : SimpleBakedModel(pl.asie.charset.lib.render.model.SimpleBakedModel)

Example 2 with SimpleBakedModel

use of pl.asie.charset.lib.render.model.SimpleBakedModel in project Charset by CharsetMC.

the class RendererGate method bake.

@Override
public IBakedModel bake(PartGate gate, boolean isItem, BlockRenderLayer blockRenderLayer) {
    SimpleBakedModel result = new SimpleBakedModel(this);
    ModelStateComposition transform = new ModelStateComposition(new TRSRTransformation(ROTATIONS_SIDE[gate.getSide().ordinal()]), new TRSRTransformation(ROTATIONS_TOP[gate.getTop().ordinal()]));
    if (gate.mirrored) {
        transform = new ModelStateComposition(transform, new TRSRTransformation(null, null, new Vector3f(-1.0f, 1.0f, 1.0f), null));
    }
    GateLogic logic = gate.logic;
    GateRenderDefinitions.Definition definition = GateRenderDefinitions.INSTANCE.getGateDefinition(SimpleLogicGates.getId(logic));
    if (definition == null) {
        result.addModel(ModelLoaderRegistry.getMissingModel().bake(transform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
        return result;
    }
    GateRenderDefinitions.BaseDefinition base = GateRenderDefinitions.INSTANCE.base;
    IModel model = definition.getModel(gate.getModelName());
    if (model != null) {
        result.addModel(model.bake(transform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
    }
    IModel layerModel = definition.getModel("layer");
    int i = 0;
    for (GateRenderDefinitions.Layer layer : definition.layers) {
        GateLogic.State state = gate.logic.getLayerState(i++);
        if (state == GateLogic.State.NO_RENDER) {
            continue;
        }
        IModelState layerTransform = transform;
        if (layer.height != 0) {
            layerTransform = new ModelStateComposition(new TRSRTransformation(new Vector3f(0, (float) layer.height / 16f, 0), null, null, null), transform);
        }
        if ("color".equals(layer.type) && layer.texture != null) {
            model = layerModels.get(layer.texture);
            if (model == null) {
                model = layerModel.retexture(ImmutableMap.of("layer", layer.texture));
                layerModels.put(layer.texture, model);
            }
            IBakedModel bakedModel = model.bake(layerTransform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter());
            int color = state == GateLogic.State.ON ? base.colorMul.get("on") : (state == GateLogic.State.OFF ? base.colorMul.get("off") : base.colorMul.get("disabled"));
            result.addModel(ModelTransformer.transform(bakedModel, SimpleLogicGates.blockGate.getDefaultState(), 0, ((quad, element, data) -> {
                if (element.getUsage() == VertexFormatElement.EnumUsage.COLOR) {
                    return new float[] { ((color) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, ((color >> 16) & 0xFF) / 255.0f, 1 };
                } else {
                    return data;
                }
            })));
        } else if ("map".equals(layer.type) && layer.textures != null) {
            String texture = layer.textures.get(state.name().toLowerCase(Locale.ENGLISH));
            if (texture == null) {
                texture = layer.textures.get("off");
                if (texture == null) {
                    texture = layer.textures.get("disabled");
                }
            }
            if (texture != null) {
                model = layerModels.get(texture);
                if (model == null) {
                    model = layerModel.retexture(ImmutableMap.of("layer", texture));
                    layerModels.put(texture, model);
                }
                result.addModel(model.bake(layerTransform, DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
            }
        }
    }
    Set<EnumFacing> invertedSides = EnumSet.noneOf(EnumFacing.class);
    i = 0;
    for (GateRenderDefinitions.Torch torch : definition.torches) {
        GateLogic.State state = gate.logic.getTorchState(i++);
        if (state == GateLogic.State.NO_RENDER) {
            continue;
        }
        if (torch.inverter != null) {
            EnumFacing inverter = EnumFacing.byName(torch.inverter);
            if (gate.logic.isSideInverted(inverter)) {
                invertedSides.add(inverter);
            } else {
                continue;
            }
        }
        result.addModel(definition.getModel(state == GateLogic.State.ON ? (torch.model_on == null ? "torch_on" : torch.model_on) : (torch.model_off == null ? "torch_off" : torch.model_off)).bake(new ModelStateComposition(transform, new TRSRTransformation(new Vector3f((torch.pos[0] - 7.5f) / 16.0f, 0f, (torch.pos[1] - 7.5f) / 16.0f), null, null, null)), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
    }
    for (EnumFacing facing : EnumFacing.HORIZONTALS) {
        if (gate.logic.isSideInverted(facing) && !invertedSides.contains(facing)) {
            result.addModel(definition.getModel(gate.getInverterState(facing) ? "torch_on" : "torch_off").bake(new ModelStateComposition(transform, new TRSRTransformation(new Vector3f(((facing.getFrontOffsetX() * 6.9875f)) / 16.0f, 0f, ((facing.getFrontOffsetZ() * 6.9875f)) / 16.0f), null, null, null)), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()));
        }
    }
    return result;
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) IModel(net.minecraftforge.client.model.IModel) EnumFacing(net.minecraft.util.EnumFacing) IModelState(net.minecraftforge.common.model.IModelState) SimpleBakedModel(pl.asie.charset.lib.render.model.SimpleBakedModel) GateLogic(pl.asie.simplelogic.gates.logic.GateLogic) ModelStateComposition(net.minecraftforge.client.model.ModelStateComposition) Vector3f(javax.vecmath.Vector3f) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 3 with SimpleBakedModel

use of pl.asie.charset.lib.render.model.SimpleBakedModel in project Charset by CharsetMC.

the class TileRendererCauldronCharset method renderTileEntityFast.

@Override
public void renderTileEntityFast(TileCauldronCharset te, double x, double y, double z, float partialTicks, int destroyStage, float partial, BufferBuilder buffer) {
    BlockPos pos = te.getPos();
    FluidStack contents = te.getContents();
    if (contents == null) {
        return;
    }
    buffer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
    IBlockState state = getFluidState(contents, Blocks.AIR.getDefaultState());
    IBakedModel model;
    TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
    TextureAtlasSprite sprite = map.getTextureExtry(contents.getFluid().getStill().toString());
    if (sprite == null) {
        sprite = map.getTextureExtry(TextureMap.LOCATION_MISSING_TEXTURE.toString());
        if (sprite == null)
            return;
    }
    float height = te.getFluidHeight();
    SimpleBakedModel smodel = new SimpleBakedModel();
    int color = contents.getFluid().getColor(contents);
    Vector3f from = new Vector3f(2, height, 2);
    Vector3f to = new Vector3f(14, height, 14);
    smodel.addQuad(null, RenderUtils.createQuad(from, to, EnumFacing.UP, sprite, -1));
    if (color == -1) {
        model = smodel;
    } else {
        model = ModelTransformer.transform(smodel, state, 0L, new FluidColorTransformer(color));
    }
    int light = contents.getFluid().getLuminosity();
    IBlockAccess tankAccess = new TankBlockAccess(te.getWorld(), light);
    renderer.renderModel(tankAccess, model, state, pos, buffer, false, 0L);
    buffer.setTranslation(0, 0, 0);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FluidStack(net.minecraftforge.fluids.FluidStack) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) IBlockAccess(net.minecraft.world.IBlockAccess) SimpleBakedModel(pl.asie.charset.lib.render.model.SimpleBakedModel) TextureMap(net.minecraft.client.renderer.texture.TextureMap) Vector3f(org.lwjgl.util.vector.Vector3f) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 4 with SimpleBakedModel

use of pl.asie.charset.lib.render.model.SimpleBakedModel in project Charset by CharsetMC.

the class TileTankRenderer method renderModel.

// TODO: Rewrite this to render per-tank-block?
public static void renderModel(IBlockAccess access, BlockPos pos, BufferBuilder buffer, TileTank tank, FluidStack contents, int tankCount) {
    IBlockState state = getFluidState(contents, Blocks.AIR.getDefaultState());
    IBakedModel model;
    TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
    TextureAtlasSprite sprite = map.getTextureExtry(contents.getFluid().getStill().toString());
    if (sprite == null) {
        sprite = map.getTextureExtry(TextureMap.LOCATION_MISSING_TEXTURE.toString());
        if (sprite == null)
            return;
    }
    float height = (float) (contents.amount) / TileTank.CAPACITY;
    SimpleBakedModel smodel = new SimpleBakedModel();
    int color = contents.getFluid().getColor(contents);
    Vector3f from = new Vector3f(1.025f, 0.025f, 1.025f);
    Vector3f to = new Vector3f(14.975f, Math.min(16 * tankCount - 0.025f, height * 16), 14.975f);
    smodel.addQuad(null, RenderUtils.createQuad(from, to, EnumFacing.DOWN, sprite, -1));
    smodel.addQuad(null, RenderUtils.createQuad(from, to, EnumFacing.UP, sprite, -1));
    for (int i = 0; i < to.y; i += 16) {
        Vector3f fromL = new Vector3f(from.x, (from.y > i ? from.y : i), from.z);
        Vector3f toL = new Vector3f(to.x, (to.y < (i + 16) ? to.y : i + 16), to.z);
        for (EnumFacing facing : EnumFacing.HORIZONTALS) {
            smodel.addQuad(null, RenderUtils.createQuad(fromL, toL, facing, sprite, -1));
        }
    }
    if (color == -1) {
        model = smodel;
    } else {
        model = ModelTransformer.transform(smodel, state, 0L, new FluidColorTransformer(color));
    }
    int light = contents.getFluid().getLuminosity();
    IBlockAccess tankAccess = new TankBlockAccess(access, light);
    renderer.renderModel(tankAccess, model, state, pos, buffer, false, 0L);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) TextureMap(net.minecraft.client.renderer.texture.TextureMap) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3f(org.lwjgl.util.vector.Vector3f) EnumFacing(net.minecraft.util.EnumFacing) IBlockAccess(net.minecraft.world.IBlockAccess) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) SimpleBakedModel(pl.asie.charset.lib.render.model.SimpleBakedModel)

Aggregations

SimpleBakedModel (pl.asie.charset.lib.render.model.SimpleBakedModel)4 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)3 IBlockState (net.minecraft.block.state.IBlockState)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 TextureMap (net.minecraft.client.renderer.texture.TextureMap)2 EnumFacing (net.minecraft.util.EnumFacing)2 IBlockAccess (net.minecraft.world.IBlockAccess)2 Vector3f (org.lwjgl.util.vector.Vector3f)2 Vector3f (javax.vecmath.Vector3f)1 BlockPos (net.minecraft.util.math.BlockPos)1 IModel (net.minecraftforge.client.model.IModel)1 ModelStateComposition (net.minecraftforge.client.model.ModelStateComposition)1 IModelState (net.minecraftforge.common.model.IModelState)1 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 GateLogic (pl.asie.simplelogic.gates.logic.GateLogic)1