Search in sources :

Example 1 with CABLE

use of mcjty.xnet.blocks.cables.ConnectorType.CABLE in project XNet by McJty.

the class GenericCableBakedModel method getQuads.

@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
    IExtendedBlockState extendedBlockState = (IExtendedBlockState) state;
    FacadeBlockId facadeId = extendedBlockState.getValue(GenericCableBlock.FACADEID);
    if (facadeId != null) {
        IBlockState facadeState = facadeId.getBlockState();
        if (!facadeState.getBlock().canRenderInLayer(facadeState, MinecraftForgeClient.getRenderLayer())) {
            return Collections.emptyList();
        }
        IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(facadeState);
        try {
            return model.getQuads(state, side, rand);
        } catch (Exception e) {
            return Collections.emptyList();
        }
    }
    if (side != null || (state.getBlock() instanceof ConnectorBlock && MinecraftForgeClient.getRenderLayer() != BlockRenderLayer.CUTOUT_MIPPED)) {
        return Collections.emptyList();
    }
    // Called with the blockstate from our block. Here we get the values of the six properties and pass that to
    // our baked model implementation.
    ConnectorType north = extendedBlockState.getValue(GenericCableBlock.NORTH);
    ConnectorType south = extendedBlockState.getValue(GenericCableBlock.SOUTH);
    ConnectorType west = extendedBlockState.getValue(GenericCableBlock.WEST);
    ConnectorType east = extendedBlockState.getValue(GenericCableBlock.EAST);
    ConnectorType up = extendedBlockState.getValue(GenericCableBlock.UP);
    ConnectorType down = extendedBlockState.getValue(GenericCableBlock.DOWN);
    CableColor cableColor = extendedBlockState.getValue(GenericCableBlock.COLOR);
    int index = cableColor.ordinal();
    initTextures();
    CableTextures ct = cableTextures[index];
    spriteCable = ct.spriteNormalCable;
    GenericCableBlock block = (GenericCableBlock) state.getBlock();
    if (block.isAdvancedConnector()) {
        spriteConnector = ct.spriteAdvancedConnector;
    } else {
        spriteConnector = ct.spriteConnector;
    }
    Function<CablePatterns.SpriteIdx, TextureAtlasSprite> getSprite = idx -> getSpriteNormal(idx, index);
    float hilight = 1.0f;
    if (block instanceof ConnectorBlock) {
        if (north != BLOCK && south != BLOCK && west != BLOCK && east != BLOCK && up != BLOCK && down != BLOCK) {
            // To make connectors with no actual connections visible
            hilight = 0.5f;
        }
    }
    List<BakedQuad> quads = new ArrayList<>();
    // Thickness of the cable. .0 would be full block, .5 is infinitely thin.
    double o = .4;
    // Thickness of the connector as it is put on the connecting block
    double p = .1;
    // The wideness of the connector
    double q = .2;
    if (up == CABLE) {
        quads.add(createQuad(v(1 - o, 1, o), v(1 - o, 1, 1 - o), v(1 - o, 1 - o, 1 - o), v(1 - o, 1 - o, o), spriteCable, hilight));
        quads.add(createQuad(v(o, 1, 1 - o), v(o, 1, o), v(o, 1 - o, o), v(o, 1 - o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(o, 1, o), v(1 - o, 1, o), v(1 - o, 1 - o, o), v(o, 1 - o, o), spriteCable, hilight));
        quads.add(createQuad(v(o, 1 - o, 1 - o), v(1 - o, 1 - o, 1 - o), v(1 - o, 1, 1 - o), v(o, 1, 1 - o), spriteCable, hilight));
    } else if (up == BLOCK) {
        quads.add(createQuad(v(1 - o, 1 - p, o), v(1 - o, 1 - p, 1 - o), v(1 - o, 1 - o, 1 - o), v(1 - o, 1 - o, o), spriteCable, hilight));
        quads.add(createQuad(v(o, 1 - p, 1 - o), v(o, 1 - p, o), v(o, 1 - o, o), v(o, 1 - o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(o, 1 - p, o), v(1 - o, 1 - p, o), v(1 - o, 1 - o, o), v(o, 1 - o, o), spriteCable, hilight));
        quads.add(createQuad(v(o, 1 - o, 1 - o), v(1 - o, 1 - o, 1 - o), v(1 - o, 1 - p, 1 - o), v(o, 1 - p, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(1 - q, 1 - p, q), v(1 - q, 1, q), v(1 - q, 1, 1 - q), v(1 - q, 1 - p, 1 - q), spriteSide, hilight));
        quads.add(createQuad(v(q, 1 - p, 1 - q), v(q, 1, 1 - q), v(q, 1, q), v(q, 1 - p, q), spriteSide, hilight));
        quads.add(createQuad(v(q, 1, q), v(1 - q, 1, q), v(1 - q, 1 - p, q), v(q, 1 - p, q), spriteSide, hilight));
        quads.add(createQuad(v(q, 1 - p, 1 - q), v(1 - q, 1 - p, 1 - q), v(1 - q, 1, 1 - q), v(q, 1, 1 - q), spriteSide, hilight));
        quads.add(createQuad(v(q, 1 - p, q), v(1 - q, 1 - p, q), v(1 - q, 1 - p, 1 - q), v(q, 1 - p, 1 - q), spriteConnector, hilight));
        quads.add(createQuad(v(q, 1, q), v(q, 1, 1 - q), v(1 - q, 1, 1 - q), v(1 - q, 1, q), spriteSide, hilight));
    } else {
        CablePatterns.QuadSetting pattern = CablePatterns.findPattern(west, south, east, north);
        quads.add(createQuad(v(o, 1 - o, 1 - o), v(1 - o, 1 - o, 1 - o), v(1 - o, 1 - o, o), v(o, 1 - o, o), getSprite.apply(pattern.getSprite()), pattern.getRotation(), hilight));
    }
    if (down == CABLE) {
        quads.add(createQuad(v(1 - o, o, o), v(1 - o, o, 1 - o), v(1 - o, 0, 1 - o), v(1 - o, 0, o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, 1 - o), v(o, o, o), v(o, 0, o), v(o, 0, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, o), v(1 - o, o, o), v(1 - o, 0, o), v(o, 0, o), spriteCable, hilight));
        quads.add(createQuad(v(o, 0, 1 - o), v(1 - o, 0, 1 - o), v(1 - o, o, 1 - o), v(o, o, 1 - o), spriteCable, hilight));
    } else if (down == BLOCK) {
        quads.add(createQuad(v(1 - o, o, o), v(1 - o, o, 1 - o), v(1 - o, p, 1 - o), v(1 - o, p, o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, 1 - o), v(o, o, o), v(o, p, o), v(o, p, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, o), v(1 - o, o, o), v(1 - o, p, o), v(o, p, o), spriteCable, hilight));
        quads.add(createQuad(v(o, p, 1 - o), v(1 - o, p, 1 - o), v(1 - o, o, 1 - o), v(o, o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(1 - q, 0, q), v(1 - q, p, q), v(1 - q, p, 1 - q), v(1 - q, 0, 1 - q), spriteSide, hilight));
        quads.add(createQuad(v(q, 0, 1 - q), v(q, p, 1 - q), v(q, p, q), v(q, 0, q), spriteSide, hilight));
        quads.add(createQuad(v(q, p, q), v(1 - q, p, q), v(1 - q, 0, q), v(q, 0, q), spriteSide, hilight));
        quads.add(createQuad(v(q, 0, 1 - q), v(1 - q, 0, 1 - q), v(1 - q, p, 1 - q), v(q, p, 1 - q), spriteSide, hilight));
        quads.add(createQuad(v(q, p, 1 - q), v(1 - q, p, 1 - q), v(1 - q, p, q), v(q, p, q), spriteConnector, hilight));
        quads.add(createQuad(v(q, 0, 1 - q), v(q, 0, q), v(1 - q, 0, q), v(1 - q, 0, 1 - q), spriteSide, hilight));
    } else {
        CablePatterns.QuadSetting pattern = CablePatterns.findPattern(west, north, east, south);
        quads.add(createQuad(v(o, o, o), v(1 - o, o, o), v(1 - o, o, 1 - o), v(o, o, 1 - o), getSprite.apply(pattern.getSprite()), pattern.getRotation(), hilight));
    }
    if (east == CABLE) {
        quads.add(createQuad(v(1, 1 - o, 1 - o), v(1, 1 - o, o), v(1 - o, 1 - o, o), v(1 - o, 1 - o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(1, o, o), v(1, o, 1 - o), v(1 - o, o, 1 - o), v(1 - o, o, o), spriteCable, hilight));
        quads.add(createQuad(v(1, 1 - o, o), v(1, o, o), v(1 - o, o, o), v(1 - o, 1 - o, o), spriteCable, hilight));
        quads.add(createQuad(v(1, o, 1 - o), v(1, 1 - o, 1 - o), v(1 - o, 1 - o, 1 - o), v(1 - o, o, 1 - o), spriteCable, hilight));
    } else if (east == BLOCK) {
        quads.add(createQuad(v(1 - p, 1 - o, 1 - o), v(1 - p, 1 - o, o), v(1 - o, 1 - o, o), v(1 - o, 1 - o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(1 - p, o, o), v(1 - p, o, 1 - o), v(1 - o, o, 1 - o), v(1 - o, o, o), spriteCable, hilight));
        quads.add(createQuad(v(1 - p, 1 - o, o), v(1 - p, o, o), v(1 - o, o, o), v(1 - o, 1 - o, o), spriteCable, hilight));
        quads.add(createQuad(v(1 - p, o, 1 - o), v(1 - p, 1 - o, 1 - o), v(1 - o, 1 - o, 1 - o), v(1 - o, o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(1 - p, 1 - q, 1 - q), v(1, 1 - q, 1 - q), v(1, 1 - q, q), v(1 - p, 1 - q, q), spriteSide, hilight));
        quads.add(createQuad(v(1 - p, q, q), v(1, q, q), v(1, q, 1 - q), v(1 - p, q, 1 - q), spriteSide, hilight));
        quads.add(createQuad(v(1 - p, 1 - q, q), v(1, 1 - q, q), v(1, q, q), v(1 - p, q, q), spriteSide, hilight));
        quads.add(createQuad(v(1 - p, q, 1 - q), v(1, q, 1 - q), v(1, 1 - q, 1 - q), v(1 - p, 1 - q, 1 - q), spriteSide, hilight));
        quads.add(createQuad(v(1 - p, q, 1 - q), v(1 - p, 1 - q, 1 - q), v(1 - p, 1 - q, q), v(1 - p, q, q), spriteConnector, hilight));
        quads.add(createQuad(v(1, q, 1 - q), v(1, q, q), v(1, 1 - q, q), v(1, 1 - q, 1 - q), spriteSide, hilight));
    } else {
        CablePatterns.QuadSetting pattern = CablePatterns.findPattern(down, north, up, south);
        quads.add(createQuad(v(1 - o, o, o), v(1 - o, 1 - o, o), v(1 - o, 1 - o, 1 - o), v(1 - o, o, 1 - o), getSprite.apply(pattern.getSprite()), pattern.getRotation(), hilight));
    }
    if (west == CABLE) {
        quads.add(createQuad(v(o, 1 - o, 1 - o), v(o, 1 - o, o), v(0, 1 - o, o), v(0, 1 - o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, o), v(o, o, 1 - o), v(0, o, 1 - o), v(0, o, o), spriteCable, hilight));
        quads.add(createQuad(v(o, 1 - o, o), v(o, o, o), v(0, o, o), v(0, 1 - o, o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, 1 - o), v(o, 1 - o, 1 - o), v(0, 1 - o, 1 - o), v(0, o, 1 - o), spriteCable, hilight));
    } else if (west == BLOCK) {
        quads.add(createQuad(v(o, 1 - o, 1 - o), v(o, 1 - o, o), v(p, 1 - o, o), v(p, 1 - o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, o), v(o, o, 1 - o), v(p, o, 1 - o), v(p, o, o), spriteCable, hilight));
        quads.add(createQuad(v(o, 1 - o, o), v(o, o, o), v(p, o, o), v(p, 1 - o, o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, 1 - o), v(o, 1 - o, 1 - o), v(p, 1 - o, 1 - o), v(p, o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(0, 1 - q, 1 - q), v(p, 1 - q, 1 - q), v(p, 1 - q, q), v(0, 1 - q, q), spriteSide, hilight));
        quads.add(createQuad(v(0, q, q), v(p, q, q), v(p, q, 1 - q), v(0, q, 1 - q), spriteSide, hilight));
        quads.add(createQuad(v(0, 1 - q, q), v(p, 1 - q, q), v(p, q, q), v(0, q, q), spriteSide, hilight));
        quads.add(createQuad(v(0, q, 1 - q), v(p, q, 1 - q), v(p, 1 - q, 1 - q), v(0, 1 - q, 1 - q), spriteSide, hilight));
        quads.add(createQuad(v(p, q, q), v(p, 1 - q, q), v(p, 1 - q, 1 - q), v(p, q, 1 - q), spriteConnector, hilight));
        quads.add(createQuad(v(0, q, q), v(0, q, 1 - q), v(0, 1 - q, 1 - q), v(0, 1 - q, q), spriteSide, hilight));
    } else {
        CablePatterns.QuadSetting pattern = CablePatterns.findPattern(down, south, up, north);
        quads.add(createQuad(v(o, o, 1 - o), v(o, 1 - o, 1 - o), v(o, 1 - o, o), v(o, o, o), getSprite.apply(pattern.getSprite()), pattern.getRotation(), hilight));
    }
    if (north == CABLE) {
        quads.add(createQuad(v(o, 1 - o, o), v(1 - o, 1 - o, o), v(1 - o, 1 - o, 0), v(o, 1 - o, 0), spriteCable, hilight));
        quads.add(createQuad(v(o, o, 0), v(1 - o, o, 0), v(1 - o, o, o), v(o, o, o), spriteCable, hilight));
        quads.add(createQuad(v(1 - o, o, 0), v(1 - o, 1 - o, 0), v(1 - o, 1 - o, o), v(1 - o, o, o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, o), v(o, 1 - o, o), v(o, 1 - o, 0), v(o, o, 0), spriteCable, hilight));
    } else if (north == BLOCK) {
        quads.add(createQuad(v(o, 1 - o, o), v(1 - o, 1 - o, o), v(1 - o, 1 - o, p), v(o, 1 - o, p), spriteCable, hilight));
        quads.add(createQuad(v(o, o, p), v(1 - o, o, p), v(1 - o, o, o), v(o, o, o), spriteCable, hilight));
        quads.add(createQuad(v(1 - o, o, p), v(1 - o, 1 - o, p), v(1 - o, 1 - o, o), v(1 - o, o, o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, o), v(o, 1 - o, o), v(o, 1 - o, p), v(o, o, p), spriteCable, hilight));
        quads.add(createQuad(v(q, 1 - q, p), v(1 - q, 1 - q, p), v(1 - q, 1 - q, 0), v(q, 1 - q, 0), spriteSide, hilight));
        quads.add(createQuad(v(q, q, 0), v(1 - q, q, 0), v(1 - q, q, p), v(q, q, p), spriteSide, hilight));
        quads.add(createQuad(v(1 - q, q, 0), v(1 - q, 1 - q, 0), v(1 - q, 1 - q, p), v(1 - q, q, p), spriteSide, hilight));
        quads.add(createQuad(v(q, q, p), v(q, 1 - q, p), v(q, 1 - q, 0), v(q, q, 0), spriteSide, hilight));
        quads.add(createQuad(v(q, q, p), v(1 - q, q, p), v(1 - q, 1 - q, p), v(q, 1 - q, p), spriteConnector, hilight));
        quads.add(createQuad(v(q, q, 0), v(q, 1 - q, 0), v(1 - q, 1 - q, 0), v(1 - q, q, 0), spriteSide, hilight));
    } else {
        CablePatterns.QuadSetting pattern = CablePatterns.findPattern(west, up, east, down);
        quads.add(createQuad(v(o, 1 - o, o), v(1 - o, 1 - o, o), v(1 - o, o, o), v(o, o, o), getSprite.apply(pattern.getSprite()), pattern.getRotation(), hilight));
    }
    if (south == CABLE) {
        quads.add(createQuad(v(o, 1 - o, 1), v(1 - o, 1 - o, 1), v(1 - o, 1 - o, 1 - o), v(o, 1 - o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, 1 - o), v(1 - o, o, 1 - o), v(1 - o, o, 1), v(o, o, 1), spriteCable, hilight));
        quads.add(createQuad(v(1 - o, o, 1 - o), v(1 - o, 1 - o, 1 - o), v(1 - o, 1 - o, 1), v(1 - o, o, 1), spriteCable, hilight));
        quads.add(createQuad(v(o, o, 1), v(o, 1 - o, 1), v(o, 1 - o, 1 - o), v(o, o, 1 - o), spriteCable, hilight));
    } else if (south == BLOCK) {
        quads.add(createQuad(v(o, 1 - o, 1 - p), v(1 - o, 1 - o, 1 - p), v(1 - o, 1 - o, 1 - o), v(o, 1 - o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(o, o, 1 - o), v(1 - o, o, 1 - o), v(1 - o, o, 1 - p), v(o, o, 1 - p), spriteCable, hilight));
        quads.add(createQuad(v(1 - o, o, 1 - o), v(1 - o, 1 - o, 1 - o), v(1 - o, 1 - o, 1 - p), v(1 - o, o, 1 - p), spriteCable, hilight));
        quads.add(createQuad(v(o, o, 1 - p), v(o, 1 - o, 1 - p), v(o, 1 - o, 1 - o), v(o, o, 1 - o), spriteCable, hilight));
        quads.add(createQuad(v(q, 1 - q, 1), v(1 - q, 1 - q, 1), v(1 - q, 1 - q, 1 - p), v(q, 1 - q, 1 - p), spriteSide, hilight));
        quads.add(createQuad(v(q, q, 1 - p), v(1 - q, q, 1 - p), v(1 - q, q, 1), v(q, q, 1), spriteSide, hilight));
        quads.add(createQuad(v(1 - q, q, 1 - p), v(1 - q, 1 - q, 1 - p), v(1 - q, 1 - q, 1), v(1 - q, q, 1), spriteSide, hilight));
        quads.add(createQuad(v(q, q, 1), v(q, 1 - q, 1), v(q, 1 - q, 1 - p), v(q, q, 1 - p), spriteSide, hilight));
        quads.add(createQuad(v(q, 1 - q, 1 - p), v(1 - q, 1 - q, 1 - p), v(1 - q, q, 1 - p), v(q, q, 1 - p), spriteConnector, hilight));
        quads.add(createQuad(v(q, 1 - q, 1), v(q, q, 1), v(1 - q, q, 1), v(1 - q, 1 - q, 1), spriteSide, hilight));
    } else {
        CablePatterns.QuadSetting pattern = CablePatterns.findPattern(west, down, east, up);
        quads.add(createQuad(v(o, o, 1 - o), v(1 - o, o, 1 - o), v(1 - o, 1 - o, 1 - o), v(o, 1 - o, 1 - o), getSprite.apply(pattern.getSprite()), pattern.getRotation(), hilight));
    }
    return quads;
}
Also used : SpriteIdx(mcjty.xnet.blocks.generic.CablePatterns.SpriteIdx) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BLOCK(mcjty.xnet.blocks.cables.ConnectorType.BLOCK) MinecraftForgeClient(net.minecraftforge.client.MinecraftForgeClient) ArrayList(java.util.ArrayList) SpriteIdx(mcjty.xnet.blocks.generic.CablePatterns.SpriteIdx) NetCableBlock(mcjty.xnet.blocks.cables.NetCableBlock) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Minecraft(net.minecraft.client.Minecraft) ConnectorType(mcjty.xnet.blocks.cables.ConnectorType) FacadeBlockId(mcjty.xnet.blocks.facade.FacadeBlockId) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) net.minecraft.client.renderer.block.model(net.minecraft.client.renderer.block.model) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Function(com.google.common.base.Function) CABLE(mcjty.xnet.blocks.cables.ConnectorType.CABLE) EnumFacing(net.minecraft.util.EnumFacing) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) XNet(mcjty.xnet.XNet) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock) Collections(java.util.Collections) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) IBlockState(net.minecraft.block.state.IBlockState) ConnectorType(mcjty.xnet.blocks.cables.ConnectorType) FacadeBlockId(mcjty.xnet.blocks.facade.FacadeBlockId) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ArrayList(java.util.ArrayList) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock)

Aggregations

Function (com.google.common.base.Function)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 XNet (mcjty.xnet.XNet)1 ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)1 ConnectorType (mcjty.xnet.blocks.cables.ConnectorType)1 BLOCK (mcjty.xnet.blocks.cables.ConnectorType.BLOCK)1 CABLE (mcjty.xnet.blocks.cables.ConnectorType.CABLE)1 NetCableBlock (mcjty.xnet.blocks.cables.NetCableBlock)1 FacadeBlockId (mcjty.xnet.blocks.facade.FacadeBlockId)1 SpriteIdx (mcjty.xnet.blocks.generic.CablePatterns.SpriteIdx)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 Minecraft (net.minecraft.client.Minecraft)1 net.minecraft.client.renderer.block.model (net.minecraft.client.renderer.block.model)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 VertexFormat (net.minecraft.client.renderer.vertex.VertexFormat)1 BlockRenderLayer (net.minecraft.util.BlockRenderLayer)1 EnumFacing (net.minecraft.util.EnumFacing)1