Search in sources :

Example 21 with Matrix4

use of blusunrize.immersiveengineering.common.util.chickenbones.Matrix4 in project ImmersiveEngineering by BluSunrize.

the class TileEntityConnectorStructural method applyTransformations.

@Override
public Optional<TRSRTransformation> applyTransformations(IBlockState object, String group, Optional<TRSRTransformation> transform) {
    Matrix4 mat = transform.isPresent() ? new Matrix4(transform.get().getMatrix()) : new Matrix4();
    mat = mat.translate(.5, 0, .5).rotate(Math.toRadians(rotation), 0, 1, 0).translate(-.5, 0, -.5);
    transform = Optional.of(new TRSRTransformation(mat.toMatrix4f()));
    return transform;
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Example 22 with Matrix4

use of blusunrize.immersiveengineering.common.util.chickenbones.Matrix4 in project ImmersiveEngineering by BluSunrize.

the class ConveyorExtract method modifyQuads.

// private static final TextureAtlasSprite texture_steel = ClientUtils.getSprite(new ResourceLocation("immersiveengineering:blocks/storage_steel"));
// private static final TextureAtlasSprite texture_casing = ClientUtils.getSprite(new ResourceLocation("immersiveengineering:blocks/wooden_device_turntable_bottom"));
// private static final TextureAtlasSprite texture_curtain = ClientUtils.getSprite(new ResourceLocation("immersiveengineering:blocks/cloth_device_stripcurtain"));
// private static final TextureAtlasSprite texture_assembler = ClientUtils.getSprite(new ResourceLocation("immersiveengineering:blocks/metal_multiblock_assembler"));
@Override
@SideOnly(Side.CLIENT)
public List<BakedQuad> modifyQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing) {
    final TextureAtlasSprite texture_steel = ClientUtils.getSprite(new ResourceLocation("immersiveengineering:blocks/storage_steel"));
    final TextureAtlasSprite texture_casing = ClientUtils.getSprite(new ResourceLocation("immersiveengineering:blocks/wooden_device_turntable_bottom"));
    final TextureAtlasSprite texture_curtain = ClientUtils.getSprite(new ResourceLocation("immersiveengineering:blocks/cloth_device_stripcurtain"));
    final TextureAtlasSprite texture_assembler = ClientUtils.getSprite(new ResourceLocation("immersiveengineering:blocks/metal_multiblock_assembler"));
    float[] colour = { 1, 1, 1, 1 };
    Matrix4 matrix = new Matrix4(this.extractDirection);
    final float extend = getExtensionIntoBlock(tile);
    this.extension = extend;
    Function<EnumFacing, TextureAtlasSprite> getCasingSprite = enumFacing -> enumFacing.getAxis() == Axis.Z ? texture_steel : texture_casing;
    Function<Vector3f[], Vector3f[]> vertexTransformer = vertices -> {
        if (extend == 0)
            return 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 - extend);
        return ret;
    };
    Function<Vector3f[], Vector3f[]> casingTransformer = 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 - .25f, vertices[i].z - .625f - extend);
        return ret;
    };
    baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.0625f, .375f, .625f), new Vector3f(.1875f, 1f, 1f), matrix, facing, casingTransformer, getCasingSprite, colour));
    baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.8125f, .375f, .625f), new Vector3f(.9375f, 1f, 1f), matrix, facing, casingTransformer, getCasingSprite, colour));
    baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.1875f, .875f, .625f), new Vector3f(.8125f, 1f, 1f), matrix, facing, casingTransformer, getCasingSprite, colour));
    if (tile != null && extend > 0) {
        TextureAtlasSprite tex_conveyor = ClientUtils.getSprite(isActive(tile) ? ConveyorBasic.texture_on : ConveyorBasic.texture_off);
        Function<EnumFacing, TextureAtlasSprite> getExtensionSprite = enumFacing -> enumFacing.getAxis() == Axis.Y ? null : enumFacing.getAxis() == Axis.Z ? texture_steel : texture_casing;
        Vector3f[] vertices = { new Vector3f(.0625f, 0, -extend), new Vector3f(.0625f, 0, 0), new Vector3f(.9375f, 0, 0), new Vector3f(.9375f, 0, -extend) };
        baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.DOWN, facing), tex_conveyor, new double[] { 15, extend * 16, 1, 0 }, colour, true));
        for (Vector3f vec : vertices) vec.setY(.125f);
        baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), tex_conveyor, new double[] { 15, (1 - extend) * 16, 1, 16 }, colour, false));
        baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.0625f, .25f, .625f), new Vector3f(.9375f, .375f, .625f + extend), matrix, facing, casingTransformer, getExtensionSprite, colour));
    }
    Vector3f[] vertices = new Vector3f[] { new Vector3f(.8125f, .625f, .03125f), new Vector3f(.8125f, .125f, .03125f), new Vector3f(.1875f, .125f, .03125f), new Vector3f(.1875f, .625f, .03125f) };
    baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.NORTH, facing), texture_assembler, new double[] { 15.25, 13.25, 12.75, 15.25 }, colour, false));
    for (Vector3f vec : vertices) vec.setZ(.0625f);
    baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.SOUTH, facing), texture_assembler, new double[] { 12.75, 13.25, 15.25, 15.25 }, colour, true));
    for (int i = 0; i < 5; i++) {
        float off = i * .125f;
        baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.203125f + off, .1875f, .09375f), new Vector3f(.296875f + off, .625f, .125f), matrix, facing, vertexTransformer, (facing1) -> texture_curtain, colour));
    }
    return baseModel;
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumHand(net.minecraft.util.EnumHand) Function(java.util.function.Function) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ClientUtils(blusunrize.immersiveengineering.client.ClientUtils) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) Side(net.minecraftforge.fml.relauncher.Side) Lib(blusunrize.immersiveengineering.api.Lib) IConveyorTile(blusunrize.immersiveengineering.api.tool.ConveyorHandler.IConveyorTile) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nullable(javax.annotation.Nullable) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EntityItem(net.minecraft.entity.item.EntityItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockFaceShape(net.minecraft.block.state.BlockFaceShape) Utils(blusunrize.immersiveengineering.common.util.Utils) World(net.minecraft.world.World) ConveyorDirection(blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) 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) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) Axis(net.minecraft.util.EnumFacing.Axis) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) EnumFacing(net.minecraft.util.EnumFacing) Vector3f(org.lwjgl.util.vector.Vector3f) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 23 with Matrix4

