Search in sources :

Example 6 with BakedQuad

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

the class IESmartObjModel method getQuads.

public List<BakedQuad> getQuads(IBlockState blockState, EnumFacing side, long rand, OBJState objstate, Map<String, String> tex, boolean addAnimationAndTex) {
    texReplace = tex;
    this.tempState = blockState;
    if (blockState instanceof IExtendedBlockState) {
        IExtendedBlockState exState = (IExtendedBlockState) blockState;
        ExtBlockstateAdapter adapter;
        if (objstate != null) {
            if (objstate.parent == null || objstate.parent == TRSRTransformation.identity())
                objstate.parent = this.getState();
            if (objstate.getVisibilityMap().containsKey(Group.ALL) || objstate.getVisibilityMap().containsKey(Group.ALL_EXCEPT))
                this.updateStateVisibilityMap(objstate);
        }
        if (addAnimationAndTex)
            adapter = new ExtBlockstateAdapter(exState, MinecraftForgeClient.getRenderLayer(), ExtBlockstateAdapter.CONNS_OBJ_CALLBACK, new Object[] { objstate, tex });
        else
            adapter = new ExtBlockstateAdapter(exState, MinecraftForgeClient.getRenderLayer(), ExtBlockstateAdapter.CONNS_OBJ_CALLBACK);
        if (!modelCache.containsKey(adapter)) {
            IESmartObjModel model = null;
            if (objstate != null)
                model = new IESmartObjModel(baseModel, getModel(), objstate, getFormat(), getTextures(), transformationMap);
            if (model == null)
                model = new IESmartObjModel(baseModel, getModel(), this.getState(), getFormat(), getTextures(), transformationMap);
            model.tempState = blockState;
            model.texReplace = tex;
            modelCache.put(adapter, model.buildQuads());
        }
        return Collections.synchronizedList(Lists.newArrayList(modelCache.get(adapter)));
    }
    if (bakedQuads == null)
        bakedQuads = buildQuads();
    List<BakedQuad> quadList = Collections.synchronizedList(Lists.newArrayList(bakedQuads));
    return quadList;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) ExtBlockstateAdapter(blusunrize.immersiveengineering.client.models.smart.ConnModelReal.ExtBlockstateAdapter) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState)

Example 7 with BakedQuad

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

the class ModelConveyor method getQuads.

