use of mcjty.xnet.blocks.cables.ConnectorBlock 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;
}
use of mcjty.xnet.blocks.cables.ConnectorBlock in project XNet by McJty.
the class GuiProxy method getClientGuiElement.
@Override
public Object getClientGuiElement(int guiid, EntityPlayer entityPlayer, World world, int x, int y, int z) {
if (guiid == GUI_MANUAL_XNET) {
return new GuiXNetManual(GuiXNetManual.MANUAL_XNET);
}
BlockPos pos = new BlockPos(x, y, z);
Block block = world.getBlockState(pos).getBlock();
if (block instanceof GenericBlock) {
GenericBlock<?, ?> genericBlock = (GenericBlock<?, ?>) block;
TileEntity te = world.getTileEntity(pos);
return genericBlock.createClientGui(entityPlayer, te);
} else if (block instanceof ConnectorBlock) {
TileEntity te = world.getTileEntity(pos);
return new GuiConnector((ConnectorTileEntity) te, new EmptyContainer(entityPlayer, null));
}
return null;
}
Aggregations