Search in sources :

Example 6 with Vector3f

use of org.lwjgl.util.vector.Vector3f in project Voxel_Game by ASasseCreations.

the class ChunkSystem method checkLeftClick.

public static final void checkLeftClick(final Inventory inventory) {
    final Vec3 block = BlockRaycast.cast();
    if (block != null) {
        final Chunk chunk = Chunk.getChunk((int) Math.floor(block.x / Chunk.H_SIZE), (int) Math.floor(block.z / Chunk.H_SIZE));
        if (chunk != null) {
            final Vector3f blockToSet = Chunk.getBlockCoordinates(block.x, block.y, block.z);
            if (chunk.blocks[(int) blockToSet.x][(int) blockToSet.y][(int) blockToSet.z] != null && !chunk.blocks[(int) blockToSet.x][(int) blockToSet.y][(int) blockToSet.z].preset.breakable)
                return;
            inventory.addBlock(chunk.blocks[(int) blockToSet.x][(int) blockToSet.y][(int) blockToSet.z].preset);
            chunk.blocks[(int) blockToSet.x][(int) blockToSet.y][(int) blockToSet.z] = null;
            chunk.modified.put(new Vector3f((int) blockToSet.x, (int) blockToSet.y, (int) blockToSet.z), -1);
            {
                final int cx = chunk.x;
                final int cz = chunk.z;
                addToQueues(chunk);
                addToQueues(Chunk.getChunk(cx - 1, cz));
                addToQueues(Chunk.getChunk(cx + 1, cz));
                addToQueues(Chunk.getChunk(cx, cz - 1));
                addToQueues(Chunk.getChunk(cx, cz + 1));
            }
        }
    }
}
Also used : Vec3(org.asassecreations.engine.math.vector.Vec3) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 7 with Vector3f

use of org.lwjgl.util.vector.Vector3f in project ImmersiveEngineering by BluSunrize.

the class ModelConfigurableSides method bakeQuads.

private static List<BakedQuad> bakeQuads(TextureAtlasSprite[] sprites) {
    List<BakedQuad> quads = Lists.newArrayListWithExpectedSize(6);
    float[] colour = { 1, 1, 1, 1 };
    Vector3f[] vertices = { new Vector3f(0, 0, 0), new Vector3f(0, 0, 1), new Vector3f(1, 0, 1), new Vector3f(1, 0, 0) };
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.DOWN, sprites[0], new double[] { 0, 16, 16, 0 }, colour, true));
    vertices = new Vector3f[] { new Vector3f(0, 1, 0), new Vector3f(0, 1, 1), new Vector3f(1, 1, 1), new Vector3f(1, 1, 0) };
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.UP, sprites[1], new double[] { 0, 0, 16, 16 }, colour, false));
    vertices = new Vector3f[] { new Vector3f(1, 0, 0), new Vector3f(1, 1, 0), new Vector3f(0, 1, 0), new Vector3f(0, 0, 0) };
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.NORTH, sprites[2], new double[] { 0, 16, 16, 0 }, colour, true));
    vertices = new Vector3f[] { new Vector3f(1, 0, 1), new Vector3f(1, 1, 1), new Vector3f(0, 1, 1), new Vector3f(0, 0, 1) };
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.SOUTH, sprites[3], new double[] { 16, 16, 0, 0 }, colour, false));
    vertices = new Vector3f[] { new Vector3f(0, 0, 0), new Vector3f(0, 1, 0), new Vector3f(0, 1, 1), new Vector3f(0, 0, 1) };
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.WEST, sprites[4], new double[] { 0, 16, 16, 0 }, colour, true));
    vertices = new Vector3f[] { new Vector3f(1, 0, 0), new Vector3f(1, 1, 0), new Vector3f(1, 1, 1), new Vector3f(1, 0, 1) };
    quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.EAST, sprites[5], new double[] { 16, 16, 0, 0 }, colour, false));
    return quads;
}
Also used : Vector3f(org.lwjgl.util.vector.Vector3f)

Example 8 with Vector3f

use of org.lwjgl.util.vector.Vector3f 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 Vector3f

use of org.lwjgl.util.vector.Vector3f 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 Vector3f

use of org.lwjgl.util.vector.Vector3f in project Voxel_Game by ASasseCreations.

the class ImageBilinearFilter method getColor.

// Vector3f is from LWJGL
public static final java.awt.Color getColor(final BufferedImage image, final float x, final int y) {
    final float imageX = x * image.getWidth();
    final float decimal = imageX % 1f;
    final java.awt.Color left = new java.awt.Color(image.getRGB(Mathi.constrain((int) imageX - 1, 0, image.getWidth() - 1), y));
    final java.awt.Color center = new java.awt.Color(image.getRGB(Mathi.constrain((int) imageX, 0, image.getWidth() - 1), y));
    final java.awt.Color right = new java.awt.Color(image.getRGB(Mathi.constrain((int) imageX + 1, 0, image.getWidth() - 1), y));
    if (decimal == 0.5f)
        return center;
    if (decimal < 0.5f) {
        final float distanceFromCenter = 0.5f - decimal;
        final float distanceFromLeft = decimal + 0.5f;
        final Vector3f leftColor = new Vector3f(left.getRed() / 255f, left.getGreen() / 255f, left.getBlue() / 255f);
        final Vector3f centerColor = new Vector3f(center.getRed() / 255f, center.getGreen() / 255f, center.getBlue() / 255f);
        leftColor.scale(1f - distanceFromLeft);
        centerColor.scale(1f - distanceFromCenter);
        final Vector3f color = Vector3f.add(leftColor, centerColor, null);
        return new java.awt.Color(color.getX(), color.getY(), color.getZ());
    } else {
        final float distanceFromCenter = decimal - 0.5f;
        final float distanceFromRight = 1f - decimal + 0.5f;
        final Vector3f rightColor = new Vector3f(right.getRed() / 255f, right.getGreen() / 255f, right.getBlue() / 255f);
        final Vector3f centerColor = new Vector3f(center.getRed() / 255f, center.getGreen() / 255f, center.getBlue() / 255f);
        rightColor.scale(1f - distanceFromRight);
        centerColor.scale(1f - distanceFromCenter);
        final Vector3f color = Vector3f.add(rightColor, centerColor, null);
        return new java.awt.Color(color.getX(), color.getY(), color.getZ());
    }
}
Also used : Vector3f(org.lwjgl.util.vector.Vector3f)

Aggregations

Vector3f (org.lwjgl.util.vector.Vector3f)15 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)5 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)5 ArrayList (java.util.ArrayList)4 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)3 IBlockState (net.minecraft.block.state.IBlockState)3 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)3 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)3 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)2 Utils (blusunrize.immersiveengineering.common.util.Utils)2 Function (java.util.function.Function)2 Block (net.minecraft.block.Block)2 Minecraft (net.minecraft.client.Minecraft)2 ADatabase (org.asassecreations.engine.serializer.ADatabase)2 AObject (org.asassecreations.engine.serializer.AObject)2 Block (org.asassecreations.voxelgame.world.block.Block)2 BlockModeled (org.asassecreations.voxelgame.world.block.BlockModeled)2 IEProperties (blusunrize.immersiveengineering.api.IEProperties)1 Lib (blusunrize.immersiveengineering.api.Lib)1 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1