@Override
public List<BakedQuad> getQuads(@Nullable IBlockState blockState, @Nullable EnumFacing side, long rand) {
    TileEntity tile = null;
    String key = "default";
    EnumFacing facing = EnumFacing.NORTH;
    if (blockState == null)
        key = conveyor != null ? ConveyorHandler.reverseClassRegistry.get(conveyor.getClass()).toString() : "immersiveengineering:conveyor";
    else {
        facing = blockState.getValue(IEProperties.FACING_ALL);
        if (blockState instanceof IExtendedBlockState) {
            IExtendedBlockState exState = (IExtendedBlockState) blockState;
            if (exState.getUnlistedNames().contains(BlockConveyor.ICONEYOR_PASSTHROUGH))
                conveyor = ((IExtendedBlockState) blockState).getValue(BlockConveyor.ICONEYOR_PASSTHROUGH);
            if (exState.getUnlistedNames().contains(IEProperties.TILEENTITY_PASSTHROUGH))
                tile = ((IExtendedBlockState) blockState).getValue(IEProperties.TILEENTITY_PASSTHROUGH);
            if (conveyor != null && tile != null)
                key = conveyor.getModelCacheKey(tile, facing);
        }
    }
    List<BakedQuad> cachedQuads = modelCache.get(key);
    if (cachedQuads != null)
        return Collections.synchronizedList(Lists.newArrayList(cachedQuads));
    else {
        cachedQuads = Collections.synchronizedList(Lists.newArrayList());
        Matrix4f facingMatrix = TRSRTransformation.getMatrix(facing);
        if (conveyor != null)
            facingMatrix = conveyor.modifyBaseRotationMatrix(facingMatrix, tile, facing);
        Matrix4 matrix = new Matrix4(facingMatrix);
        ConveyorDirection conDir = conveyor != null ? conveyor.getConveyorDirection() : ConveyorDirection.HORIZONTAL;
        boolean[] walls = conveyor != null && tile != null ? new boolean[] { conveyor.renderWall(tile, facing, 0), conveyor.renderWall(tile, facing, 1) } : new boolean[] { true, true };
        TextureAtlasSprite tex_conveyor = ClientUtils.mc().getTextureMapBlocks().getMissingSprite();
        TextureAtlasSprite tex_conveyor_colour = null;
        int colourStripes = -1;
        if (conveyor != null) {
            tex_conveyor = ClientUtils.getSprite(tile != null ? (conveyor.isActive(tile) ? conveyor.getActiveTexture() : conveyor.getInactiveTexture()) : conveyor.getActiveTexture());
            if ((colourStripes = conveyor.getDyeColour()) >= 0)
                tex_conveyor_colour = ClientUtils.getSprite(conveyor.getColouredStripesTexture());
        }
        cachedQuads.addAll(getBaseConveyor(facing, 1, matrix, conDir, tex_conveyor, walls, new boolean[] { true, true }, tex_conveyor_colour, colourStripes));
        if (conveyor != null)
            cachedQuads = conveyor.modifyQuads(cachedQuads, tile, facing);
        modelCache.put(key, cachedQuads);
        return Collections.synchronizedList(Lists.newArrayList(cachedQuads));
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Matrix4f(javax.vecmath.Matrix4f) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) ConveyorDirection(blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Example 8 with BakedQuad

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

the class ModelConveyor method getBaseConveyor.

public static Set<BakedQuad> getBaseConveyor(EnumFacing facing, float length, Matrix4 matrix, ConveyorDirection conDir, TextureAtlasSprite tex_conveyor, boolean[] walls, boolean[] corners, TextureAtlasSprite tex_conveyor_colour, int stripeColour) {
    Set<BakedQuad> quads = new LinkedHashSet<BakedQuad>();
    Vector3f[] vertices = { new Vector3f(.0625f, 0, 1 - length), new Vector3f(.0625f, 0, 1), new Vector3f(.9375f, 0, 1), new Vector3f(.9375f, 0, 1 - length) };
    TextureAtlasSprite tex_casing0 = ClientUtils.getSprite(rl_casing[0]);
    TextureAtlasSprite tex_casing1 = ClientUtils.getSprite(rl_casing[1]);
    TextureAtlasSprite tex_casing2 = ClientUtils.getSprite(rl_casing[2]);
    float[] colour = { 1, 1, 1, 1 };
    float[] colourStripes = { (stripeColour >> 16 & 255) / 255f, (stripeColour >> 8 & 255) / 255f, (stripeColour & 255) / 255f, 1 };
    //Shift if up/down
    for (int i = 0; i < 4; i++) if ((i == 0 || i == 3) ? conDir == ConveyorDirection.UP : conDir == ConveyorDirection.DOWN)
        vertices[i].translate(0, length, 0);
    //Draw bottom
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.DOWN, facing), tex_conveyor, new double[] { 1, 0, 15, length * 16 }, colour, true));
    //Expand verts to side
    for (Vector3f v : vertices) v.setX(v.getX() < .5f ? 0 : 1);
    //Draw bottom casing
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.DOWN, facing), tex_casing2, new double[] { 0, 0, 16, length * 16 }, colour, true));
    //Shift verts to top
    for (Vector3f v : vertices) v.translate(0, .125f, 0);
    //Draw top
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), tex_conveyor, new double[] { 0, length * 16, 16, 0 }, colour, false));
    if (corners[0]) {
        vertices = new Vector3f[] { new Vector3f(0, .1875f, .9375f), new Vector3f(0, .1875f, 1), new Vector3f(1, .1875f, 1), new Vector3f(1, .1875f, .9375f) };
        //Shift if up/down
        for (int i = 0; i < 4; i++) vertices[i].translate(0, i == 0 || i == 3 ? (conDir == ConveyorDirection.UP ? .0625f : conDir == ConveyorDirection.DOWN ? length - .0625f : 0) : (conDir == ConveyorDirection.DOWN ? length : 0), 0);
        //Draw top casing back
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), tex_casing0, new double[] { 0, 1, 16, 0 }, colour, false));
    }
    if (corners[1]) {
        vertices = new Vector3f[] { new Vector3f(0, .1875f, 1 - length), new Vector3f(0, .1875f, 1.0625f - length), new Vector3f(1, .1875f, 1.0625f - length), new Vector3f(1, .1875f, 1 - length) };
        //Shift if up/down
        for (int i = 0; i < 4; i++) vertices[i].translate(0, i == 1 || i == 2 ? (conDir == ConveyorDirection.UP ? length - .0625f : conDir == ConveyorDirection.DOWN ? .0625f : 0) : (conDir == ConveyorDirection.UP ? length : 0), 0);
        //Draw top casing front
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), tex_casing0, new double[] { 0, 1, 16, 0 }, colour, false));
    }
    /**
		 * Sides
		 */
    vertices = new Vector3f[] { new Vector3f(0, 0, 1 - length), new Vector3f(0, 0, 1), new Vector3f(0, .125f, 1), new Vector3f(0, .125f, 1 - length) };
    for (int i = 0; i < 4; i++) if ((i == 0 || i == 3) ? conDir == ConveyorDirection.UP : conDir == ConveyorDirection.DOWN)
        vertices[i].translate(0, length, 0);
    //Draw left side
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), tex_casing1, new double[] { 0, 0, 2, length * 16 }, colour, false));
    //Shift upwards
    for (int i = 0; i < 4; i++) vertices[i].setY(vertices[i].getY() + ((i == 0 || i == 1) ? .125f : .0625f));
    //Shift back down and to the other side
    for (int i = 0; i < 4; i++) vertices[i].set(1, vertices[i].getY() - ((i == 0 || i == 1) ? .125f : .0625f));
    //Draw right side
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), tex_casing1, new double[] { 0, 0, 2, length * 16 }, colour, true));
    //Shift upwards
    for (int i = 0; i < 4; i++) vertices[i].setY(vertices[i].getY() + ((i == 0 || i == 1) ? .125f : .0625f));
    /**
		 * Corners
		 */
    if (corners[0]) {
        vertices = new Vector3f[] { new Vector3f(0, .125f, .9375f), new Vector3f(0, .125f, 1), new Vector3f(0, .1875f, 1), new Vector3f(0, .1875f, .9375f) };
        if (conDir != ConveyorDirection.HORIZONTAL)
            for (int i = 0; i < 4; i++) vertices[i].translate(0, i == 0 || i == 3 ? (conDir == ConveyorDirection.UP ? .0625f : conDir == ConveyorDirection.DOWN ? length - .0625f : 0) : (conDir == ConveyorDirection.DOWN ? length : 0), 0);
        //Back left
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), tex_casing0, new double[] { 0, 0, 1, 1 }, colour, false));
        for (Vector3f v : vertices) v.translate(.0625f, 0, 0);
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), tex_casing0, new double[] { 0, 0, 1, 1 }, colour, true));
        //Shift right
        for (Vector3f v : vertices) v.setX(1);
        //Back right
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), tex_casing0, new double[] { 0, 0, 1, 1 }, colour, true));
        for (Vector3f v : vertices) v.translate(-.0625f, 0, 0);
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), tex_casing0, new double[] { 0, 0, 1, 1 }, colour, false));
    }
    if (corners[1]) {
        vertices = new Vector3f[] { new Vector3f(0, .125f, 1 - length), new Vector3f(0, .125f, 1.0625f - length), new Vector3f(0, .1875f, 1.0625f - length), new Vector3f(0, .1875f, 1 - length) };
        if (conDir != ConveyorDirection.HORIZONTAL)
            for (int i = 0; i < 4; i++) vertices[i].translate(0, i == 1 || i == 2 ? (conDir == ConveyorDirection.UP ? length - .0625f : conDir == ConveyorDirection.DOWN ? .0625f : 0) : (conDir == ConveyorDirection.UP ? length : 0), 0);
        //Front left
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), tex_casing0, new double[] { 0, 15, 1, 16 }, colour, false));
        for (Vector3f v : vertices) v.translate(.0625f, 0, 0);
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), tex_casing0, new double[] { 0, 15, 1, 16 }, colour, true));
        //Shift right
        for (Vector3f v : vertices) v.setX(1);
        //Front right
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), tex_casing0, new double[] { 0, 15, 1, 16 }, colour, true));
        for (Vector3f v : vertices) v.translate(-.0625f, 0, 0);
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), tex_casing0, new double[] { 0, 15, 1, 16 }, colour, false));
    }
    /**
		 * Front & Back
		 */
    vertices = new Vector3f[] { new Vector3f(.0625f, 0, 1 - length), new Vector3f(.0625f, .125f, 1 - length), new Vector3f(.9375f, .125f, 1 - length), new Vector3f(.9375f, 0, 1 - length) };
    //Shift if up/down
    if (conDir == ConveyorDirection.UP)
        for (Vector3f v : vertices) v.translate(0, length, 0);
    //Draw front
    double frontUMax = (1 - length) * 16;
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing, tex_conveyor, new double[] { 1, frontUMax + 2, 15, frontUMax }, colour, false));
    //Expand to side and up
    for (int i = 0; i < 4; i++) vertices[i].set(vertices[i].getX() < .5f ? 0 : 1, vertices[i].getY() + (i == 1 || i == 2 ? .0625f : 0));
    //Draw front casing
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing, tex_casing2, new double[] { 0, 3, 16, 0 }, colour, false));
    for (Vector3f v : vertices) v.translate(0, (conDir == ConveyorDirection.UP ? -.0625f : conDir == ConveyorDirection.DOWN ? .0625f : 0), .0625f);
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing, tex_casing2, new double[] { 0, 3, 16, 0 }, colour, true));
    //Undo expand, shift if up/down, shift to back
    for (int i = 0; i < 4; i++) {
        Vector3f v = vertices[i];
        v.setX(v.getX() < .5f ? .0625f : .9375f);
        v.setY(v.getY() - (i == 1 || i == 2 ? .0625f : 0));
        if (conDir == ConveyorDirection.UP)
            v.translate(0, -(length - .0625f), 0);
        if (conDir == ConveyorDirection.DOWN)
            v.translate(0, (length - .0625f), 0);
        v.translate(0, 0, length - .0625f);
    }
    //Draw back
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing.getOpposite(), tex_conveyor, new double[] { 1, 0, 15, 2 }, colour, true));
    //Expand to side and up
    for (int i = 0; i < 4; i++) vertices[i].set(vertices[i].getX() < .5f ? 0 : 1, vertices[i].getY() + (i == 1 || i == 2 ? .0625f : 0));
    //Draw back casing
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing.getOpposite(), tex_casing2, new double[] { 0, 0, 16, 3 }, colour, true));
    for (Vector3f v : vertices) v.translate(0, conDir == ConveyorDirection.UP ? .0625f : conDir == ConveyorDirection.DOWN ? -.0625f : 0, -.0625f);
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing.getOpposite(), tex_casing2, new double[] { 0, 0, 16, 3 }, colour, false));
    /**
		 * Walls
		 */
    float wallLength = length - .125f;
    vertices = new Vector3f[] { new Vector3f(0, .1875f, .9375f - wallLength), new Vector3f(0, .1875f, .9375f), new Vector3f(.0625f, .1875f, .9375f), new Vector3f(.0625f, .1875f, .9375f - wallLength) };
    Vector3f[] vertices2 = new Vector3f[] { new Vector3f(0, .125f, .9375f - wallLength), new Vector3f(0, .125f, .9375f), new Vector3f(0, .1875f, .9375f), new Vector3f(0, .1875f, .9375f - wallLength) };
    Vector3f[] vertices3 = new Vector3f[] { new Vector3f(.0625f, .125f, .9375f - wallLength), new Vector3f(.0625f, .125f, .9375f), new Vector3f(.0625f, .1875f, .9375f), new Vector3f(.0625f, .1875f, .9375f - wallLength) };
    Vector3f[] verticesColour = new Vector3f[] { new Vector3f(0, .1876f, corners[1] ? (1 - length) : (.9375f - wallLength)), new Vector3f(0, .1876f, corners[0] ? 1 : .9375f), new Vector3f(.0625f, .1876f, corners[0] ? 1 : .9375f), new Vector3f(.0625f, .1876f, corners[1] ? (1 - length) : (.9375f - wallLength)) };
    for (int i = 0; i < 4; i++) if (conDir != ConveyorDirection.HORIZONTAL) {
        float f = (i == 0 || i == 3) ? (conDir == ConveyorDirection.UP ? length - .0625f : .0625f) : (conDir == ConveyorDirection.UP ? .0625f : length - .0625f);
        vertices[i].translate(0, f, 0);
        vertices2[i].translate(0, f, 0);
        vertices3[i].translate(0, f, 0);
        verticesColour[i].translate(0, f, 0);
    }
    //Draw left walls
    if (walls[0]) {
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), tex_casing2, new double[] { 0, wallLength * 16, 1, 1 }, colour, false));
        if (tex_conveyor_colour != null && stripeColour >= 0)
            quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, verticesColour), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), tex_conveyor_colour, new double[] { 0, wallLength * 16, 1, 1 }, colourStripes, false));
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices2), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), tex_casing1, new double[] { 2, wallLength * 16, 3, 1 }, colour, false));
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices3), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), tex_casing1, new double[] { 2, wallLength * 16, 3, 1 }, colour, true));
    }
    for (int i = 0; i < 4; i++) {
        vertices[i].translate(.9375f, 0, 0);
        vertices2[i].translate(.9375f, 0, 0);
        vertices3[i].translate(.9375f, 0, 0);
        verticesColour[i].translate(.9375f, 0, 0);
    }
    //Draw right walls
    if (walls[1]) {
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), tex_casing2, new double[] { 15, wallLength * 16, 16, 1 }, colour, false));
        if (tex_conveyor_colour != null && stripeColour >= 0)
            quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, verticesColour), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), tex_conveyor_colour, new double[] { 15, wallLength * 16, 16, 1 }, colourStripes, false));
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices2), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), tex_casing1, new double[] { 2, wallLength * 16, 3, 1 }, colour, false));
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices3), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), tex_casing1, new double[] { 2, wallLength * 16, 3, 1 }, colour, true));
    }
    return quads;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 9 with BakedQuad

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

