use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.
the class RendererWire method addWire.
public void addWire(Wire wire, WireSheet sheet, List<BakedQuad> quads) {
WireFace side = wire.getLocation();
int renderColor = wire.getRenderColor();
if (side == WireFace.CENTER) {
addWireFreestanding(wire, sheet, renderColor, quads);
return;
}
float min = 8.0f - (sheet.width / 2);
float max = 8.0f + (sheet.width / 2);
float minH = 0.0f;
float maxH = sheet.height;
EnumFacing[] dirs = WireUtils.getConnectionsForRender(side);
boolean[] connectionMatrix = new boolean[] { wire == null || wire.connectsAny(dirs[0]), wire == null || wire.connectsAny(dirs[1]), wire == null || wire.connectsAny(dirs[2]), wire == null || wire.connectsAny(dirs[3]) };
int cmc = (connectionMatrix[0] ? 8 : 0) | (connectionMatrix[1] ? 4 : 0) | (connectionMatrix[2] ? 2 : 0) | (connectionMatrix[3] ? 1 : 0);
boolean[] cornerConnectionMatrix = new boolean[] { wire == null || wire.connectsCorner(dirs[0]), wire == null || wire.connectsCorner(dirs[1]), wire == null || wire.connectsCorner(dirs[2]), wire == null || wire.connectsCorner(dirs[3]) };
ModelRotation rot = ROTATIONS[side.ordinal()];
// Center face
Vector3f from = new Vector3f(min, sheet.height, min);
Vector3f to = new Vector3f(max, sheet.height, max);
if (connectionMatrix[0]) {
from.setZ(0.0f);
}
if (connectionMatrix[1]) {
to.setZ(16.0f);
}
if (connectionMatrix[2]) {
from.setX(0.0f);
}
if (connectionMatrix[3]) {
to.setX(16.0f);
}
quads.add(RenderUtils.BAKERY.makeBakedQuad(from, to, renderColor, new float[] { from.getX(), from.getZ(), to.getX(), to.getZ() }, sheet.top[cmc], EnumFacing.UP, rot, true));
if (!wire.getFactory().isFlat()) {
from.setY(0.0F);
to.setY(0.0F);
quads.add(RenderUtils.BAKERY.makeBakedQuad(from, to, renderColor, new float[] { from.getX(), from.getZ(), to.getX(), to.getZ() }, sheet.top[cmc], EnumFacing.DOWN, rot, true));
// Side faces
Vector3f fromZ = new Vector3f(from.getX(), 0.0f, min);
Vector3f toZ = new Vector3f(to.getX(), sheet.height, min);
Vector3f fromX = new Vector3f(min, 0.0f, from.getZ());
Vector3f toX = new Vector3f(min, sheet.height, to.getZ());
// Should we render a faux side wire on this side? (For bundled)
boolean crossroadsX = connectionMatrix[2] && !connectionMatrix[3];
boolean crossroadsZ = connectionMatrix[0] && !connectionMatrix[1];
// getIcon(false, cmc == 1, crossroadsX, EnumFacing.WEST)
if (sheet.side != null) {
quads.add(RenderUtils.BAKERY.makeBakedQuad(fromX, toX, renderColor, new float[] { fromX.getZ(), fromX.getY(), toX.getZ(), toX.getY() }, sheet.side, EnumFacing.WEST, rot, false));
// getIcon(false, cmc == 0 || cmc == 4, crossroadsZ, EnumFacing.NORTH)
quads.add(RenderUtils.BAKERY.makeBakedQuad(fromZ, toZ, renderColor, new float[] { toZ.getX(), fromZ.getY(), fromZ.getX(), toZ.getY() }, sheet.side, EnumFacing.NORTH, rot, false));
}
fromX.setX(max);
toX.setX(max);
fromZ.setZ(max);
toZ.setZ(max);
if (sheet.side != null) {
// getIcon(false, cmc == 2, crossroadsX, EnumFacing.EAST)
quads.add(RenderUtils.BAKERY.makeBakedQuad(fromX, toX, renderColor, new float[] { toX.getZ(), fromX.getY(), fromX.getZ(), toX.getY() }, sheet.side, EnumFacing.EAST, rot, false));
// getIcon(false, cmc == 0 || cmc == 8, crossroadsZ, EnumFacing.SOUTH)
quads.add(RenderUtils.BAKERY.makeBakedQuad(fromZ, toZ, renderColor, new float[] { fromZ.getX(), fromZ.getY(), toZ.getX(), toZ.getY() }, sheet.side, EnumFacing.SOUTH, rot, false));
}
// Edge faces
float[] edgeUV = new float[] { min, minH, max, maxH };
float[] edgeUVFlipped = new float[] { max, minH, min, maxH };
if (sheet.edge != null) {
if (connectionMatrix[0]) {
quads.add(RenderUtils.BAKERY.makeBakedQuad(new Vector3f(min, minH, 0.0F), new Vector3f(max, maxH, 0.0F), renderColor, edgeUVFlipped, sheet.edge, EnumFacing.NORTH, rot, false));
}
if (connectionMatrix[1]) {
quads.add(RenderUtils.BAKERY.makeBakedQuad(new Vector3f(min, minH, 16.0F), new Vector3f(max, maxH, 16.0F), renderColor, edgeUV, sheet.edge, EnumFacing.SOUTH, rot, false));
}
if (connectionMatrix[2]) {
quads.add(RenderUtils.BAKERY.makeBakedQuad(new Vector3f(0.0F, minH, min), new Vector3f(0.0F, maxH, max), renderColor, edgeUV, sheet.edge, EnumFacing.WEST, rot, false));
}
if (connectionMatrix[3]) {
quads.add(RenderUtils.BAKERY.makeBakedQuad(new Vector3f(16.0F, minH, min), new Vector3f(16.0F, maxH, max), renderColor, edgeUVFlipped, sheet.edge, EnumFacing.EAST, rot, false));
}
}
EnumFacing[] dirs0 = WireUtils.getConnectionsForRender(WireFace.DOWN);
for (int i = 0; i < 4; i++) {
if (cornerConnectionMatrix[i]) {
addCorner(wire, sheet, dirs0[i], renderColor, quads);
}
}
}
}
use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.
the class Wire method updateConnections.
protected void updateConnections() {
if (!connectionCheckDirty) {
return;
}
Set<WireFace> validSides = EnumSet.noneOf(WireFace.class);
Set<WireFace> invalidCornerSides = EnumSet.noneOf(WireFace.class);
for (WireFace facing : WireFace.VALUES) {
if (facing == location) {
continue;
}
if (facing != WireFace.CENTER && location != WireFace.CENTER && location.facing.getAxis() == facing.facing.getAxis()) {
continue;
}
validSides.add(facing);
}
int oldConnectionCache = getConnectionMask();
internalConnections = externalConnections = cornerConnections = occludedSides = cornerOccludedSides = 0;
// Occlusion test
EnumFacing[] connFaces = WireUtils.getConnectionsForRender(location);
for (int i = 0; i < connFaces.length; i++) {
WireFace face = WireFace.get(connFaces[i]);
if (validSides.contains(face)) {
boolean found = false;
AxisAlignedBB mask = factory.getBox(location, i + 1);
if (mask != null) {
if (OcclusionUtils.INSTANCE.intersects(Collections.singletonList(mask), container.world(), container.pos())) {
occludedSides |= 1 << connFaces[i].ordinal();
validSides.remove(face);
found = true;
}
}
/*
if (!found && location != WireFace.CENTER) {
BlockPos cPos = container.pos().offset(connFaces[i]);
AxisAlignedBB cornerMask = factory.getCornerBox(location, i ^ 1);
if (cornerMask != null) {
if (OcclusionUtils.PRIMARY.intersects(Collections.singletonList(cornerMask), container.world(), cPos)) {
cornerOccludedSides |= 1 << connFaces[i].ordinal();
invalidCornerSides.add(face);
}
}
} */
}
}
if (validSides.contains(WireFace.CENTER)) {
AxisAlignedBB mask = factory.getBox(WireFace.CENTER, 1 + location.ordinal());
if (mask != null) {
if (OcclusionUtils.INSTANCE.intersects(Collections.singletonList(mask), container.world(), container.pos())) {
occludedSides |= 1 << 6;
validSides.remove(WireFace.CENTER);
}
}
}
// Connection test
for (WireFace facing : validSides) {
if (WireUtils.canConnectInternal(this, facing)) {
internalConnections |= 1 << facing.ordinal();
} else if (facing != WireFace.CENTER) {
if (WireUtils.canConnectExternal(this, facing.facing)) {
externalConnections |= 1 << facing.ordinal();
} else if (location != WireFace.CENTER && !invalidCornerSides.contains(facing) && WireUtils.canConnectCorner(this, facing.facing)) {
cornerConnections |= 1 << facing.ordinal();
}
}
}
int newConnectionCache = getConnectionMask();
if (oldConnectionCache != newConnectionCache) {
container.requestNeighborUpdate(oldConnectionCache ^ newConnectionCache);
container.requestRenderUpdate();
}
connectionCheckDirty = false;
}
use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.
the class BlockWire method requestNeighborUpdate.
public void requestNeighborUpdate(World world, BlockPos pos, WireFace location, int connectionMask) {
if ((connectionMask & 0xFF) != 0 && world instanceof IMultipartWorld) {
IPartInfo info = ((IMultipartWorld) world).getPartInfo();
info.getContainer().notifyChange(info);
}
for (EnumFacing facing : EnumFacing.VALUES) {
if (world.isRemote) {
if ((connectionMask & (1 << (facing.ordinal() + 8))) != 0) {
WireUtils.getAllWires(world, pos.offset(facing)).forEach((wire) -> wire.onChanged(true));
} else if (location != WireFace.CENTER && location.facing.getAxis() != facing.getAxis()) {
WireUtils.getAllWires(world, pos.offset(facing).offset(location.facing)).forEach((wire) -> wire.onChanged(true));
}
} else {
if ((connectionMask & (1 << (facing.ordinal() + 8))) != 0) {
world.neighborChanged(pos.offset(facing), this, pos);
} else if (location != WireFace.CENTER && location.facing.getAxis() != facing.getAxis()) {
world.neighborChanged(pos.offset(facing).offset(location.facing), this, pos);
}
}
}
}
use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.
the class BlockWire method getSlotForPlacement.
@Override
public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer) {
ItemStack stack = placer.getHeldItemMainhand();
WireFace location = (stack.getMetadata() & 1) != 0 ? WireFace.CENTER : WireFace.get(facing.getOpposite());
return WireUtils.toPartSlot(location);
}
use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.
the class ItemWire method placeWirePartAt.
public boolean placeWirePartAt(ItemStack stack, EntityPlayer player, EnumHand hand, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, IMultipart multipartBlock, IBlockState state) {
WireProvider factory = WireManager.REGISTRY.getValue(stack.getMetadata() >> 1);
WireFace location = (stack.getMetadata() & 1) != 0 ? WireFace.CENTER : WireFace.get(facing.getOpposite());
if (!factory.canPlace(world, pos, location)) {
return false;
}
return ItemBlockMultipart.placePartAt(stack, player, hand, world, pos, facing, hitX, hitY, hitZ, multipartBlock, state);
}
Aggregations