From dda786c0183f6655a4a264edf2d75688e7fe895e Mon Sep 17 00:00:00 2001 From: GDCloud <93287602+GDCloudstrike@users.noreply.github.com> Date: Sun, 15 Sep 2024 19:38:40 +0200 Subject: Godforge finale (#3080) Co-authored-by: BucketBrigade <138534411+CookieBrigade@users.noreply.github.com> Co-authored-by: Martin Robertz Co-authored-by: serenibyss <10861407+serenibyss@users.noreply.github.com> --- .../tectech/thing/block/RenderForgeOfGods.java | 421 ++++++++++++++++++- .../tectech/thing/block/TileEntityForgeOfGods.java | 176 ++++++-- .../java/tectech/thing/gui/TecTechUITextures.java | 28 +- .../thing/metaTileEntity/multi/MTEForgeOfGods.java | 464 ++++++++++++++++++--- .../multi/godforge_modules/MTEBaseModule.java | 16 +- .../multi/godforge_modules/MTEExoticModule.java | 332 +++++++++++---- .../multi/godforge_modules/MTEMoltenModule.java | 101 +---- .../multi/godforge_modules/MTEPlasmaModule.java | 21 +- .../multi/godforge_modules/MTESmeltingModule.java | 16 +- 9 files changed, 1293 insertions(+), 282 deletions(-) (limited to 'src/main/java/tectech/thing') diff --git a/src/main/java/tectech/thing/block/RenderForgeOfGods.java b/src/main/java/tectech/thing/block/RenderForgeOfGods.java index 976dd6da8e..04c46155c0 100644 --- a/src/main/java/tectech/thing/block/RenderForgeOfGods.java +++ b/src/main/java/tectech/thing/block/RenderForgeOfGods.java @@ -1,52 +1,427 @@ package tectech.thing.block; -import static tectech.Reference.MODID; -import static tectech.rendering.EOH.EOHRenderingUtils.renderStarLayer; import static tectech.rendering.EOH.EOHTileEntitySR.STAR_LAYER_0; import static tectech.rendering.EOH.EOHTileEntitySR.STAR_LAYER_1; import static tectech.rendering.EOH.EOHTileEntitySR.STAR_LAYER_2; +import static tectech.thing.casing.TTCasingsContainer.GodforgeCasings; -import java.awt.Color; +import java.nio.FloatBuffer; +import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.AdvancedModelLoader; import net.minecraftforge.client.model.IModelCustom; +import org.joml.Matrix4fStack; +import org.joml.Vector3f; +import org.joml.Vector4f; +import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; +import org.lwjgl.opengl.GL15; +import org.lwjgl.opengl.GL20; + +import com.gtnewhorizon.gtnhlib.client.renderer.shader.ShaderProgram; +import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VertexBuffer; + +import tectech.Reference; +import tectech.thing.metaTileEntity.multi.ForgeOfGodsRingsStructureString; +import tectech.thing.metaTileEntity.multi.ForgeOfGodsStructureString; +import tectech.util.StructureVBO; +import tectech.util.TextureUpdateRequester; public class RenderForgeOfGods extends TileEntitySpecialRenderer { - public static IModelCustom starModel; + private static ShaderProgram starProgram; + private static IModelCustom starModel; + private static float modelNormalize = .0067f * 2; + + private static boolean initialized = false; + private static int u_Color = -1, u_ModelMatrix = -1, u_Gamma = -1; + private Matrix4fStack starModelMatrix = new Matrix4fStack(3); + + private static ShaderProgram beamProgram; + private static int a_VertexID = -1; + private static int u_BeamModelMatrix = -1; + private static int u_CameraPosition = -1, u_SegmentArray = -1, u_SegmentQuads = -1; + private static int u_BeamIntensity = -1, u_BeamColor = -1, u_BeamTime = -1; + private static int beam_vboID = -1; + private static int maxSegments = -1; + private static final int beamSegmentQuads = 16; + private static Matrix4fStack beamModelMatrix = new Matrix4fStack(2); + + private VertexBuffer ringOne, ringTwo, ringThree; + // These are nudges/translations for each ring to align with the structure + private static final Vector3f ringOneNudge = new Vector3f(0, -1, 0); + private static final Vector3f ringTwoNudge = new Vector3f(0, -1, 0); + private static final Vector3f ringThreeNudge = new Vector3f(.5f, -1, 0); + + private static ShaderProgram fadeBypassProgram; + private static TextureUpdateRequester textureUpdater; + + private void init() { + try { + starProgram = new ShaderProgram(Reference.MODID, "shaders/star.vert.glsl", "shaders/star.frag.glsl"); + + u_Color = starProgram.getUniformLocation("u_Color"); + u_Gamma = starProgram.getUniformLocation("u_Gamma"); + u_ModelMatrix = starProgram.getUniformLocation("u_ModelMatrix"); + + } catch (Exception e) { + System.out.println(e.getMessage()); + return; + } + + starModel = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.MODID, "models/Star.obj")); + + try { + beamProgram = new ShaderProgram( + Reference.MODID, + "shaders/gorgeBeam.vert.glsl", + "shaders/gorgeBeam.frag.glsl"); - public RenderForgeOfGods() { - starModel = AdvancedModelLoader.loadModel(new ResourceLocation(MODID, "models/Star.obj")); + u_BeamModelMatrix = beamProgram.getUniformLocation("u_ModelMatrix"); + u_CameraPosition = beamProgram.getUniformLocation("u_CameraPosition"); + u_SegmentQuads = beamProgram.getUniformLocation("u_SegmentQuads"); + u_SegmentArray = beamProgram.getUniformLocation("u_SegmentArray"); + u_BeamColor = beamProgram.getUniformLocation("u_Color"); + u_BeamIntensity = beamProgram.getUniformLocation("u_Intensity"); + u_BeamTime = beamProgram.getUniformLocation("u_Time"); + + a_VertexID = beamProgram.getAttribLocation("a_VertexID"); + } catch (Exception e) { + System.out.println(e.getMessage()); + return; + } + + beamProgram.use(); + GL20.glUniform1f(u_SegmentQuads, (float) beamSegmentQuads); + maxSegments = 10;// GL20.glGetActiveUniformSize(beamProgram.getProgram(), u_SegmentArray); + + FloatBuffer buffer = BufferUtils.createFloatBuffer(maxSegments * beamSegmentQuads * 6 * 3); + + for (int i = 0; i < maxSegments; i++) { + for (int j = 0; j < beamSegmentQuads; j++) { + for (int v = 0; v < 6; v++) { + int segID = i * beamSegmentQuads * 6; + int quadID = j * 6; + int vertID = segID + quadID + v; + buffer.put(vertID); + buffer.put(0); + buffer.put(0); + } + } + } + + buffer.flip(); + beam_vboID = GL15.glGenBuffers(); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, beam_vboID); + GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); + GL20.glVertexAttribPointer(a_VertexID, 1, GL11.GL_FLOAT, false, 3 * Float.BYTES, 0); + GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0); + + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + ShaderProgram.clear(); + initialized = true; } - @Override - public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float timeSinceLastTick) { - if (!(tile instanceof TileEntityForgeOfGods)) return; + private void initRings() { + StructureVBO ringStructure = (new StructureVBO()).addMapping('H', BlockGodforgeGlass.INSTANCE, 0) + .addMapping('B', GodforgeCasings, 0) + .addMapping('C', GodforgeCasings, 1) + .addMapping('D', GodforgeCasings, 2) + .addMapping('E', GodforgeCasings, 3) + .addMapping('G', GodforgeCasings, 5) + .addMapping('K', GodforgeCasings, 6) + .addMapping('I', GodforgeCasings, 7); - { - GL11.glPushMatrix(); - GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5); - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_BLEND); + ringOne = ringStructure.assignStructure(ForgeOfGodsStructureString.FIRST_RING) + .build(); + ringTwo = ringStructure.assignStructure(ForgeOfGodsRingsStructureString.SECOND_RING) + .build(); + ringThree = ringStructure.assignStructure(ForgeOfGodsRingsStructureString.THIRD_RING) + .build(); - // Innermost layer should be opaque - enableOpaqueColorInversion(); - renderStarLayer(0, STAR_LAYER_0, new Color(1.0f, 0.4f, 0.05f, 1.0f), 1.0f, 25); - disableOpaqueColorInversion(); + fadeBypassProgram = new ShaderProgram( + Reference.MODID, + "shaders/fadebypass.vert.glsl", + "shaders/fadebypass.frag.glsl"); - enablePseudoTransparentColorInversion(); - renderStarLayer(1, STAR_LAYER_1, new Color(1.0f, 0.4f, 0.05f, 1.0f), 0.4f, 25); - renderStarLayer(2, STAR_LAYER_2, new Color(1.0f, 0.4f, 0.05f, 1.0f), 0.2f, 25); + textureUpdater = ringStructure.getTextureUpdateRequestor(); + } + + public void RenderStarLayer(Vector4f color, ResourceLocation texture, float size, Vector3f rotationAxis, + float degrees) { + starModelMatrix.pushMatrix(); + starModelMatrix.rotate((degrees / 180f * ((float) Math.PI)), rotationAxis.x, rotationAxis.y, rotationAxis.z); + starModelMatrix.scale(size, size, size); + + this.bindTexture(texture); + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + + // Enable transparency if needed + if (color.w < 1 && color.w > 0) { + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glDepthMask(false); // Disable depth writing for transparency + } + + FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16); + GL20.glUniformMatrix4(u_ModelMatrix, false, starModelMatrix.get(matrixBuffer)); + GL20.glUniform4f(u_Color, color.x, color.y, color.z, color.w); + starModel.renderAll(); + GL11.glPopAttrib(); + starModelMatrix.popMatrix(); + } + + public void RenderEntireStar(TileEntityForgeOfGods tile, double x, double y, double z, float timer) { + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL13.glActiveTexture(GL13.GL_TEXTURE0); + GL11.glDisable(GL11.GL_LIGHTING); + + starProgram.use(); + + float cx = (float) x + .5f; + float cy = (float) y + .5f; + float cz = (float) z + .5f; + float size = modelNormalize; + starModelMatrix.clear(); + starModelMatrix.translate(cx, cy, cz); + + size *= tile.getStarRadius(); - GL11.glPopAttrib(); + timer *= tile.getRotationSpeed(); + + float r = tile.getColorR(), g = tile.getColorG(), b = tile.getColorB(); + GL20.glUniform1f(u_Gamma, tile.getGamma()); + RenderStarLayer( + new Vector4f(r, g, b, 1f), + STAR_LAYER_0, + size, + new Vector3f(0F, 1F, 1).normalize(), + 130 + (timer) % 360000); + RenderStarLayer( + new Vector4f(r, g, b, 0.4f), + STAR_LAYER_1, + size * 1.02f, + new Vector3f(1F, 1F, 0F).normalize(), + -49 + (timer) % 360000); + RenderStarLayer( + new Vector4f(r, g, b, 0.2f), + STAR_LAYER_2, + size * 1.04f, + new Vector3f(1F, 0F, 1F).normalize(), + 67 + (timer) % 360000); + + ShaderProgram.clear(); + GL11.glPopAttrib(); + } + + public void bufferSoftBeam(TileEntityForgeOfGods tile) { + FloatBuffer buffer = BufferUtils.createFloatBuffer(maxSegments * 3); + + float angle = tile.getStartAngle(); + float radius = tile.getStarRadius() * 1.1f; + float startx = -radius * ((float) Math.cos(angle)); + float starty = radius * ((float) Math.sin(angle)); + + buffer.put(starty); + buffer.put(startx); + buffer.put(0); + + for (int i = tile.getRingCount() - 1; i >= 0; i--) { + buffer.put(tile.getLenRadius(i)); + buffer.put(tile.getLensDistance(i)); + buffer.put(1f); + } + + buffer.put(TileEntityForgeOfGods.BACK_PLATE_RADIUS); + buffer.put(TileEntityForgeOfGods.BACK_PLATE_DISTANCE); + buffer.put(-.05f); + + buffer.rewind(); + GL20.glUniform3(u_SegmentArray, buffer); + } + + public void bufferIntenseBeam(TileEntityForgeOfGods tile) { + FloatBuffer buffer = BufferUtils.createFloatBuffer(maxSegments * 3); + float angle = tile.getStartAngle(); + float radius = tile.getStarRadius() * 1.05f; + float startx = -radius * ((float) Math.cos(angle)); + float starty = radius * ((float) Math.sin(angle)); + + // first lens means the one closest to the star + int firstLens = tile.getRingCount() - 1; + + float nextx = tile.getLensDistance(firstLens); + float nexty = tile.getLenRadius(firstLens) * .75f; + + float backx = Math.max(-radius, (nextx + radius) / 2); + float backy = TileEntityForgeOfGods.interpolate(startx, nextx, starty, nexty, backx); + + buffer.put(backy); + buffer.put(backx); + buffer.put(0); + + float transparency = .2f; + for (int i = tile.getRingCount() - 1; i >= 0; i--) { + buffer.put(tile.getLenRadius(i) / 2); + buffer.put(tile.getLensDistance(i)); + buffer.put(transparency); + transparency += .3f; + } + + float currx = tile.getLensDistance(0); + float curry = tile.getLenRadius(0) / 2; + float lastx = TileEntityForgeOfGods.BACK_PLATE_DISTANCE; + float lasty = Math.min(tile.getLenRadius(firstLens), TileEntityForgeOfGods.BACK_PLATE_RADIUS); + + float midx = lastx + 8f; + float midy = TileEntityForgeOfGods.interpolate(currx, lastx, curry, lasty, midx); + + buffer.put(midy); + buffer.put(midx); + buffer.put(transparency); + + buffer.put(lasty); + buffer.put(lastx); + buffer.put(0f); + + buffer.rewind(); + GL20.glUniform3(u_SegmentArray, buffer); + // return buffer; + } + + public void RenderBeamSegment(TileEntityForgeOfGods tile, double x, double y, double z, float timer) { + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + // GL11.glDisable(GL11.GL_TEXTURE_2D); + // GL11.glDisable(GL11.GL_CULL_FACE); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glDisable(GL11.GL_LIGHTING); + GL13.glActiveTexture(GL13.GL_TEXTURE0); + this.bindTexture(new ResourceLocation(Reference.MODID, "models/spaceLayer.png")); + + float cx = (float) x + .5f; + float cy = (float) y + .5f; + float cz = (float) z + .5f; + beamModelMatrix.clear(); + beamModelMatrix.translate(cx, cy, cz); + + beamModelMatrix.rotate( + tile.getRotAngle() / 180 * ((float) Math.PI), + tile.getRotAxisX(), + tile.getRotAxisY(), + tile.getRotAxisZ()); + beamModelMatrix.rotate((float) Math.PI / 2f, 0, 1, 0); + + beamProgram.use(); + + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glDepthMask(false); // Disable depth writing for transparency + + bufferSoftBeam(tile); + + FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16); + GL20.glUniformMatrix4(u_BeamModelMatrix, false, beamModelMatrix.get(matrixBuffer)); + + beamModelMatrix.invert(); + + Vector4f cameraPosition = new Vector4f( + ActiveRenderInfo.objectX, + ActiveRenderInfo.objectY, + ActiveRenderInfo.objectZ, + 1); + cameraPosition = beamModelMatrix.transform(cameraPosition); + GL20.glUniform3f(u_CameraPosition, cameraPosition.x, cameraPosition.y, cameraPosition.z); + GL20.glUniform3f(u_BeamColor, tile.getColorR(), tile.getColorG(), tile.getColorB()); + GL20.glUniform1f(u_BeamIntensity, 2); + GL20.glUniform1f(u_BeamTime, timer); + + GL20.glEnableVertexAttribArray(a_VertexID); + GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); + + GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, maxSegments * beamSegmentQuads * 6); + + GL20.glUniform3f(u_BeamColor, 1, 1, 1); + GL20.glUniform1f(u_BeamIntensity, 4); + bufferIntenseBeam(tile); + GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, maxSegments * beamSegmentQuads * 6); + + GL20.glDisableVertexAttribArray(a_VertexID); + GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY); + + GL11.glPopAttrib(); + ShaderProgram.clear(); + } + + private void RenderRings(TileEntityForgeOfGods tile, double x, double y, double z, float timer) { + bindTexture(TextureMap.locationBlocksTexture); + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + textureUpdater.requestUpdate(); + fadeBypassProgram.use(); + + GL11.glPushMatrix(); + GL11.glTranslated(x + .5f, y + .5f, z + .5f); + GL11.glRotatef(tile.getRotAngle(), tile.getRotAxisX(), tile.getRotAxisY(), tile.getRotAxisZ()); + GL11.glRotatef(timer / 6 * 7, 1, 0, 0); + GL11.glTranslated(ringOneNudge.x, ringOneNudge.y, ringOneNudge.z); + + ringOne.render(); + GL11.glPopMatrix(); + if (tile.getRingCount() > 1) { + GL11.glPushMatrix(); + GL11.glTranslated(x + .5f, y + .5f, z + .5f); + GL11.glRotatef(tile.getRotAngle(), tile.getRotAxisX(), tile.getRotAxisY(), tile.getRotAxisZ()); + GL11.glRotatef(-timer / 4 * 5, 1, 0, 0); + GL11.glTranslated(ringTwoNudge.x, ringTwoNudge.y, ringTwoNudge.z); + ringTwo.render(); GL11.glPopMatrix(); + + if (tile.getRingCount() > 2) { + GL11.glPushMatrix(); + GL11.glTranslated(x + .5f, y + .5f, z + .5f); + GL11.glRotatef(tile.getRotAngle(), tile.getRotAxisX(), tile.getRotAxisY(), tile.getRotAxisZ()); + GL11.glRotatef(timer * 3, 1, 0, 0); + GL11.glTranslated(ringThreeNudge.x, ringThreeNudge.y, ringThreeNudge.z); + ringThree.render(); + GL11.glPopMatrix(); + } } + ShaderProgram.clear(); + GL11.glPopAttrib(); + } + + @Override + public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float timeSinceLastTick) { + if (!(tile instanceof TileEntityForgeOfGods forgeTile)) return; + if (forgeTile.getRingCount() < 1) return; + + if (!initialized) { + init(); + initRings(); + if (!initialized) return; + } + + // Based on system time to prevent tps issues from causing stutters + // Need to look into different timing system to prevent stutters based on tps issues + // But prevent bypassing the pause menu + long millis = System.currentTimeMillis() % (1000 * 36000); + float timer = millis / (50f); // to ticks + + RenderEntireStar(forgeTile, x, y, z, timer); + RenderRings(forgeTile, x, y, z, timer); + + RenderBeamSegment(forgeTile, x, y, z, timer); + } public static void enablePseudoTransparentColorInversion() { diff --git a/src/main/java/tectech/thing/block/TileEntityForgeOfGods.java b/src/main/java/tectech/thing/block/TileEntityForgeOfGods.java index 7c671b8a31..dfe4bab143 100644 --- a/src/main/java/tectech/thing/block/TileEntityForgeOfGods.java +++ b/src/main/java/tectech/thing/block/TileEntityForgeOfGods.java @@ -6,11 +6,32 @@ import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation; public class TileEntityForgeOfGods extends TileEntity { - private float size = 10; + private float radius = 32; private float rotationSpeed = 10; + private int ringCount = 1; + private float colorR = .7f, colorG = .8f, colorB = 1f, gamma = 3f; + private float rotAngle = 0, rotAxisX = 1, rotAxisY = 0, rotAxisZ = 0; + + private static final String NBT_TAG = "FOG:"; + private static final String ROTATION_SPEED_NBT_TAG = NBT_TAG + "ROTATION"; + private static final String SIZE_NBT_TAG = NBT_TAG + "RADIUS"; + private static final String RINGS_NBT_TAG = NBT_TAG + "RINGS"; + private static final String COLOR_RED_NBT_TAG = NBT_TAG + "COLOR_RED"; + private static final String COLOR_GREEN_NBT_TAG = NBT_TAG + "COLOR_GREEN"; + private static final String COLOR_BLUE_NBT_TAG = NBT_TAG + "COLOR_BLUE"; + private static final String COLOR_GAMMA_NBT_TAG = NBT_TAG + "COLOR_GAMMA"; + private static final String ROT_ANGLE_NBT_TAG = NBT_TAG + "ROT_ANGLE"; + private static final String ROT_AXIS_X_NBT_TAG = NBT_TAG + "ROT_AXIS_X"; + private static final String ROT_AXIS_Y_NBT_TAG = NBT_TAG + "ROT_AXIS_Y"; + private static final String ROT_AXIS_Z_NBT_TAG = NBT_TAG + "ROT_AXIS_Z"; + + public static final float BACK_PLATE_DISTANCE = -121.5f, BACK_PLATE_RADIUS = 13f; @Override public AxisAlignedBB getRenderBoundingBox() { @@ -19,53 +40,156 @@ public class TileEntityForgeOfGods extends TileEntity { @Override public double getMaxRenderDistanceSquared() { - return 25600; + return 51200; } - public void setRenderSize(float size) { - this.size = size; + public void setStarRadius(float size) { + this.radius = size; } - public void setRenderRotationSpeed(float rotationSpeed) { - this.rotationSpeed = rotationSpeed; + public float getStarRadius() { + return radius; } - public float getRenderSize() { - return size; + public float getRotationSpeed() { + return rotationSpeed; } - public float getRenderRotationSpeed() { - return rotationSpeed; + public void setRotationSpeed(float speed) { + this.rotationSpeed = speed; } - @Override - public void updateEntity() { - angle += 10.0f; + public float getColorR() { + return colorR; + } + + public float getColorG() { + return colorG; + } + + public float getColorB() { + return colorB; + } + + public float getGamma() { + return gamma; + } + + public void setColor(float r, float g, float b) { + setColor(r, g, b, 1); + } + + public void setColor(float r, float g, float b, float gamma) { + colorR = r; + colorG = g; + colorB = b; + this.gamma = gamma; + } + + public int getRingCount() { + return ringCount; + } + + public void setRingCount(int count) { + if (ringCount < 1) return; + ringCount = count; + } + + public float getRotAngle() { + return rotAngle; + } + + public float getRotAxisX() { + return rotAxisX; + } + + public float getRotAxisY() { + return rotAxisY; } - // Used to track the rotation of the star - public float angle; + public float getRotAxisZ() { + return rotAxisZ; + } - private static final String FOG_NBT_TAG = "FOG:"; - private static final String ROTATION_SPEED_NBT_TAG = FOG_NBT_TAG + "renderRotationSpeed"; - private static final String SIZE_NBT_TAG = FOG_NBT_TAG + "renderSize"; + public void setRenderRotation(Rotation rotation, ForgeDirection direction) { + switch (direction) { + case SOUTH -> rotAngle = 90; + case NORTH -> rotAngle = 90; + case WEST -> rotAngle = 0; + case EAST -> rotAngle = 180; + case UP -> rotAngle = -90; + case DOWN -> rotAngle = -90; + } + rotAxisX = 0; + rotAxisY = direction.offsetZ + direction.offsetX; + rotAxisZ = direction.offsetY; + + updateToClient(); + } + + public float getLensDistance(int lensID) { + return switch (lensID) { + case 0 -> -61.5f; + case 1 -> -54.5f; + case 2 -> -44.5f; + default -> throw new IllegalStateException("Unexpected value: " + lensID); + }; + } + + public float getLenRadius(int lensID) { + return switch (lensID) { + case 0 -> 1.1f; + case 1 -> 3.5f; + case 2 -> 5f; + default -> throw new IllegalStateException("Unexpected value: " + lensID); + }; + } + + public float getStartAngle() { + float x = -getLensDistance(getRingCount() - 1); + float y = getLenRadius(getRingCount() - 1); + float alpha = (float) Math.atan2(y, x); + float beta = (float) Math.asin(radius / Math.sqrt(x * x + y * y)); + return alpha + ((float) Math.PI / 2 - beta); + } + + public static float interpolate(float x0, float x1, float y0, float y1, float x) { + return y0 + ((x - x0) * (y1 - y0)) / (x1 - x0); + } @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); - - // Save stats compound.setFloat(ROTATION_SPEED_NBT_TAG, rotationSpeed); - compound.setFloat(SIZE_NBT_TAG, size); + compound.setFloat(SIZE_NBT_TAG, radius); + compound.setInteger(RINGS_NBT_TAG, ringCount); + compound.setFloat(COLOR_RED_NBT_TAG, colorR); + compound.setFloat(COLOR_GREEN_NBT_TAG, colorG); + compound.setFloat(COLOR_BLUE_NBT_TAG, colorB); + compound.setFloat(COLOR_GAMMA_NBT_TAG, gamma); + compound.setFloat(ROT_ANGLE_NBT_TAG, rotAngle); + compound.setFloat(ROT_AXIS_X_NBT_TAG, rotAxisX); + compound.setFloat(ROT_AXIS_Y_NBT_TAG, rotAxisY); + compound.setFloat(ROT_AXIS_Z_NBT_TAG, rotAxisZ); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); - - // Load stats rotationSpeed = compound.getFloat(ROTATION_SPEED_NBT_TAG); - size = compound.getFloat(SIZE_NBT_TAG); + radius = compound.getFloat(SIZE_NBT_TAG); + + ringCount = compound.getInteger(RINGS_NBT_TAG); + if (ringCount < 1) ringCount = 1; + + colorR = compound.getFloat(COLOR_RED_NBT_TAG); + colorG = compound.getFloat(COLOR_GREEN_NBT_TAG); + colorB = compound.getFloat(COLOR_BLUE_NBT_TAG); + gamma = compound.getFloat(COLOR_GAMMA_NBT_TAG); + rotAngle = compound.getFloat(ROT_ANGLE_NBT_TAG); + rotAxisX = compound.getFloat(ROT_AXIS_X_NBT_TAG); + rotAxisY = compound.getFloat(ROT_AXIS_Y_NBT_TAG); + rotAxisZ = compound.getFloat(ROT_AXIS_Z_NBT_TAG); } @Override @@ -79,4 +203,8 @@ public class TileEntityForgeOfGods extends TileEntity { public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { readFromNBT(pkt.func_148857_g()); } + + public void updateToClient() { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } } diff --git a/src/main/java/tectech/thing/gui/TecTechUITextures.java b/src/main/java/tectech/thing/gui/TecTechUITextures.java index d4bc73f8e1..f2774dc42f 100644 --- a/src/main/java/tectech/thing/gui/TecTechUITextures.java +++ b/src/main/java/tectech/thing/gui/TecTechUITextures.java @@ -23,6 +23,7 @@ public class TecTechUITextures { public static final UITexture BACKGROUND_GLOW_BLUE = UITexture.fullImage(MODID, "gui/background/blue_glow"); public static final UITexture BACKGROUND_GLOW_GREEN = UITexture.fullImage(MODID, "gui/background/green_glow"); public static final UITexture BACKGROUND_GLOW_WHITE = UITexture.fullImage(MODID, "gui/background/white_glow"); + public static final UITexture BACKGROUND_GLOW_RAINBOW = UITexture.fullImage(MODID, "gui/background/rainbow_glow"); public static final UITexture BACKGROUND_SPACE = UITexture.fullImage(MODID, "gui/background/space"); public static final UITexture BUTTON_STANDARD_16x16 = UITexture.fullImage(MODID, "gui/button/standard_16x16"); @@ -82,6 +83,7 @@ public class TecTechUITextures { public static final UITexture OVERLAY_BUTTON_BATTERY_OFF = UITexture .fullImage(MODID, "gui/overlay_button/battery_off"); public static final UITexture OVERLAY_BUTTON_FLAG = UITexture.fullImage(MODID, "gui/overlay_button/flag"); + public static final UITexture OVERLAY_BUTTON_HEART = UITexture.fullImage(MODID, "gui/overlay_button/heart"); public static final UITexture OVERLAY_CYCLIC_BLUE = UITexture.fullImage(MODID, "gui/overlay_button/cyclic_blue"); public static final UITexture OVERLAY_EJECTION_LOCKED = UITexture .fullImage(MODID, "gui/overlay_button/eject_disabled"); @@ -162,11 +164,26 @@ public class TecTechUITextures { public static final UITexture PICTURE_PARAMETER_GRAY = UITexture.fullImage(MODID, "gui/picture/parameter_gray"); public static final UITexture PICTURE_UNCERTAINTY_MONITOR_MULTIMACHINE = UITexture .fullImage(MODID, "gui/picture/uncertainty/monitor_multimachine"); - public static final UITexture PICTURE_UPGRADE_CONNECTOR_FULL = UITexture.fullImage(MODID, "gui/picture/connector"); - public static final UITexture PICTURE_UPGRADE_CONNECTOR_EMPTY = UITexture - .fullImage(MODID, "gui/picture/connector_empty"); - public static final UITexture PICTURE_UPGRADE_CONNECTOR_SWITCH = UITexture - .fullImage(MODID, "gui/picture/connector_switch"); + public static final UITexture PICTURE_UPGRADE_CONNECTOR_PURPLE = UITexture + .fullImage(MODID, "gui/picture/connector_purple"); + public static final UITexture PICTURE_UPGRADE_CONNECTOR_GREEN = UITexture + .fullImage(MODID, "gui/picture/connector_green"); + public static final UITexture PICTURE_UPGRADE_CONNECTOR_ORANGE = UITexture + .fullImage(MODID, "gui/picture/connector_orange"); + public static final UITexture PICTURE_UPGRADE_CONNECTOR_BLUE = UITexture + .fullImage(MODID, "gui/picture/connector_blue"); + public static final UITexture PICTURE_UPGRADE_CONNECTOR_RED = UITexture + .fullImage(MODID, "gui/picture/connector_red"); + public static final UITexture PICTURE_UPGRADE_CONNECTOR_PURPLE_OPAQUE = UITexture + .fullImage(MODID, "gui/picture/connector_purple_opaque"); + public static final UITexture PICTURE_UPGRADE_CONNECTOR_GREEN_OPAQUE = UITexture + .fullImage(MODID, "gui/picture/connector_green_opaque"); + public static final UITexture PICTURE_UPGRADE_CONNECTOR_ORANGE_OPAQUE = UITexture + .fullImage(MODID, "gui/picture/connector_orange_opaque"); + public static final UITexture PICTURE_UPGRADE_CONNECTOR_BLUE_OPAQUE = UITexture + .fullImage(MODID, "gui/picture/connector_blue_opaque"); + public static final UITexture PICTURE_UPGRADE_CONNECTOR_RED_OPAQUE = UITexture + .fullImage(MODID, "gui/picture/connector_red_opaque"); public static final UITexture SLOT_OUTLINE_GREEN = UITexture.fullImage(MODID, "gui/picture/green_selector"); public static final UITexture PICTURE_GODFORGE_MILESTONE_CHARGE = UITexture .fullImage(MODID, "gui/picture/milestone_charge"); @@ -176,6 +193,7 @@ public class TecTechUITextures { .fullImage(MODID, "gui/picture/milestone_catalyst"); public static final UITexture PICTURE_GODFORGE_MILESTONE_COMPOSITION = UITexture .fullImage(MODID, "gui/picture/milestone_composition"); + public static final UITexture PICTURE_GODFORGE_THANKS = UITexture.fullImage(MODID, "gui/picture/thanks"); public static final UITexture PICTURE_GODFORGE_MILESTONE_CHARGE_GLOW = UITexture .fullImage(MODID, "gui/picture/milestone_charge_glow"); public static final UITexture PICTURE_GODFORGE_MILESTONE_CONVERSION_GLOW = UITexture diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/MTEForgeOfGods.java b/src/main/java/tectech/thing/metaTileEntity/multi/MTEForgeOfGods.java index 181ee0d6d4..d55bf32e90 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/MTEForgeOfGods.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/MTEForgeOfGods.java @@ -38,6 +38,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; @@ -50,9 +51,9 @@ import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; import com.gtnewhorizons.modularui.api.ModularUITextures; import com.gtnewhorizons.modularui.api.drawable.IDrawable; -import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; import com.gtnewhorizons.modularui.api.drawable.Text; import com.gtnewhorizons.modularui.api.drawable.UITexture; +import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; import com.gtnewhorizons.modularui.api.math.Alignment; import com.gtnewhorizons.modularui.api.math.Color; @@ -66,12 +67,14 @@ import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.widget.ButtonWidget; import com.gtnewhorizons.modularui.common.widget.DrawableWidget; import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn; +import com.gtnewhorizons.modularui.common.widget.DynamicPositionedRow; import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; import com.gtnewhorizons.modularui.common.widget.FluidNameHolderWidget; import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; import com.gtnewhorizons.modularui.common.widget.ProgressBar; import com.gtnewhorizons.modularui.common.widget.Scrollable; import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; import com.gtnewhorizons.modularui.common.widget.TextWidget; import com.gtnewhorizons.modularui.common.widget.textfield.NumericWidget; @@ -97,6 +100,7 @@ import gregtech.common.tileentities.machines.MTEHatchInputBusME; import gregtech.common.tileentities.machines.MTEHatchInputME; import gregtech.common.tileentities.machines.MTEHatchOutputBusME; import tectech.TecTech; +import tectech.loader.TecTechConfig; import tectech.thing.block.BlockGodforgeGlass; import tectech.thing.block.TileEntityForgeOfGods; import tectech.thing.gui.TecTechUITextures; @@ -150,6 +154,7 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, private static final int INDIVIDUAL_MILESTONE_WINDOW_ID = 14; private static final int MANUAL_INSERTION_WINDOW_ID = 15; private static final int GENERAL_INFO_WINDOW_ID = 16; + private static final int SPECIAL_THANKS_WINDOW_ID = 17; private static final int TEXTURE_INDEX = 960; private static final int[] FIRST_SPLIT_UPGRADES = new int[] { 12, 13, 14 }; private static final Integer[] UPGRADE_MATERIAL_ID_CONVERSION = { 0, 5, 7, 11, 26, 29, 30 }; @@ -178,10 +183,9 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, private static final ItemStack STELLAR_FUEL = Avaritia.isModLoaded() ? getModItem(Avaritia.ID, "Resource", 1, 8) : GTOreDictUnificator.get(OrePrefixes.block, Materials.CosmicNeutronium, 1); - private final boolean debugMode = false; + private final boolean debugMode = TecTechConfig.DEBUG_MODE; public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { - if (mMachine) return -1; int realBudget = elementBudget >= 1000 ? elementBudget : Math.min(1000, elementBudget * 5); // 1000 blocks max per placement. int built = survivialBuildPiece(STRUCTURE_PIECE_MAIN, stackSize, 63, 14, 1, realBudget, env, false, true); @@ -241,7 +245,7 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, HatchElementBuilder.builder() .atLeast(moduleElement.Module) .casingIndex(TEXTURE_INDEX) - .dot(3) + .dot(2) .buildAndChain(GodforgeCasings, 0)) .addElement('K', ofBlock(GodforgeCasings, 6)) .addElement('L', ofBlock(Blocks.air, 0)) @@ -309,7 +313,6 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, public boolean checkMachine_EM(IGregTechTileEntity iGregTechTileEntity, ItemStack itemStack) { moduleHatches.clear(); - // Check structure of multi if (isRenderActive) { if (!structureCheck_EM(STRUCTURE_PIECE_SHAFT, 63, 14, 1) @@ -324,7 +327,6 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, if (internalBattery != 0 && !isRenderActive) { createRenderer(); } - // Check there is 1 input bus if (mInputBusses.size() != 1) { return false; @@ -340,7 +342,6 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, return false; } } - // Make sure there are no energy hatches { if (mEnergyHatches.size() > 0) { @@ -360,19 +361,38 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, if (isUpgradeActive(26)) { if (checkPiece(STRUCTURE_PIECE_SECOND_RING, 55, 11, -67)) { ringAmount = 2; + destroySecondRing(); + UpdateRenderer(); } if (isRenderActive && ringAmount >= 2 && !checkPiece(STRUCTURE_PIECE_SECOND_RING_AIR, 55, 11, -67)) { destroyRenderer(); } + } else { + if (ringAmount == 3) { + buildThirdRing(); + } + if (ringAmount >= 2) { + ringAmount = 1; + UpdateRenderer(); + buildSecondRing(); + } } if (isUpgradeActive(29)) { if (checkPiece(STRUCTURE_PIECE_THIRD_RING, 47, 13, -76)) { ringAmount = 3; + destroyThirdRing(); + UpdateRenderer(); } if (isRenderActive && ringAmount == 3 && !checkPiece(STRUCTURE_PIECE_THIRD_RING_AIR, 47, 13, -76)) { destroyRenderer(); } + } else { + if (ringAmount == 3) { + ringAmount = 2; + UpdateRenderer(); + buildThirdRing(); + } } return true; @@ -548,6 +568,38 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, } } + private TileEntityForgeOfGods getRenderer() { + IGregTechTileEntity gregTechTileEntity = this.getBaseMetaTileEntity(); + + int x = gregTechTileEntity.getXCoord(); + int y = gregTechTileEntity.getYCoord(); + int z = gregTechTileEntity.getZCoord(); + + double xOffset = 122 * getExtendedFacing().getRelativeBackInWorld().offsetX; + double zOffset = 122 * getExtendedFacing().getRelativeBackInWorld().offsetZ; + double yOffset = 122 * getExtendedFacing().getRelativeBackInWorld().offsetY; + + TileEntity tile = this.getBaseMetaTileEntity() + .getWorld() + .getTileEntity((int) (x + xOffset), (int) (y + yOffset), (int) (z + zOffset)); + + if (tile instanceof TileEntityForgeOfGods forgeTile) { + return forgeTile; + } + return null; + } + + private void UpdateRenderer() { + TileEntityForgeOfGods tile = getRenderer(); + if (tile == null) return; + + tile.setRingCount(ringAmount); + tile.setStarRadius(20); + tile.setRotationSpeed(5); + + tile.updateToClient(); + } + private void createRenderer() { IGregTechTileEntity gregTechTileEntity = this.getBaseMetaTileEntity(); @@ -570,24 +622,24 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, .getWorld() .getTileEntity((int) (x + xOffset), (int) (y + yOffset), (int) (z + zOffset)); - rendererTileEntity.setRenderSize(20); - rendererTileEntity.setRenderRotationSpeed(5); - switch (ringAmount) { case 2 -> { - buildPiece(STRUCTURE_PIECE_FIRST_RING_AIR, null, false, 63, 14, -59); - buildPiece(STRUCTURE_PIECE_SECOND_RING_AIR, null, false, 55, 11, -67); + destroyFirstRing(); + destroySecondRing(); } case 3 -> { - buildPiece(STRUCTURE_PIECE_FIRST_RING_AIR, null, false, 63, 14, -59); - buildPiece(STRUCTURE_PIECE_SECOND_RING_AIR, null, false, 55, 11, -67); - buildPiece(STRUCTURE_PIECE_THIRD_RING_AIR, null, false, 47, 13, -76); + destroyFirstRing(); + destroySecondRing(); + destroyThirdRing(); } default -> { - buildPiece(STRUCTURE_PIECE_FIRST_RING_AIR, null, false, 63, 14, -59); + destroyFirstRing(); } } + rendererTileEntity.setRenderRotation(getRotation(), getDirection()); + UpdateRenderer(); + isRenderActive = true; } @@ -609,26 +661,65 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, switch (ringAmount) { case 2 -> { - buildPiece(STRUCTURE_PIECE_FIRST_RING, null, false, 63, 14, -59); - buildPiece(STRUCTURE_PIECE_SECOND_RING, null, false, 55, 11, -67); + buildFirstRing(); + buildSecondRing(); } case 3 -> { - buildPiece(STRUCTURE_PIECE_FIRST_RING, null, false, 63, 14, -59); - buildPiece(STRUCTURE_PIECE_SECOND_RING, null, false, 55, 11, -67); - buildPiece(STRUCTURE_PIECE_THIRD_RING, null, false, 47, 13, -76); + buildFirstRing(); + buildSecondRing(); + buildThirdRing(); } default -> { - buildPiece(STRUCTURE_PIECE_FIRST_RING, null, false, 63, 14, -59); + buildFirstRing(); } } isRenderActive = false; } + private void destroyFirstRing() { + buildPiece(STRUCTURE_PIECE_FIRST_RING_AIR, null, false, 63, 14, -59); + } + + private void destroySecondRing() { + buildPiece(STRUCTURE_PIECE_SECOND_RING_AIR, null, false, 55, 11, -67); + } + + private void destroyThirdRing() { + buildPiece(STRUCTURE_PIECE_THIRD_RING_AIR, null, false, 47, 13, -76); + } + + private void buildFirstRing() { + buildPiece(STRUCTURE_PIECE_FIRST_RING, null, false, 63, 14, -59); + } + + private void buildSecondRing() { + buildPiece(STRUCTURE_PIECE_SECOND_RING, null, false, 55, 11, -67); + } + + private void buildThirdRing() { + buildPiece(STRUCTURE_PIECE_THIRD_RING, null, false, 47, 13, -76); + } + + @Override + public final void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (!debugMode) return; + if (isRenderActive) { + destroyRenderer(); + isRenderActive = false; + } else { + ringAmount = 3; + createRenderer(); + isRenderActive = true; + } + } + @Override public void onBlockDestroyed() { super.onBlockDestroyed(); - destroyRenderer(); + if (isRenderActive) { + destroyRenderer(); + } } @Override @@ -673,6 +764,7 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, buildContext.addSyncedWindow(INDIVIDUAL_MILESTONE_WINDOW_ID, this::createIndividualMilestoneWindow); buildContext.addSyncedWindow(MANUAL_INSERTION_WINDOW_ID, this::createManualInsertionWindow); buildContext.addSyncedWindow(GENERAL_INFO_WINDOW_ID, this::createGeneralInfoWindow); + buildContext.addSyncedWindow(SPECIAL_THANKS_WINDOW_ID, this::createSpecialThanksWindow); builder.widget( new ButtonWidget().setOnClick( (clickData, widget) -> { @@ -765,6 +857,17 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, .setSize(18, 18) .addTooltip(translateToLocal("gt.blockmachines.multimachine.FOG.clickhere")) .setPos(172, 67) + .setTooltipShowUpDelay(TOOLTIP_DELAY)) + .widget( + new ButtonWidget().setOnClick( + (clickData, widget) -> { + if (!widget.isClient()) widget.getContext() + .openSyncedWindow(SPECIAL_THANKS_WINDOW_ID); + }) + .setSize(16, 16) + .addTooltip(translateToLocal("fog.button.thanks.tooltip")) + .setBackground(TecTechUITextures.OVERLAY_BUTTON_HEART) + .setPos(8, 69) .setTooltipShowUpDelay(TOOLTIP_DELAY)); } @@ -1277,6 +1380,11 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, return new ButtonWidget().setOnClick((clickData, widget) -> { currentMilestoneID = milestoneID; if (!widget.isClient()) { + if (widget.getContext() + .isWindowOpen(INDIVIDUAL_MILESTONE_WINDOW_ID)) { + widget.getContext() + .closeWindow(INDIVIDUAL_MILESTONE_WINDOW_ID); + } widget.getContext() .openSyncedWindow(INDIVIDUAL_MILESTONE_WINDOW_ID); } @@ -1297,11 +1405,11 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, private int currentColorCode = 0; private int currentMilestoneBG = 0; private int gravitonShardCost = 0; - private int[] prereqUpgrades = new int[] {}; + private int[][] prereqUpgrades = new int[31][]; private int[] followupUpgrades = new int[] {}; - private boolean allPrereqRequired = false; private boolean isUpradeSplitStart = false; private boolean doesCurrentUpgradeRequireExtraMats = false; + private boolean[] allPrereqRequired = new boolean[31]; private boolean[] upgrades = new boolean[31]; private boolean[] materialPaidUpgrades = new boolean[7]; @@ -1310,6 +1418,44 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, final int PARENT_WIDTH = 300; final int PARENT_HEIGHT = 300; ModularWindow.Builder builder = ModularWindow.builder(PARENT_WIDTH, PARENT_HEIGHT); + + scrollable.widget(createUpgradeConnectorLine(new Pos2d(143, 71), 45, 0, 0, 0, 1)) + .widget(createUpgradeConnectorLine(new Pos2d(124, 124), 60, 27, 0, 1, 2)) + .widget(createUpgradeConnectorLine(new Pos2d(162, 124), 60, 333, 0, 1, 3)) + .widget(createUpgradeConnectorLine(new Pos2d(94, 184), 60, 27, 0, 2, 4)) + .widget(createUpgradeConnectorLine(new Pos2d(130, 184), 60, 336, 0, 2, 5)) + .widget(createUpgradeConnectorLine(new Pos2d(156, 184), 60, 24, 0, 3, 5)) + .widget(createUpgradeConnectorLine(new Pos2d(192, 184), 60, 333, 0, 3, 6)) + .widget(createUpgradeConnectorLine(new Pos2d(143, 251), 45, 0, 0, 5, 7)) + .widget(createUpgradeConnectorLine(new Pos2d(143, 311), 45, 0, 0, 7, 9)) + .widget(createUpgradeConnectorLine(new Pos2d(78, 250), 110, 5, 4, 4, 8)) + .widget(createUpgradeConnectorLine(new Pos2d(110, 290), 80, 40, 4, 7, 8)) + .widget(createUpgradeConnectorLine(new Pos2d(208, 250), 110, 355, 4, 6, 10)) + .widget(createUpgradeConnectorLine(new Pos2d(176, 290), 80, 320, 4, 7, 10)) + .widget(createUpgradeConnectorLine(new Pos2d(100, 355), 80, 313, 0, 8, 11)) + .widget(createUpgradeConnectorLine(new Pos2d(186, 355), 80, 47, 0, 10, 11)) + .widget(createUpgradeConnectorLine(new Pos2d(143, 430), 48, 0, 2, 11, 13)) + .widget(createUpgradeConnectorLine(new Pos2d(143, 490), 48, 0, 2, 13, 18)) + .widget(createUpgradeConnectorLine(new Pos2d(143, 550), 48, 0, 2, 18, 21)) + .widget(createUpgradeConnectorLine(new Pos2d(143, 610), 48, 0, 2, 21, 23)) + .widget(createUpgradeConnectorLine(new Pos2d(110, 410), 80, 40, 1, 11, 12)) + .widget(createUpgradeConnectorLine(new Pos2d(83, 490), 48, 0, 1, 12, 17)) + .widget(createUpgradeConnectorLine(new Pos2d(83, 550), 48, 0, 1, 17, 20)) + .widget(createUpgradeConnectorLine(new Pos2d(101, 590), 80, 320, 1, 20, 23)) + .widget(createUpgradeConnectorLine(new Pos2d(53, 536), 35, 45, 1, 17, 16)) + .widget(createUpgradeConnectorLine(new Pos2d(176, 410), 80, 320, 3, 11, 14)) + .widget(createUpgradeConnectorLine(new Pos2d(203, 490), 48, 0, 3, 14, 19)) + .widget(createUpgradeConnectorLine(new Pos2d(203, 550), 48, 0, 3, 19, 22)) + .widget(createUpgradeConnectorLine(new Pos2d(185, 590), 80, 40, 3, 22, 23)) + .widget(createUpgradeConnectorLine(new Pos2d(233, 476), 35, 315, 3, 14, 15)) + .widget(createUpgradeConnectorLine(new Pos2d(143, 670), 48, 0, 0, 23, 24)) + .widget(createUpgradeConnectorLine(new Pos2d(101, 707), 75, 62.3f, 0, 24, 25)) + .widget(createUpgradeConnectorLine(new Pos2d(53, 772), 78, 0, 0, 25, 26)) + .widget(createUpgradeConnectorLine(new Pos2d(95, 837), 75, 297.7f, 0, 26, 27)) + .widget(createUpgradeConnectorLine(new Pos2d(191, 837), 75, 62.3f, 0, 27, 28)) + .widget(createUpgradeConnectorLine(new Pos2d(233, 772), 78, 0, 0, 28, 29)) + .widget(createUpgradeConnectorLine(new Pos2d(191, 747), 75, 62.3f, 0, 29, 30)); + scrollable .widget( createUpgradeBox( @@ -1725,6 +1871,14 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, .setPos(4, 4)) .widget( ButtonWidget.closeWindowButton(true) + .setOnClick((data, widget) -> { + if (!widget.isClient()) { + widget.getWindow() + .closeWindow(); + widget.getContext() + .closeWindow(INDIVIDUAL_UPGRADE_WINDOW_ID); + } + }) .setPos(282, 4)); if (debugMode) { builder.widget(new MultiChildWidget().addChild(new ButtonWidget().setOnClick((clickData, widget) -> { @@ -1881,10 +2035,9 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, .widget(new MultiChildWidget().addChild(new ButtonWidget().setOnClick((clickData, widget) -> { int unlockedPrereqUpgrades = 0; - int unlockedFollowupUpgrades = 0; int unlockedSplitUpgrades = 0; if (!upgrades[currentUpgradeID]) { - for (int prereqUpgrade : prereqUpgrades) { + for (int prereqUpgrade : prereqUpgrades[currentUpgradeID]) { if (upgrades[prereqUpgrade]) { unlockedPrereqUpgrades++; } @@ -1892,14 +2045,14 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, if (!doesCurrentUpgradeRequireExtraMats || materialPaidUpgrades[Arrays.asList(UPGRADE_MATERIAL_ID_CONVERSION) .indexOf(currentUpgradeID)]) { - if (allPrereqRequired) { - if (unlockedPrereqUpgrades == prereqUpgrades.length + if (allPrereqRequired[currentUpgradeID]) { + if (unlockedPrereqUpgrades == prereqUpgrades[currentUpgradeID].length && gravitonShardsAvailable >= gravitonShardCost) { gravitonShardsAvailable -= gravitonShardCost; gravitonShardsSpent += gravitonShardCost; upgrades[currentUpgradeID] = true; } - } else if (unlockedPrereqUpgrades > 0 || prereqUpgrades.length == 0) { + } else if (unlockedPrereqUpgrades > 0 || prereqUpgrades[currentUpgradeID].length == 0) { if (isUpradeSplitStart) { for (int splitUpgrade : FIRST_SPLIT_UPGRADES) { if (upgrades[splitUpgrade]) { @@ -1916,11 +2069,34 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, } } } else { + int unlockedFollowupUpgrades = 0; + int unlockedNeighboringUpgrades = 0; + boolean doesFollowupRequireAllPrereqs = false; + boolean canFollowupSpareAConnection = true; + for (int followupUpgrade : followupUpgrades) { if (upgrades[followupUpgrade]) { unlockedFollowupUpgrades++; } + if (allPrereqRequired[followupUpgrade]) { + doesFollowupRequireAllPrereqs = true; + } + int[] currentPrereqs = prereqUpgrades[followupUpgrade]; + for (int prereqUpgrade : currentPrereqs) { + if (upgrades[prereqUpgrade]) { + unlockedNeighboringUpgrades++; + } + } + if (unlockedNeighboringUpgrades <= 1) { + canFollowupSpareAConnection = false; + } + unlockedNeighboringUpgrades = 0; } + + if (!doesFollowupRequireAllPrereqs && followupUpgrades.length > 0 && canFollowupSpareAConnection) { + unlockedFollowupUpgrades = 0; + } + if (unlockedFollowupUpgrades == 0) { gravitonShardsAvailable += gravitonShardCost; gravitonShardsSpent -= gravitonShardCost; @@ -1936,10 +2112,11 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, return new IDrawable[] { GTUITextures.BUTTON_STANDARD }; } }) - .addTooltip(translateToLocal("fog.upgrade.confirm")) + .dynamicTooltip(this::constructionStatus) .setTooltipShowUpDelay(TOOLTIP_DELAY)) .addChild( - new TextWidget(translateToLocal("fog.upgrade.confirm")).setTextAlignment(Alignment.Center) + TextWidget.dynamicText(this::constructionStatusText) + .setTextAlignment(Alignment.Center) .setScale(0.7f) .setMaxWidth(36) .setPos(3, 5)) @@ -2006,18 +2183,27 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, private Widget createUpgradeBox(int upgradeID, int colorCode, int milestone, int[] prerequisiteUpgradeIDs, boolean requireAllPrerequisites, int[] followingUpgradeIDs, boolean isStartOfSplit, boolean requiresExtraMaterials, int shardCost, Pos2d pos, IWidgetBuilder builder) { + prereqUpgrades[upgradeID] = prerequisiteUpgradeIDs; + allPrereqRequired[upgradeID] = requireAllPrerequisites; return new MultiChildWidget().addChild(new ButtonWidget().setOnClick((clickData, widget) -> { currentUpgradeID = upgradeID; currentColorCode = colorCode; currentMilestoneBG = milestone; gravitonShardCost = shardCost; - prereqUpgrades = prerequisiteUpgradeIDs; - allPrereqRequired = requireAllPrerequisites; followupUpgrades = followingUpgradeIDs; isUpradeSplitStart = isStartOfSplit; doesCurrentUpgradeRequireExtraMats = requiresExtraMaterials; - if (!widget.isClient()) widget.getContext() - .openSyncedWindow(INDIVIDUAL_UPGRADE_WINDOW_ID); + if (!widget.isClient()) { + // unfortunately this is the easiest way to prevent this window desyncing. it causes the window to + // reposition itself on the screen which would be a good thing to not do. + if (widget.getContext() + .isWindowOpen(INDIVIDUAL_UPGRADE_WINDOW_ID)) { + widget.getContext() + .closeWindow(INDIVIDUAL_UPGRADE_WINDOW_ID); + } + widget.getContext() + .openSyncedWindow(INDIVIDUAL_UPGRADE_WINDOW_ID); + } }) .setSize(40, 15) .setBackground(() -> { @@ -2041,6 +2227,44 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, builder); } + private Widget createUpgradeConnectorLine(Pos2d pos, int length, float rotationAngle, int colorCode, + int startUpgradeID, int endUpgradeID) { + return new DrawableWidget() + .setDrawable( + () -> (upgrades[startUpgradeID] && upgrades[endUpgradeID]) + ? coloredLine(colorCode, true).withRotationDegree(rotationAngle) + : coloredLine(colorCode, false).withRotationDegree(rotationAngle)) + .setPos(pos) + .setSize(6, length); + } + + private IDrawable coloredLine(int colorCode, boolean opaque) { + IDrawable line; + switch (colorCode) { + case 1 -> { + line = opaque ? TecTechUITextures.PICTURE_UPGRADE_CONNECTOR_PURPLE_OPAQUE + : TecTechUITextures.PICTURE_UPGRADE_CONNECTOR_PURPLE; + } + case 2 -> { + line = opaque ? TecTechUITextures.PICTURE_UPGRADE_CONNECTOR_ORANGE_OPAQUE + : TecTechUITextures.PICTURE_UPGRADE_CONNECTOR_ORANGE; + } + case 3 -> { + line = opaque ? TecTechUITextures.PICTURE_UPGRADE_CONNECTOR_GREEN_OPAQUE + : TecTechUITextures.PICTURE_UPGRADE_CONNECTOR_GREEN; + } + case 4 -> { + line = opaque ? TecTechUITextures.PICTURE_UPGRADE_CONNECTOR_RED_OPAQUE + : TecTechUITextures.PICTURE_UPGRADE_CONNECTOR_RED; + } + default -> { + line = opaque ? TecTechUITextures.PICTURE_UPGRADE_CONNECTOR_BLUE_OPAQUE + : TecTechUITextures.PICTURE_UPGRADE_CONNECTOR_BLUE; + } + } + return line; + } + protected ModularWindow createManualInsertionWindow(final EntityPlayer player) { ItemStack[] inputs = godforgeUpgradeMats.get(currentUpgradeID); final int WIDTH = 189; @@ -2121,25 +2345,26 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, .setPos(5, 82) .setSize(179, 16)); + IItemHandlerModifiable upgradeMatsHandler = new ItemStackHandler(12); int uniqueItems = inputs.length; for (int i = 0; i < 12; i++) { int index = i; int cleanDiv4 = index / 4; if (i < uniqueItems) { + ItemStack stack = inputs[index]; + if (stack != null) { + stack = stack.copy(); + stack.stackSize = 1; + upgradeMatsHandler.setStackInSlot(index, stack); + } builder.widget( new DrawableWidget().setDrawable(GTUITextures.BUTTON_STANDARD_PRESSED) .setPos(5 + cleanDiv4 * 36, 6 + index % 4 * 18) .setSize(18, 18)); columnList.get(cleanDiv4) .addChild( - new ItemDrawable().setItem(inputs[index]) - .asWidget() - .dynamicTooltip(() -> { - List tooltip = new ArrayList<>(); - tooltip.add(inputs[index] != null ? inputs[index].getDisplayName() : ""); - return tooltip; - }) - .setSize(16, 16)); + new SlotWidget(upgradeMatsHandler, index).setAccess(false, false) + .disableInteraction()); columnList.get(cleanDiv4 + 3) .addChild( new TextWidget("x" + inputs[i].stackSize).setTextAlignment(Alignment.CenterLeft) @@ -2155,9 +2380,9 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, int counter = 0; for (DynamicPositionedColumn column : columnList) { - int spacing = 2; - int xCord = 1 + counter * 36; - int yCord = 1; + int spacing = 0; + int xCord = counter * 36; + int yCord = 0; if (counter > 2) { spacing = 10; xCord = 19 + (counter - 3) * 36; @@ -2336,6 +2561,137 @@ public class MTEForgeOfGods extends TTMultiblockBase implements IConstructable, return builder.build(); } + protected ModularWindow createSpecialThanksWindow(final EntityPlayer player) { + final int WIDTH = 200; + final int HEIGHT = 200; + ModularWindow.Builder builder = ModularWindow.builder(WIDTH, HEIGHT); + + builder.setBackground(TecTechUITextures.BACKGROUND_GLOW_RAINBOW); + builder.setDraggable(true); + builder.widget( + ButtonWidget.closeWindowButton(true) + .setPos(184, 4)) + .widget( + new DrawableWidget().setDrawable(TecTechUITextures.PICTURE_GODFORGE_THANKS) + .setPos(50, 50) + .setSize(100, 100)) + .widget( + new TextWidget(translateToLocal("gt.blockmachines.multimachine.FOG.contributors")) + .setDefaultColor(EnumChatFormatting.GOLD) + .setTextAlignment(Alignment.Center) + .setScale(1f) + .setPos(0, 5) + .setSize(200, 15)) + .widget( + new TextWidget( + EnumChatFormatting.UNDERLINE + translateToLocal("gt.blockmachines.multimachine.FOG.lead")) + .setScale(0.8f) + .setDefaultColor(EnumChatFormatting.GOLD) + .setTextAlignment(Alignment.CenterLeft) + .setPos(7, 30) + .setSize(60, 10)) + .widget( + new TextWidget(translateToLocal("gt.blockmachines.multimachine.FOG.cloud")).setScale(0.8f) + .setDefaultColor(EnumChatFormatting.AQUA) + .setTextAlignment(Alignment.CenterLeft) + .setPos(7, 40) + .setSize(60, 10)) + .widget( + new TextWidget( + EnumChatFormatting.UNDERLINE + translateToLocal("gt.blockmachines.multimachine.FOG.programming")) + .setScale(0.8f) + .setDefaultColor(EnumChatFormatting.GOLD) + .setTextAlignment(Alignment.CenterLeft) + .setPos(7, 55) + .setSize(60, 10)) + .widget( + new TextWidget( + EnumChatFormatting.DARK_AQUA + translateToLocal("gt.blockmachines.multimac