diff options
3 files changed, 86 insertions, 59 deletions
diff --git a/src/main/java/com/github/technus/tectech/thing/block/RenderEyeOfHarmony.java b/src/main/java/com/github/technus/tectech/thing/block/RenderEyeOfHarmony.java index 24a4360a88..1e7f9f363c 100644 --- a/src/main/java/com/github/technus/tectech/thing/block/RenderEyeOfHarmony.java +++ b/src/main/java/com/github/technus/tectech/thing/block/RenderEyeOfHarmony.java @@ -14,7 +14,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.AdvancedModelLoader; import net.minecraftforge.client.model.IModelCustom; import org.lwjgl.opengl.GL11; -import pers.gwyog.gtneioreplugin.plugin.block.ModBlocks; public class RenderEyeOfHarmony extends TileEntitySpecialRenderer { @@ -35,63 +34,47 @@ public class RenderEyeOfHarmony extends TileEntitySpecialRenderer { TileEyeOfHarmony EOHRenderTile = (TileEyeOfHarmony) tile; + // Render outer space layer. + { GL11.glPushMatrix(); GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5); + renderOuterSpaceShell(); - if (EOHRenderTile.getOrbitingBody() != null) { - renderOrbitObjects(EOHRenderTile); - } + renderOrbitObjects(EOHRenderTile); // Render star stuff. renderStarLayer(EOHRenderTile, 0, starLayer0, 1.0f); renderStarLayer(EOHRenderTile, 1, starLayer1, 0.4f); renderStarLayer(EOHRenderTile, 2, starLayer2, 0.2f); - // Render outer space layer. - renderOuterSpaceShell(); GL11.glPopMatrix(); } } - public class OrbitingObject { - public OrbitingObject(float rotationSpeed, float orbitSpeed, float xAngle, float zAngle, float scale) { - this.rotationSpeed = rotationSpeed; - this.orbitSpeed = orbitSpeed; - this.xAngle = xAngle; - this.zAngle = zAngle; - this.scale = scale; - } + private void renderOrbitObjects(final TileEyeOfHarmony EOHRenderTile) { - public final float rotationSpeed; - public final float orbitSpeed; - public final float xAngle; - public final float zAngle; - public final float scale; - } + if (EOHRenderTile.getOrbitingObjects() != null) { // Bad stuff! - private void renderOrbitObjects(final TileEyeOfHarmony EOHRenderTile) { + if (EOHRenderTile.getOrbitingObjects().size() == 0) { + EOHRenderTile.generateImportantInfo(); + } - switch ((int) EOHRenderTile.getTier()) { - case 0: - renderOrbit(ModBlocks.getBlock("Ow"), EOHRenderTile, new OrbitingObject(1.0f, 1.0f, -4, 3, 0.4f)); - case 1: - case 2: - case 8: - case 9: - renderOrbit(ModBlocks.getBlock("DD"), EOHRenderTile, new OrbitingObject(1.0f, 1.0f, 90, 45, 0.4f)); + for (TileEyeOfHarmony.OrbitingObject t : EOHRenderTile.getOrbitingObjects()) { + renderOrbit(EOHRenderTile, t); + } } } - void renderOrbit(final Block block, final TileEyeOfHarmony EOHRenderTile, final OrbitingObject orbitingObject) { + void renderOrbit(final TileEyeOfHarmony EOHRenderTile, final TileEyeOfHarmony.OrbitingObject orbitingObject) { // Render orbiting body. GL11.glPushMatrix(); GL11.glRotatef(orbitingObject.zAngle, 0, 0, 1); GL11.glRotatef(orbitingObject.xAngle, 1, 0, 0); GL11.glRotatef((orbitingObject.rotationSpeed * 0.1f * EOHRenderTile.angle) % 360.0f, 0F, 1F, 0F); - GL11.glTranslated(- 1 - EOHRenderTile.getSize(), 0,0); + GL11.glTranslated(- 0.2 - orbitingObject.distance - starRescale * EOHRenderTile.getSize(), 0,0); GL11.glRotatef((orbitingObject.orbitSpeed * 0.1f * EOHRenderTile.angle) % 360.0f, 0F, 1F, 0F); - renderBlockInWorld(block, 0, orbitingObject.scale); + renderBlockInWorld(orbitingObject.block, 0, orbitingObject.scale); GL11.glPopMatrix(); } @@ -126,6 +109,8 @@ public class RenderEyeOfHarmony extends TileEntitySpecialRenderer { } + private static final float starRescale = 0.2f; + private void renderStarLayer(TileEyeOfHarmony EOHRenderTile, int layer, ResourceLocation texture, float alpha) { // Begin animation. @@ -147,7 +132,7 @@ public class RenderEyeOfHarmony extends TileEntitySpecialRenderer { // 0.01f magic number to shrink sphere obj down. // Size obtained from the multis current recipe. - float scale = 0.01f * EOHRenderTile.getSize(); + float scale = 0.01f * starRescale * EOHRenderTile.getSize(); // Put each subsequent layer further out. scale *= pow(1.04f, layer); diff --git a/src/main/java/com/github/technus/tectech/thing/block/TileEyeOfHarmony.java b/src/main/java/com/github/technus/tectech/thing/block/TileEyeOfHarmony.java index 31dfc9f170..eac341b1ac 100644 --- a/src/main/java/com/github/technus/tectech/thing/block/TileEyeOfHarmony.java +++ b/src/main/java/com/github/technus/tectech/thing/block/TileEyeOfHarmony.java @@ -7,6 +7,12 @@ import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import pers.gwyog.gtneioreplugin.plugin.block.ModBlocks; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Random; +import java.util.stream.IntStream; public class TileEyeOfHarmony extends TileEntity { @@ -27,16 +33,24 @@ public class TileEyeOfHarmony extends TileEntity { private float size = 1; private float rotationSpeed = 0; - public Block getOrbitingBody() { - return orbitingBody; + // Fun fact, these methods were entirely written by ChatGPT3... Take that as you will. + public static <T> ArrayList<T> selectNRandomElements(Collection<T> inputList, long n) { + ArrayList<T> randomElements = new ArrayList<>((int) n); + ArrayList<T> inputArray = new ArrayList<>(inputList); + Random rand = new Random(); + IntStream.range(0, (int) n).forEach(i -> { + int randomIndex = rand.nextInt(inputArray.size()); + randomElements.add(inputArray.get(randomIndex)); + inputArray.remove(randomIndex); + }); + return randomElements; } - public void setOrbitingBody(Block orbitingBody) { - this.orbitingBody = orbitingBody; + public static float generateRandomFloat(float a, float b) { + Random rand = new Random(); + return rand.nextFloat() * (b - a) + a; } - private Block orbitingBody; - public long getTier() { return tier; } @@ -68,15 +82,56 @@ public class TileEyeOfHarmony extends TileEntity { angle += 10.0f; } - public float angle; + public class OrbitingObject { + public OrbitingObject(Block block, float distance, float rotationSpeed, float orbitSpeed, float xAngle, float zAngle, float scale) { + this.block = block; + this.distance = distance; + this.rotationSpeed = rotationSpeed; + this.orbitSpeed = orbitSpeed; + this.xAngle = xAngle; + this.zAngle = zAngle; + this.scale = scale; + } + + public final Block block; + public final float distance; + public final float rotationSpeed; + public final float orbitSpeed; + public final float xAngle; + public final float zAngle; + public final float scale; + } + + public ArrayList<OrbitingObject> getOrbitingObjects() { + return orbitingObjects; + } + + private final ArrayList<OrbitingObject> orbitingObjects = new ArrayList<>(); + + private final static float maxAngle = 30; + + // This must be set last. + public void generateImportantInfo() { + int index = 0; + for (Block block : selectNRandomElements(ModBlocks.blocks.values(), tier)) { + + float xAngle = generateRandomFloat(-maxAngle, maxAngle); + float zAngle = generateRandomFloat(-maxAngle ,maxAngle); + index += 1.0; + float distance = index + generateRandomFloat(-0.2f, 0.2f); + float scale = generateRandomFloat(0.2f, 0.9f); + float rotationSpeed = generateRandomFloat(0.5f, 1.5f); + float orbitSpeed = generateRandomFloat(0.5f, 1.5f); + orbitingObjects.add(new OrbitingObject(block, distance, rotationSpeed, orbitSpeed, xAngle, zAngle, scale)); + } + + } + + public float angle; private static final String EOHNBTTag = "EOH:"; private static final String rotationSpeedNBTTag = EOHNBTTag + "rotationSpeed"; private static final String sizeNBTTag = EOHNBTTag + "size"; - private static final String sizeRedNBTTag = EOHNBTTag + "red"; - private static final String sizeGreenNBTTag = EOHNBTTag + "green"; - private static final String sizeBlueNBTTag = EOHNBTTag + "blue"; - private static final String orbitingBodyIDNBTTag = EOHNBTTag + "orbitingBodyID"; private static final String tierNBTTag = EOHNBTTag + "tier"; @Override @@ -87,11 +142,6 @@ public class TileEyeOfHarmony extends TileEntity { compound.setFloat(rotationSpeedNBTTag, rotationSpeed); compound.setFloat(sizeNBTTag, size); compound.setLong(tierNBTTag, tier); - - if (orbitingBody != null) { - int blockID = Block.getIdFromBlock(orbitingBody); - compound.setInteger(orbitingBodyIDNBTTag, blockID); - } } @Override @@ -102,11 +152,6 @@ public class TileEyeOfHarmony extends TileEntity { rotationSpeed = compound.getFloat(rotationSpeedNBTTag); size = compound.getFloat(sizeNBTTag); tier = compound.getLong(tierNBTTag); - - if (compound.hasKey(orbitingBodyIDNBTTag)) { - int blockID = compound.getInteger(orbitingBodyIDNBTTag); - orbitingBody = Block.getBlockById(blockID); - } } @Override diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java index bbc7de8d6c..0963d95959 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java @@ -1786,6 +1786,8 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl this.getBaseMetaTileEntity().getWorld().getTileEntity((int) (x + xOffset), (int) (y + yOffset), (int) (z + zOffset)); + rendererTileEntity.setTier(currentRecipe.getRocketTier()); + int recipeSpacetimeTier = (int) currentRecipe.getSpacetimeCasingTierRequired(); // Star is a larger size depending on the spacetime tier of the recipe. @@ -1794,11 +1796,6 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl // Star rotates faster the higher tier time dilation you use in the multi. // Lower value = faster rotation speed. rendererTileEntity.setRotationSpeed((1 + timeAccelerationFieldMetadata) / 2.0f); - - // Set recipe spacetime tier for usage elsewhere. - rendererTileEntity.setTier(currentRecipe.getRocketTier()); - rendererTileEntity.setOrbitingBody( - Block.getBlockFromItem(currentRecipe.getRecipeTriggerItem().getItem())); } private double successChance; |