diff options
Diffstat (limited to 'src/main/java/tectech/util')
-rw-r--r-- | src/main/java/tectech/util/FaceCulledRenderBlocks.java | 62 | ||||
-rw-r--r-- | src/main/java/tectech/util/FaceVisibility.java | 12 | ||||
-rw-r--r-- | src/main/java/tectech/util/GodforgeMath.java | 13 | ||||
-rw-r--r-- | src/main/java/tectech/util/StructureVBO.java | 114 | ||||
-rw-r--r-- | src/main/java/tectech/util/TextureUpdateRequester.java | 38 |
5 files changed, 232 insertions, 7 deletions
diff --git a/src/main/java/tectech/util/FaceCulledRenderBlocks.java b/src/main/java/tectech/util/FaceCulledRenderBlocks.java new file mode 100644 index 0000000000..468ac527a0 --- /dev/null +++ b/src/main/java/tectech/util/FaceCulledRenderBlocks.java @@ -0,0 +1,62 @@ +package tectech.util; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; + +public class FaceCulledRenderBlocks extends RenderBlocks { + + FaceVisibility faceVisibility; + + public FaceCulledRenderBlocks(IBlockAccess world) { + super(world); + } + + public void setFaceVisibility(FaceVisibility faceVisibility) { + this.faceVisibility = faceVisibility; + } + + @Override + public void renderFaceYNeg(Block block, double x, double y, double z, IIcon icon) { + if (this.faceVisibility.bottom) { + super.renderFaceYNeg(block, 0, 0, 0, icon); + } + } + + @Override + public void renderFaceYPos(Block block, double x, double y, double z, IIcon icon) { + if (this.faceVisibility.top) { + super.renderFaceYPos(block, 0, 0, 0, icon); + } + } + + @Override + public void renderFaceZNeg(Block block, double x, double y, double z, IIcon icon) { + if (this.faceVisibility.back) { + super.renderFaceZNeg(block, 0, 0, 0, icon); + } + } + + @Override + public void renderFaceZPos(Block block, double x, double y, double z, IIcon icon) { + if (this.faceVisibility.front) { + super.renderFaceZPos(block, 0, 0, 0, icon); + } + } + + @Override + public void renderFaceXNeg(Block block, double x, double y, double z, IIcon icon) { + if (this.faceVisibility.left) { + super.renderFaceXNeg(block, 0, 0, 0, icon); + } + } + + @Override + public void renderFaceXPos(Block block, double x, double y, double z, IIcon icon) { + if (this.faceVisibility.right) { + super.renderFaceXPos(block, 0, 0, 0, icon); + } + } + +} diff --git a/src/main/java/tectech/util/FaceVisibility.java b/src/main/java/tectech/util/FaceVisibility.java new file mode 100644 index 0000000000..da981a98d8 --- /dev/null +++ b/src/main/java/tectech/util/FaceVisibility.java @@ -0,0 +1,12 @@ +package tectech.util; + +public class FaceVisibility { + + public boolean front = true, back = true; + public boolean left = true, right = true; + public boolean top = true, bottom = true; + + public boolean isEntireObscured() { + return !front && !back && !left && !right && !top && !bottom; + } +} diff --git a/src/main/java/tectech/util/GodforgeMath.java b/src/main/java/tectech/util/GodforgeMath.java index c11a71be02..a3105e08a1 100644 --- a/src/main/java/tectech/util/GodforgeMath.java +++ b/src/main/java/tectech/util/GodforgeMath.java @@ -138,7 +138,7 @@ public class GodforgeMath { baseParallel = 384; } if (module instanceof MTEExoticModule) { - baseParallel = 36; + baseParallel = 64; } if (module instanceof MTEMoltenModule @@ -178,19 +178,18 @@ public class GodforgeMath { } } - int maxParallel = (int) (baseParallel * node53 - * fuelFactorMultiplier - * heatMultiplier - * upgradeAmountMultiplier); + float totalBonuses = node53 * fuelFactorMultiplier * heatMultiplier * upgradeAmountMultiplier; if (module instanceof MTEExoticModule) { if (godforge.isUpgradeActive(25)) { - maxParallel = (int) Math.max(9 * Math.floor(Math.sqrt(maxParallel) / 9), 36); + totalBonuses = (float) Math.sqrt(totalBonuses); } else { - maxParallel = baseParallel; + totalBonuses = 1; } } + int maxParallel = (int) (baseParallel * totalBonuses); + module.setMaxParallel(maxParallel); } diff --git a/src/main/java/tectech/util/StructureVBO.java b/src/main/java/tectech/util/StructureVBO.java new file mode 100644 index 0000000000..1e1206d4c9 --- /dev/null +++ b/src/main/java/tectech/util/StructureVBO.java @@ -0,0 +1,114 @@ +package tectech.util; + +import java.util.HashMap; +import java.util.HashSet; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.init.Blocks; + +import org.apache.commons.lang3.tuple.Pair; + +import com.gtnewhorizon.gtnhlib.client.renderer.CapturingTessellator; +import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager; +import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VertexBuffer; +import com.gtnewhorizon.gtnhlib.client.renderer.vertex.DefaultVertexFormat; + +public class StructureVBO { + + private String[][] structure; + + private HashSet<Character> values = new HashSet<>(); + private HashMap<Character, Pair<Block, Integer>> mapper = new HashMap<>(); + + public StructureVBO assignStructure(String[][] structure) { + this.structure = structure; + return this; + } + + public StructureVBO addMapping(char letter, Block block) { + mapper.put(letter, Pair.of(block, 0)); + return this; + } + + public StructureVBO addMapping(char letter, Block block, int meta) { + mapper.put(letter, Pair.of(block, meta)); + return this; + } + + public TextureUpdateRequester getTextureUpdateRequestor() { + TextureUpdateRequester textureUpdateRequester = new TextureUpdateRequester(); + for (char key : mapper.keySet()) { + Pair<Block, Integer> pair = mapper.get(key); + textureUpdateRequester.add(pair.getLeft(), pair.getRight()); + } + return textureUpdateRequester; + } + + private boolean isOpaqueAt(int x, int y, int z) { + char letter = structure[x][y].charAt(z); + if (letter == ' ') return false; + Pair<Block, Integer> info = mapper.get(letter); + if (info == null) return false; + if (info.getLeft() == Blocks.air) return false; + return info.getLeft() + .isOpaqueCube(); + } + + private FaceVisibility getVisibleFaces(int x, int y, int z) { + FaceVisibility visibility = new FaceVisibility(); + int maxX = structure.length - 1; + int maxY = structure[0].length - 1; + int maxZ = structure[0][0].length() - 1; + // X is ordered from left to right + if ((x > 0) && (isOpaqueAt(x - 1, y, z))) visibility.left = false; + if ((x < maxX) && (isOpaqueAt(x + 1, y, z))) visibility.right = false; + // Y is ordered from top to bottom + if ((y > 0) && (isOpaqueAt(x, y - 1, z))) visibility.top = false; + if ((y < maxY) && (isOpaqueAt(x, y + 1, z))) visibility.bottom = false; + // Z is ordered from front to back + if ((z > 0) && (isOpaqueAt(x, y, z - 1))) visibility.back = false; + if ((z < maxZ) && (isOpaqueAt(x, y, z + 1))) visibility.front = false; + return visibility; + } + + public VertexBuffer build() { + TessellatorManager.startCapturing(); + CapturingTessellator tess = (CapturingTessellator) TessellatorManager.get(); + FaceCulledRenderBlocks renderer = new FaceCulledRenderBlocks(Minecraft.getMinecraft().theWorld); + renderer.enableAO = false; + + for (int x = 0; x < structure.length; x++) { + String[] plane = structure[x]; + for (int y = 0; y < plane.length; y++) { + String row = plane[y]; + for (int z = 0; z < row.length(); z++) { + char letter = row.charAt(z); + if (letter == ' ') continue; + Pair<Block, Integer> info = mapper.get(letter); + if (info == null) { + values.add(letter); + continue; + } + if (info.getLeft() == Blocks.air) continue; + + FaceVisibility faceInfo = getVisibleFaces(x, y, z); + + if (faceInfo.isEntireObscured()) continue; + + renderer.setFaceVisibility(faceInfo); + + // The floor division is intended to produce proper offsets + tess.setTranslation( + -structure.length / 2f + x, + plane.length / 2f - y, // y needs to be drawn from top to bottom + -row.length() / 2f + z); + + renderer.renderBlockAsItem(info.getLeft(), info.getRight(), 1f); + } + } + } + + return TessellatorManager.stopCapturingToVBO(DefaultVertexFormat.POSITION_TEXTURE_NORMAL); + } +} diff --git a/src/main/java/tectech/util/TextureUpdateRequester.java b/src/main/java/tectech/util/TextureUpdateRequester.java new file mode 100644 index 0000000000..250686686f --- /dev/null +++ b/src/main/java/tectech/util/TextureUpdateRequester.java @@ -0,0 +1,38 @@ +package tectech.util; + +import java.util.HashSet; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; + +import org.apache.commons.lang3.tuple.Pair; +import org.lwjgl.opengl.GL11; + +import com.gtnewhorizon.gtnhlib.client.renderer.CapturingTessellator; +import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager; +import com.gtnewhorizon.gtnhlib.client.renderer.vertex.DefaultVertexFormat; + +// Ugly hack to wake up angelica/hodgepodge to update the texture by fake rendering out a block +public class TextureUpdateRequester { + + private final HashSet<Pair<Block, Integer>> blocks = new HashSet<>(); + + public void add(Block block, int meta) { + blocks.add(Pair.of(block, meta)); + } + + // Using capturing tesselator just to make sure we dont render anything out + public void requestUpdate() { + GL11.glPushMatrix(); + TessellatorManager.startCapturing(); + CapturingTessellator tess = (CapturingTessellator) TessellatorManager.get(); + FaceCulledRenderBlocks renderer = new FaceCulledRenderBlocks(Minecraft.getMinecraft().theWorld); + renderer.setFaceVisibility(new FaceVisibility()); + for (Pair<Block, Integer> block : blocks) { + renderer.renderBlockAsItem(block.getLeft(), block.getRight(), 1f); + } + tess.setTranslation(0, 0, 0); + TessellatorManager.stopCapturingToBuffer(DefaultVertexFormat.POSITION_TEXTURE_NORMAL); + GL11.glPopMatrix(); + } +} |