Search in sources :

Example 1 with ConveyorDirection

use of blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection 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 2 with ConveyorDirection

use of blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection in project ImmersiveEngineering by BluSunrize.

the class ConveyorCovered method modifyQuads.

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

Aggregations

ConveyorDirection (blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection)2 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)2 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 ClientUtils (blusunrize.immersiveengineering.client.ClientUtils)1 IEContent (blusunrize.immersiveengineering.common.IEContent)1 BlockTypes_MetalDecoration1 (blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration1)1 BlockTypes_WoodenDecoration (blusunrize.immersiveengineering.common.blocks.wooden.BlockTypes_WoodenDecoration)1 Utils (blusunrize.immersiveengineering.common.util.Utils)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Function (java.util.function.Function)1 Nullable (javax.annotation.Nullable)1 Matrix4f (javax.vecmath.Matrix4f)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1