use of blusunrize.immersiveengineering.common.util.chickenbones.Matrix4 in project ImmersiveEngineering by BluSunrize.

the class ConveyorVerticalCovered method modifyQuads.

@Override
@SideOnly(Side.CLIENT)
public List<BakedQuad> modifyQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing) {
    boolean renderBottom = tile != null && this.renderBottomBelt(tile, facing);
    boolean[] walls;
    if (renderBottom) {
        TextureAtlasSprite sprite = ClientUtils.getSprite(isActive(tile) ? ConveyorBasic.texture_on : ConveyorBasic.texture_off);
        TextureAtlasSprite spriteColour = ClientUtils.getSprite(getColouredStripesTexture());
        walls = new boolean[] { renderBottomWall(tile, facing, 0), renderBottomWall(tile, facing, 1) };
        baseModel.addAll(ModelConveyor.getBaseConveyor(facing, .875f, new Matrix4(facing), ConveyorDirection.HORIZONTAL, sprite, walls, new boolean[] { true, false }, spriteColour, getDyeColour()));
    } else
        walls = new boolean[] { true, true };
    ItemStack cover = !this.cover.isEmpty() ? this.cover : ConveyorCovered.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;
        float[] colour = { 1, 1, 1, 1 };
        Matrix4 matrix = new Matrix4(facing);
        if (// just vertical
        !renderBottom) {
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, 0, .75f), new Vector3f(1, 1, 1), matrix, facing, getSprite, colour));
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, 0, .1875f), new Vector3f(.0625f, 1, .75f), matrix, facing, getSprite, colour));
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, 0, .1875f), new Vector3f(1, 1, .75f), matrix, facing, getSprite, colour));
        } else {
            boolean straightInput = tile != null && isInwardConveyor(tile, facing.getOpposite());
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .9375f, .75f), new Vector3f(1, 1, 1), matrix, facing, getSprite, colour));
            if (!straightInput)
                baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, .9375f), new Vector3f(1, 1f, 1), matrix, facing, getSprite, colour));
            else // has direct input, needs a cutout
            {
                baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .75f, .9375f), new Vector3f(1, 1, 1), matrix, facing, getSprite, colour));
                baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, .9375f), new Vector3f(.0625f, .75f, 1), matrix, facing, getSprite, colour));
                baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, .9375f), new Vector3f(1, .75f, 1), matrix, facing, getSprite, colour));
            }
            if (// wall to the left
            walls[0])
                baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, .1875f), new Vector3f(.0625f, 1, .9375f), matrix, facing, getSprite, colour));
            else
                // cutout to the left
                baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .75f, .1875f), new Vector3f(.0625f, 1, .9375f), matrix, facing, getSprite, colour));
            if (// wall to the right
            walls[1])
                baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, .1875f), new Vector3f(1, 1, .9375f), matrix, facing, getSprite, colour));
            else
                // cutout to the right
                baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .75f, .1875f), new Vector3f(1, 1, .9375f), matrix, facing, getSprite, colour));
        }
    }
    return baseModel;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) 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) ClientUtils(blusunrize.immersiveengineering.client.ClientUtils) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) 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) ConveyorDirection(blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection) EnumFacing(net.minecraft.util.EnumFacing) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) 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) ModelConveyor(blusunrize.immersiveengineering.client.models.ModelConveyor) TileEntity(net.minecraft.tileentity.TileEntity) Collections(java.util.Collections) 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) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 24 with Matrix4

