Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Xs to Machine Grid #356

Merged
merged 4 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import gregtech.api.cover.ICoverable;
import gregtech.api.gui.ModularUI;
import gregtech.api.metatileentity.multiblock.MultiblockControllerBase;
import gregtech.api.pipenet.tile.TileEntityPipeBase;
import gregtech.api.recipes.FluidKey;
import gregtech.client.renderer.texture.Textures;
import gregtech.api.util.*;
Expand Down Expand Up @@ -736,14 +737,14 @@ public int getHarvestLevel() {
public void writeInitialSyncData(PacketBuffer buf) {
buf.writeByte(this.frontFacing.getIndex());
boolean isPainted = false;
if(this.paintingColor != DEFAULT_PAINTING_COLOR && !(this instanceof MultiblockControllerBase)) {
for(EnumDyeColor color : EnumDyeColor.values()) {
if(this.paintingColor == color.colorValue) {
if (this.paintingColor != DEFAULT_PAINTING_COLOR && !(this instanceof MultiblockControllerBase)) {
for (EnumDyeColor color : EnumDyeColor.values()) {
if (this.paintingColor == color.colorValue) {
isPainted = true;
break;
}
}
if(!isPainted) {
if (!isPainted) {
setPaintingColor(DEFAULT_PAINTING_COLOR);
}
}
Expand Down Expand Up @@ -1356,4 +1357,16 @@ public final void toggleMuffled() {
public boolean isMuffled() {
return muffled;
}

public boolean canRenderFrontFaceX() {
return false;
}

public boolean isSideUsed(EnumFacing face) {
if (getCoverAtSide(face) != null) return true;
if (face == this.getFrontFacing() && this.canRenderFrontFaceX()) return true;
TileEntity tileEntity = this.getWorld().getTileEntity(this.getPos().add(face.getOpposite().getDirectionVec()));
if (!(tileEntity instanceof TileEntityPipeBase)) return false;
return ((TileEntityPipeBase) tileEntity).isConnectionOpenAny(face);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.pipenet.tile.TileEntityPipeBase;
import gregtech.api.util.GTUtility;
import gregtech.api.util.function.BooleanConsumer;
import gregtech.common.metatileentities.multi.electric.centralmonitor.MetaTileEntityMonitorScreen;
import gregtech.common.pipelike.cable.Insulation;
import gregtech.common.pipelike.fluidpipe.FluidPipeType;
Expand All @@ -36,10 +37,16 @@
import org.lwjgl.opengl.GL11;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

@SideOnly(Side.CLIENT)
public class ToolOverlayRenderer {

private static float rColor;
private static float gColor;
private static float bColor;

public static void onDrawBlockHighlight(DrawBlockHighlightEvent event) {
EntityPlayer player = event.getPlayer();
World world = player.world;
Expand Down Expand Up @@ -94,8 +101,15 @@ public static void onDrawBlockHighlight(DrawBlockHighlightEvent event) {
double d4 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) event.getPartialTicks();
double d5 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) event.getPartialTicks();
AxisAlignedBB box = blockState.getSelectedBoundingBox(world, pos).grow(0.002D).offset(-d3, -d4, -d5);
RenderGlobal.drawSelectionBoundingBox(box, 0.0F, 0.0F, 0.0F, 0.4F);
drawOverlayLines(facing, box);
RenderGlobal.drawSelectionBoundingBox(box, 1, 1, 1, 0.4F);
rColor = gColor = bColor = 0.2f + (float) Math.sin((float) (System.currentTimeMillis() % (Math.PI * 800)) / 800) / 2;

if (tileEntity instanceof TileEntityPipeBase)
drawOverlayLines(facing, box, ((TileEntityPipeBase) tileEntity)::isConnectionOpenAny);
else if (tileEntity instanceof MetaTileEntityHolder)
drawOverlayLines(facing, box, face -> ((MetaTileEntityHolder) tileEntity).getMetaTileEntity().isSideUsed(face));
else
drawOverlayLines(facing, box, ignored -> false);
}

GlStateManager.depthMask(true);
Expand Down Expand Up @@ -210,7 +224,7 @@ private static void drawBlockDamageTexture(DrawBlockHighlightEvent event, List<B
postRenderDamagedBlocks();
}

private static void drawOverlayLines(EnumFacing facing, AxisAlignedBB box) {
private static void drawOverlayLines(EnumFacing facing, AxisAlignedBB box, Function<EnumFacing, Boolean> test) {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
Expand All @@ -223,13 +237,19 @@ private static void drawOverlayLines(EnumFacing facing, AxisAlignedBB box) {
Vector3 shiftVert = new Vector3(0, 0.25, 0);

Vector3 cubeCenter = new Vector3(box.getCenter());



topRight.subtract(cubeCenter);
bottomRight.subtract(cubeCenter);
bottomLeft.subtract(cubeCenter);
topLeft.subtract(cubeCenter);

boolean leftBlocked;
boolean topBlocked;
boolean rightBlocked;
boolean bottomBlocked;
boolean frontBlocked = test.apply(facing);
boolean backBlocked = test.apply(facing.getOpposite());

switch (facing) {
case WEST: {
topRight.rotate(Math.PI / 2, Vector3.down);
Expand All @@ -238,6 +258,11 @@ private static void drawOverlayLines(EnumFacing facing, AxisAlignedBB box) {
topLeft.rotate(Math.PI / 2, Vector3.down);
shift.rotate(Math.PI / 2, Vector3.down);
shiftVert.rotate(Math.PI / 2, Vector3.down);

leftBlocked = test.apply(EnumFacing.NORTH);
topBlocked = test.apply(EnumFacing.UP);
rightBlocked = test.apply(EnumFacing.SOUTH);
bottomBlocked = test.apply(EnumFacing.DOWN);
break;
}
case EAST: {
Expand All @@ -247,6 +272,11 @@ private static void drawOverlayLines(EnumFacing facing, AxisAlignedBB box) {
topLeft.rotate(-Math.PI / 2, Vector3.down);
shift.rotate(-Math.PI / 2, Vector3.down);
shiftVert.rotate(-Math.PI / 2, Vector3.down);

leftBlocked = test.apply(EnumFacing.SOUTH);
topBlocked = test.apply(EnumFacing.UP);
rightBlocked = test.apply(EnumFacing.NORTH);
bottomBlocked = test.apply(EnumFacing.DOWN);
break;
}
case NORTH: {
Expand All @@ -256,6 +286,11 @@ private static void drawOverlayLines(EnumFacing facing, AxisAlignedBB box) {
topLeft.rotate(Math.PI, Vector3.down);
shift.rotate(Math.PI, Vector3.down);
shiftVert.rotate(Math.PI, Vector3.down);

leftBlocked = test.apply(EnumFacing.EAST);
topBlocked = test.apply(EnumFacing.UP);
rightBlocked = test.apply(EnumFacing.WEST);
bottomBlocked = test.apply(EnumFacing.DOWN);
break;
}
case UP: {
Expand All @@ -266,6 +301,11 @@ private static void drawOverlayLines(EnumFacing facing, AxisAlignedBB box) {
topLeft.rotate(-Math.PI / 2, side);
shift.rotate(-Math.PI / 2, side);
shiftVert.rotate(-Math.PI / 2, side);

leftBlocked = test.apply(EnumFacing.WEST);
topBlocked = test.apply(EnumFacing.NORTH);
rightBlocked = test.apply(EnumFacing.EAST);
bottomBlocked = test.apply(EnumFacing.SOUTH);
break;
}
case DOWN: {
Expand All @@ -276,8 +316,19 @@ private static void drawOverlayLines(EnumFacing facing, AxisAlignedBB box) {
topLeft.rotate(Math.PI / 2, side);
shift.rotate(Math.PI / 2, side);
shiftVert.rotate(Math.PI / 2, side);

leftBlocked = test.apply(EnumFacing.WEST);
topBlocked = test.apply(EnumFacing.SOUTH);
rightBlocked = test.apply(EnumFacing.EAST);
bottomBlocked = test.apply(EnumFacing.NORTH);
break;
}
default: {
leftBlocked = test.apply(EnumFacing.WEST);
topBlocked = test.apply(EnumFacing.UP);
rightBlocked = test.apply(EnumFacing.EAST);
bottomBlocked = test.apply(EnumFacing.DOWN);
}
}

topRight.add(cubeCenter);
Expand All @@ -299,15 +350,67 @@ private static void drawOverlayLines(EnumFacing facing, AxisAlignedBB box) {
startLine(buffer, bottomLeft.copy().add(shiftVert));
endLine(buffer, bottomRight.copy().add(shiftVert));

if (leftBlocked) {
startLine(buffer, topLeft.copy().add(shiftVert.copy().negate()));
endLine(buffer, bottomLeft.copy().add(shiftVert.copy()).add(shift));

startLine(buffer, topLeft.copy().add(shiftVert.copy().negate()).add(shift));
endLine(buffer, bottomLeft.copy().add(shiftVert));
}
if (topBlocked) {
startLine(buffer, topLeft.copy().add(shift));
endLine(buffer, topRight.copy().add(shift.copy().negate()).add(shiftVert.copy().negate()));

startLine(buffer, topLeft.copy().add(shift).add(shiftVert.copy().negate()));
endLine(buffer, topRight.copy().add(shift.copy().negate()));
}
if (rightBlocked) {
startLine(buffer, topRight.copy().add(shiftVert.copy().negate()));
endLine(buffer, bottomRight.copy().add(shiftVert.copy()).add(shift.copy().negate()));

startLine(buffer, topRight.copy().add(shiftVert.copy().negate()).add(shift.copy().negate()));
endLine(buffer, bottomRight.copy().add(shiftVert));
}
if (bottomBlocked) {
startLine(buffer, bottomLeft.copy().add(shift));
endLine(buffer, bottomRight.copy().add(shift.copy().negate()).add(shiftVert));

startLine(buffer, bottomLeft.copy().add(shift).add(shiftVert));
endLine(buffer, bottomRight.copy().add(shift.copy().negate()));
}
if (frontBlocked) {
startLine(buffer, topLeft.copy().add(shift).add(shiftVert.copy().negate()));
endLine(buffer, bottomRight.copy().add(shift.copy().negate()).add(shiftVert));

startLine(buffer, topRight.copy().add(shift.copy().negate()).add(shiftVert.copy().negate()));
endLine(buffer, bottomLeft.copy().add(shift).add(shiftVert));
}
if (backBlocked) {
Vector3 localXShift = new Vector3(0, 0, 0); // Set up translations for the current X.
for (int i = 0; i < 2; i++) {
Vector3 localXShiftVert = new Vector3(0, 0, 0);
for (int j = 0; j < 2; j++) {
startLine(buffer, topLeft.copy().add(localXShift).add(localXShiftVert));
endLine(buffer, topLeft.copy().add(localXShift).add(localXShiftVert).add(shift).subtract(shiftVert));

startLine(buffer, topLeft.copy().add(localXShift).add(localXShiftVert).add(shift));
endLine(buffer, topLeft.copy().add(localXShift).add(localXShiftVert).subtract(shiftVert));

localXShiftVert.add(bottomLeft.copy().subtract(topLeft).add(shiftVert)); // Move by the vector from the top to the bottom, minus the shift from the edge.
}
localXShift.add(topRight.copy().subtract(topLeft).subtract(shift)); // Move by the vector from the left to the right, minus the shift from the edge.
}
}

tessellator.draw();
}

private static void startLine(BufferBuilder buffer, Vector3 vec) {
buffer.pos(vec.x, vec.y, vec.z).color(0, 0, 0, 0.0F).endVertex();
buffer.pos(vec.x, vec.y, vec.z).color(rColor, gColor, bColor, 0.0F).endVertex();
}

private static void endLine(BufferBuilder buffer, Vector3 vec) {
buffer.pos(vec.x, vec.y, vec.z).color(0, 0, 0, 0.5F).endVertex();
buffer.pos(vec.x, vec.y, vec.z).color(rColor, gColor, bColor, 1F).endVertex();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,9 @@ public void addInformation(ItemStack stack, @Nullable World player, List<String>
tooltip.add(I18n.format("gregtech.universal.tooltip.energy_storage_capacity", energyContainer.getEnergyCapacity()));
tooltip.add(I18n.format("gregtech.universal.enabled"));
}

@Override
public boolean canRenderFrontFaceX() {
return isExportHatch;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,9 @@ public void addInformation(ItemStack stack, @Nullable World player, List<String>
tooltip.add(I18n.format("gregtech.universal.tooltip.energy_storage_capacity", energyContainer.getEnergyCapacity()));
tooltip.add(I18n.format("gregtech.universal.enabled"));
}

@Override
public boolean canRenderFrontFaceX() {
return isExportHatch;
}
}