the class ModelCoresample method getQuads.

//	@Override
//	public List<BakedQuad> getFaceQuads(EnumFacing p_177551_1_)
//	{
//		return emptyQuads;
//	}
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState blockState, @Nullable EnumFacing side, long rand) {
    if (bakedQuads == null) {
        try {
            bakedQuads = Collections.synchronizedSet(new LinkedHashSet<BakedQuad>());
            float width = .25f;
            float depth = .25f;
            float wOff = (1 - width) / 2;
            float dOff = (1 - depth) / 2;
            int pixelLength = 0;
            HashMap<TextureAtlasSprite, Integer> textureOre = new HashMap();
            if (mineral != null && mineral.oreOutput != null) {
                for (int i = 0; i < mineral.oreOutput.length; i++) if (mineral.oreOutput[i] != null) {
                    int weight = Math.max(2, Math.round(16 * mineral.recalculatedChances[i]));
                    Block b = Block.getBlockFromItem(mineral.oreOutput[i].getItem());
                    IBlockState state = b != null ? b.getStateFromMeta(mineral.oreOutput[i].getMetadata()) : Blocks.STONE.getDefaultState();
                    IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(state);
                    if (model != null && model.getParticleTexture() != null)
                        textureOre.put(model.getParticleTexture(), weight);
                    pixelLength += weight;
                }
            } else
                pixelLength = 16;
            TextureAtlasSprite textureStone = ClientUtils.getSprite(new ResourceLocation("blocks/stone"));
            Vector2f[] stoneUVs = { new Vector2f(textureStone.getInterpolatedU(16 * wOff), textureStone.getInterpolatedV(16 * dOff)), new Vector2f(textureStone.getInterpolatedU(16 * wOff), textureStone.getInterpolatedV(16 * (dOff + depth))), new Vector2f(textureStone.getInterpolatedU(16 * (wOff + width)), textureStone.getInterpolatedV(16 * (dOff + depth))), new Vector2f(textureStone.getInterpolatedU(16 * (wOff + width)), textureStone.getInterpolatedV(16 * dOff)) };
            putVertexData(new Vector3f(0, -1, 0), new Vector3f[] { new Vector3f(wOff, 0, dOff), new Vector3f(wOff + width, 0, dOff), new Vector3f(wOff + width, 0, dOff + depth), new Vector3f(wOff, 0, dOff + depth) }, stoneUVs, textureStone);
            putVertexData(new Vector3f(0, 1, 0), new Vector3f[] { new Vector3f(wOff, 1, dOff), new Vector3f(wOff, 1, dOff + depth), new Vector3f(wOff + width, 1, dOff + depth), new Vector3f(wOff + width, 1, dOff) }, stoneUVs, textureStone);
            if (textureOre.isEmpty()) {
                Vector2f[][] uvs = new Vector2f[4][];
                for (int j = 0; j < 4; j++) uvs[j] = new Vector2f[] { new Vector2f(textureStone.getInterpolatedU(j * 4), textureStone.getInterpolatedV(0)), new Vector2f(textureStone.getInterpolatedU(j * 4), textureStone.getInterpolatedV(16)), new Vector2f(textureStone.getInterpolatedU((j + 1) * 4), textureStone.getInterpolatedV(16)), new Vector2f(textureStone.getInterpolatedU((j + 1) * 4), textureStone.getInterpolatedV(0)) };
                putVertexData(new Vector3f(0, 0, -1), new Vector3f[] { new Vector3f(wOff, 0, dOff), new Vector3f(wOff, 1, dOff), new Vector3f(wOff + width, 1, dOff), new Vector3f(wOff + width, 0, dOff) }, uvs[0], textureStone);
                putVertexData(new Vector3f(0, 0, 1), new Vector3f[] { new Vector3f(wOff + width, 0, dOff + depth), new Vector3f(wOff + width, 1, dOff + depth), new Vector3f(wOff, 1, dOff + depth), new Vector3f(wOff, 0, dOff + depth) }, uvs[2], textureStone);
                putVertexData(new Vector3f(-1, 0, 0), new Vector3f[] { new Vector3f(wOff, 0, dOff + depth), new Vector3f(wOff, 1, dOff + depth), new Vector3f(wOff, 1, dOff), new Vector3f(wOff, 0, dOff) }, uvs[3], textureStone);
                putVertexData(new Vector3f(1, 0, 0), new Vector3f[] { new Vector3f(wOff + width, 0, dOff), new Vector3f(wOff + width, 1, dOff), new Vector3f(wOff + width, 1, dOff + depth), new Vector3f(wOff + width, 0, dOff + depth) }, uvs[1], textureStone);
            } else {
                float h = 0;
                for (TextureAtlasSprite sprite : textureOre.keySet()) {
                    int weight = textureOre.get(sprite);
                    int v = weight > 8 ? 16 - weight : 8;
                    Vector2f[][] uvs = new Vector2f[4][];
                    for (int j = 0; j < 4; j++) uvs[j] = new Vector2f[] { new Vector2f(sprite.getInterpolatedU(j * 4), sprite.getInterpolatedV(v)), new Vector2f(sprite.getInterpolatedU(j * 4), sprite.getInterpolatedV(v + weight)), new Vector2f(sprite.getInterpolatedU((j + 1) * 4), sprite.getInterpolatedV(v + weight)), new Vector2f(sprite.getInterpolatedU((j + 1) * 4), sprite.getInterpolatedV(v)) };
                    float h1 = weight / (float) pixelLength;
                    putVertexData(new Vector3f(0, 0, -1), new Vector3f[] { new Vector3f(wOff, h, dOff), new Vector3f(wOff, h + h1, dOff), new Vector3f(wOff + width, h + h1, dOff), new Vector3f(wOff + width, h, dOff) }, uvs[0], sprite);
                    putVertexData(new Vector3f(0, 0, 1), new Vector3f[] { new Vector3f(wOff + width, h, dOff + depth), new Vector3f(wOff + width, h + h1, dOff + depth), new Vector3f(wOff, h + h1, dOff + depth), new Vector3f(wOff, h, dOff + depth) }, uvs[2], sprite);
                    putVertexData(new Vector3f(-1, 0, 0), new Vector3f[] { new Vector3f(wOff, h, dOff + depth), new Vector3f(wOff, h + h1, dOff + depth), new Vector3f(wOff, h + h1, dOff), new Vector3f(wOff, h, dOff) }, uvs[3], sprite);
                    putVertexData(new Vector3f(1, 0, 0), new Vector3f[] { new Vector3f(wOff + width, h, dOff), new Vector3f(wOff + width, h + h1, dOff), new Vector3f(wOff + width, h + h1, dOff + depth), new Vector3f(wOff + width, h, dOff + depth) }, uvs[1], sprite);
                    h += h1;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (bakedQuads != null && !bakedQuads.isEmpty()) {
        List<BakedQuad> quadList = Collections.synchronizedList(Lists.newArrayList(bakedQuads));
        return quadList;
    }
    return emptyQuads;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) IBlockState(net.minecraft.block.state.IBlockState) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector2f(org.lwjgl.util.vector.Vector2f) ResourceLocation(net.minecraft.util.ResourceLocation) Vector3f(org.lwjgl.util.vector.Vector3f) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 10 with BakedQuad

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

the class ClientUtils method createBakedBox.

public static Set<BakedQuad> createBakedBox(Vector3f from, Vector3f to, Matrix4 matrix, EnumFacing facing, Function<Vector3f[], Vector3f[]> vertexTransformer, Function<EnumFacing, TextureAtlasSprite> textureGetter, float[] colour) {
    HashSet quads = new HashSet();
    if (vertexTransformer == null)
        vertexTransformer = v -> v;
    Vector3f[] vertices = { new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, from.y, to.z), new Vector3f(to.x, from.y, to.z), new Vector3f(to.x, from.y, from.z) };
    TextureAtlasSprite sprite = textureGetter.apply(EnumFacing.DOWN);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.DOWN, facing), sprite, new double[] { from.x * 16, 16 - from.z * 16, to.x * 16, 16 - to.z * 16 }, colour, true));
    for (Vector3f v : vertices) v.setY(to.y);
    sprite = textureGetter.apply(EnumFacing.UP);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), sprite, new double[] { from.x * 16, from.z * 16, to.x * 16, to.z * 16 }, colour, false));
    vertices = new Vector3f[] { new Vector3f(to.x, to.y, from.z), new Vector3f(to.x, from.y, from.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
    sprite = textureGetter.apply(EnumFacing.NORTH);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.NORTH, facing), sprite, new double[] { from.x * 16, 16 - to.y * 16, to.x * 16, 16 - from.y * 16 }, colour, false));
    for (Vector3f v : vertices) v.setZ(to.z);
    sprite = textureGetter.apply(EnumFacing.SOUTH);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.SOUTH, facing), sprite, new double[] { to.x * 16, 16 - to.y * 16, from.x * 16, 16 - from.y * 16 }, colour, true));
    vertices = new Vector3f[] { new Vector3f(from.x, to.y, to.z), new Vector3f(from.x, from.y, to.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
    sprite = textureGetter.apply(EnumFacing.WEST);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), sprite, new double[] { to.z * 16, 16 - to.y * 16, from.z * 16, 16 - from.y * 16 }, colour, true));
    for (Vector3f v : vertices) v.setX(to.x);
    sprite = textureGetter.apply(EnumFacing.EAST);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), sprite, new double[] { from.z * 16, 16 - to.y * 16, to.z * 16, 16 - from.y * 16 }, colour, false));
    return quads;
}
Also used : net.minecraft.util(net.minecraft.util) Normal(net.minecraftforge.client.model.obj.OBJModel.Normal) ModelBox(net.minecraft.client.model.ModelBox) AttenuationType(net.minecraft.client.audio.ISound.AttenuationType) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) ModelRenderer(net.minecraft.client.model.ModelRenderer) I18n(net.minecraft.client.resources.I18n) Vec3i(net.minecraft.util.math.Vec3i) Vec3d(net.minecraft.util.math.Vec3d) Lib(blusunrize.immersiveengineering.api.Lib) GL11(org.lwjgl.opengl.GL11) IEProperties(blusunrize.immersiveengineering.api.IEProperties) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Quat4d(javax.vecmath.Quat4d) Vector3f(org.lwjgl.util.vector.Vector3f) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank) net.minecraft.client.renderer(net.minecraft.client.renderer) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) java.util(java.util) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SmartLightingQuad(blusunrize.immersiveengineering.client.models.SmartLightingQuad) Function(java.util.function.Function) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) IEFluid(blusunrize.immersiveengineering.common.util.IEFluid) net.minecraft.block(net.minecraft.block) Minecraft(net.minecraft.client.Minecraft) Nonnull(javax.annotation.Nonnull) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Entity(net.minecraft.entity.Entity) Utils(blusunrize.immersiveengineering.common.util.Utils) World(net.minecraft.world.World) TextFormatting(net.minecraft.util.text.TextFormatting) TextureMap(net.minecraft.client.renderer.texture.TextureMap) Timer(net.minecraft.util.Timer) BlockPos(net.minecraft.util.math.BlockPos) TextureManager(net.minecraft.client.renderer.texture.TextureManager) ModelBase(net.minecraft.client.model.ModelBase) IETileSound(blusunrize.immersiveengineering.common.util.sound.IETileSound) IBlockState(net.minecraft.block.state.IBlockState) GuiScreen(net.minecraft.client.gui.GuiScreen) FontRenderer(net.minecraft.client.gui.FontRenderer) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) Material(net.minecraft.block.material.Material) TileEntity(net.minecraft.tileentity.TileEntity) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3f(org.lwjgl.util.vector.Vector3f)

Aggregations

BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)30 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)13 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)12 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)8 EnumFacing (net.minecraft.util.EnumFacing)8 Tessellator (net.minecraft.client.renderer.Tessellator)6 Vec3i (net.minecraft.util.math.Vec3i)6 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)5 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)5 Vector3f (org.lwjgl.util.vector.Vector3f)5 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)4 ImmutableList (com.google.common.collect.ImmutableList)4 IBlockState (net.minecraft.block.state.IBlockState)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 BlockPos (net.minecraft.util.math.BlockPos)4 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)4 HashMap (java.util.HashMap)3 TransformType (net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)3 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)2 ConveyorDirection (blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection)2