use of blusunrize.immersiveengineering.common.util.chickenbones.Matrix4 in project ImmersiveEngineering by BluSunrize.

the class TileEntityRedstoneBreaker method getBlockBounds.

@Override
public float[] getBlockBounds() {
    Vec3d start = new Vec3d(0, .125f, 0);
    Vec3d end = new Vec3d(1, .875f, 1);
    Matrix4 mat = new Matrix4(facing);
    mat.translate(.5, .5, 0).rotate(Math.PI / 2 * rotation, 0, 0, 1).translate(-.5, -.5, 0);
    start = mat.apply(start);
    end = mat.apply(end);
    return new float[] { (float) start.x, (float) start.y, (float) start.z, (float) end.x, (float) end.y, (float) end.z };
}
Also used : Vec3d(net.minecraft.util.math.Vec3d) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Example 25 with Matrix4

use of blusunrize.immersiveengineering.common.util.chickenbones.Matrix4 in project ImmersiveEngineering by BluSunrize.

the class TileEntityRedstoneBreaker method getConnectionOffset.

@Override
public Vec3d getConnectionOffset(Connection con) {
    Matrix4 mat = new Matrix4(facing);
    mat.translate(.5, .5, 0).rotate(Math.PI / 2 * rotation, 0, 0, 1).translate(-.5, -.5, 0);
    if (endOfLeftConnection == null)
        calculateLeftConn(mat);
    boolean isLeft = con.end.equals(endOfLeftConnection) || con.start.equals(endOfLeftConnection);
    Vec3d ret = mat.apply(isLeft ? new Vec3d(.125, .5, 1) : new Vec3d(.875, .5, 1));
    return ret;
}
Also used : Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)27 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)10 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)9 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)8 TileEntity (net.minecraft.tileentity.TileEntity)8 Vec3d (net.minecraft.util.math.Vec3d)8 Vector3f (org.lwjgl.util.vector.Vector3f)8 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)7 ItemStack (net.minecraft.item.ItemStack)7 Function (java.util.function.Function)6 IBlockState (net.minecraft.block.state.IBlockState)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 EnumFacing (net.minecraft.util.EnumFacing)6 ConveyorDirection (blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection)5 ClientUtils (blusunrize.immersiveengineering.client.ClientUtils)5 Utils (blusunrize.immersiveengineering.common.util.Utils)5 List (java.util.List)5 Nullable (javax.annotation.Nullable)5 Minecraft (net.minecraft.client.Minecraft)5