diff options
| author | GDCloud <93287602+GDCloudstrike@users.noreply.github.com> | 2024-09-15 19:38:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-15 19:38:40 +0200 |
| commit | dda786c0183f6655a4a264edf2d75688e7fe895e (patch) | |
| tree | d818890893be86d0b61f1fa17605896640999089 /src/main/java/tectech/thing/block | |
| parent | 6d4894f688c9ae1fdd5c8cee1cd8f0d204220ff9 (diff) | |
| download | GT5-Unofficial-dda786c0183f6655a4a264edf2d75688e7fe895e.tar.gz GT5-Unofficial-dda786c0183f6655a4a264edf2d75688e7fe895e.tar.bz2 GT5-Unofficial-dda786c0183f6655a4a264edf2d75688e7fe895e.zip | |
Godforge finale (#3080)
Co-authored-by: BucketBrigade <138534411+CookieBrigade@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: serenibyss <10861407+serenibyss@users.noreply.github.com>
Diffstat (limited to 'src/main/java/tectech/thing/block')
| -rw-r--r-- | src/main/java/tectech/thing/block/RenderForgeOfGods.java | 421 | ||||
| -rw-r--r-- | src/main/java/tectech/thing/block/TileEntityForgeOfGods.java | 176 |
2 files changed, 550 insertions, 47 deletions
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); + } } |
