aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/render
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/common/render')
-rw-r--r--src/main/java/gregtech/common/render/GT_CopiedCTMBlockTexture.java128
-rw-r--r--src/main/java/gregtech/common/render/GT_TextureBuilder.java39
2 files changed, 166 insertions, 1 deletions
diff --git a/src/main/java/gregtech/common/render/GT_CopiedCTMBlockTexture.java b/src/main/java/gregtech/common/render/GT_CopiedCTMBlockTexture.java
new file mode 100644
index 0000000000..fc83e4b687
--- /dev/null
+++ b/src/main/java/gregtech/common/render/GT_CopiedCTMBlockTexture.java
@@ -0,0 +1,128 @@
+package gregtech.common.render;
+
+import gregtech.api.interfaces.IBlockContainer;
+import gregtech.api.interfaces.ITexture;
+import gregtech.api.util.GT_RenderingWorld;
+import gregtech.api.util.LightingHelper;
+import net.minecraft.block.Block;
+import net.minecraft.client.renderer.RenderBlocks;
+import net.minecraft.util.IIcon;
+import net.minecraftforge.common.util.ForgeDirection;
+
+class GT_CopiedCTMBlockTexture implements ITexture, IBlockContainer {
+ private final Block mBlock;
+ private final byte mSide, mMeta;
+
+ GT_CopiedCTMBlockTexture(Block aBlock, int aSide, int aMeta, short[] aRGBa, boolean allowAlpha) {
+ if (aRGBa.length != 4) throw new IllegalArgumentException("RGBa doesn't have 4 Values @ GT_CopiedCTMBlockTexture");
+ mBlock = aBlock;
+ mSide = (byte) aSide;
+ mMeta = (byte) aMeta;
+ }
+
+ private IIcon getIcon(int aSide, int aX, int aY, int aZ, RenderBlocks aRenderer) {
+ int tSide = mSide == 6 ? aSide : mSide;
+ return mBlock.getIcon(getBlockAccess(aRenderer), aX, aY, aZ, tSide);
+ }
+
+ private GT_RenderingWorld getBlockAccess(RenderBlocks aRenderer) {
+ return GT_RenderingWorld.getInstance(aRenderer.blockAccess);
+ }
+
+ @Override
+ public void renderXPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
+ IIcon aIcon = getIcon(ForgeDirection.EAST.ordinal(), aX, aY, aZ, aRenderer);
+ aRenderer.field_152631_f = true;
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //startDrawingQuads(aRenderer, 1.0f, 0.0f, 0.0f);
+ new LightingHelper(aRenderer)
+ .setupLightingXPos(aBlock, aX, aY, aZ)
+ .setupColor(ForgeDirection.EAST.ordinal(), mBlock.colorMultiplier(getBlockAccess(aRenderer), aX, aY, aZ));
+ aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, aIcon);
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //draw(aRenderer);
+ aRenderer.field_152631_f = false;
+ }
+
+ @Override
+ public void renderXNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //startDrawingQuads(aRenderer, -1.0f, 0.0f, 0.0f);
+ IIcon aIcon = getIcon(ForgeDirection.WEST.ordinal(), aX, aY, aZ, aRenderer);
+ new LightingHelper(aRenderer)
+ .setupLightingXNeg(aBlock, aX, aY, aZ)
+ .setupColor(ForgeDirection.WEST.ordinal(), mBlock.colorMultiplier(getBlockAccess(aRenderer), aX, aY, aZ));
+ aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, aIcon);
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //draw(aRenderer);
+ }
+
+ @Override
+ public void renderYPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //startDrawingQuads(aRenderer, 0.0f, 1.0f, 0.0f);
+ IIcon aIcon = getIcon(ForgeDirection.UP.ordinal(), aX, aY, aZ, aRenderer);
+ new LightingHelper(aRenderer)
+ .setupLightingYPos(aBlock, aX, aY, aZ)
+ .setupColor(ForgeDirection.UP.ordinal(), mBlock.colorMultiplier(getBlockAccess(aRenderer), aX, aY, aZ));
+ aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, aIcon);
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //draw(aRenderer);
+ }
+
+ @Override
+ public void renderYNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //startDrawingQuads(aRenderer, 0.0f, -1.0f, 0.0f);
+ IIcon aIcon = getIcon(ForgeDirection.DOWN.ordinal(), aX, aY, aZ, aRenderer);
+ new LightingHelper(aRenderer)
+ .setupLightingYNeg(aBlock, aX, aY, aZ)
+ .setupColor(ForgeDirection.DOWN.ordinal(), mBlock.colorMultiplier(getBlockAccess(aRenderer), aX, aY, aZ));
+ aRenderer.renderFaceYNeg(aBlock, aX, aY, aZ, aIcon);
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //draw(aRenderer);
+ }
+
+ @Override
+ public void renderZPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //startDrawingQuads(aRenderer, 0.0f, 0.0f, 1.0f);
+ IIcon aIcon = getIcon(ForgeDirection.SOUTH.ordinal(), aX, aY, aZ, aRenderer);
+ new LightingHelper(aRenderer)
+ .setupLightingZPos(aBlock, aX, aY, aZ)
+ .setupColor(ForgeDirection.SOUTH.ordinal(), mBlock.colorMultiplier(getBlockAccess(aRenderer), aX, aY, aZ));
+ aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, aIcon);
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //draw(aRenderer);
+ }
+
+ @Override
+ public void renderZNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //startDrawingQuads(aRenderer, 0.0f, 0.0f, -1.0f);
+ IIcon aIcon = getIcon(ForgeDirection.NORTH.ordinal(), aX, aY, aZ, aRenderer);
+ aRenderer.field_152631_f = true;
+ new LightingHelper(aRenderer)
+ .setupLightingZNeg(aBlock, aX, aY, aZ)
+ .setupColor(ForgeDirection.NORTH.ordinal(), mBlock.colorMultiplier(getBlockAccess(aRenderer), aX, aY, aZ));
+ aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, aIcon);
+ // TODO: Uncomment this once all addons have migrated to the new Texture API
+ //draw(aRenderer);
+ aRenderer.field_152631_f = false;
+ }
+
+ @Override
+ public boolean isValidTexture() {
+ return mBlock != null;
+ }
+
+ @Override
+ public Block getBlock() {
+ return mBlock;
+ }
+
+ @Override
+ public byte getMeta() {
+ return mMeta;
+ }
+}
diff --git a/src/main/java/gregtech/common/render/GT_TextureBuilder.java b/src/main/java/gregtech/common/render/GT_TextureBuilder.java
index 82bce4c8c4..f79e438dd7 100644
--- a/src/main/java/gregtech/common/render/GT_TextureBuilder.java
+++ b/src/main/java/gregtech/common/render/GT_TextureBuilder.java
@@ -1,6 +1,8 @@
package gregtech.common.render;
+import gregtech.GT_Mod;
import gregtech.api.enums.Dyes;
+import gregtech.api.enums.GT_Values;
import gregtech.api.interfaces.IIconContainer;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.ITextureBuilder;
@@ -23,6 +25,7 @@ public class GT_TextureBuilder implements ITextureBuilder {
private boolean stdOrient;
private boolean extFacing;
private boolean glow;
+ private Boolean worldCoord = null;
public GT_TextureBuilder() {
textureLayers = new ArrayList<>();
@@ -78,6 +81,20 @@ public class GT_TextureBuilder implements ITextureBuilder {
}
@Override
+ public ITextureBuilder useWorldCoord() {
+ if (fromBlock == null) throw new IllegalStateException("no from block");
+ this.worldCoord = true;
+ return this;
+ }
+
+ @Override
+ public ITextureBuilder noWorldCoord() {
+ if (fromBlock == null) throw new IllegalStateException("no from block");
+ this.worldCoord = false;
+ return this;
+ }
+
+ @Override
public ITextureBuilder extFacing() {
this.extFacing = true;
return this;
@@ -91,7 +108,12 @@ public class GT_TextureBuilder implements ITextureBuilder {
@Override
public ITexture build() {
- if (fromBlock != null) return new GT_CopiedBlockTexture(fromBlock, fromSide.ordinal(), fromMeta, rgba, allowAlpha);
+ if (fromBlock != null) {
+ if (worldCoord == Boolean.TRUE || worldCoord == null && isCTMBlock(fromBlock, fromMeta))
+ return new GT_CopiedCTMBlockTexture(fromBlock, fromSide.ordinal(), fromMeta, rgba, allowAlpha);
+ else
+ return new GT_CopiedBlockTexture(fromBlock, fromSide.ordinal(), fromMeta, rgba, allowAlpha);
+ }
if (!textureLayers.isEmpty()) return new GT_MultiTexture(textureLayers.toArray(new ITexture[0]));
switch (iconContainerList.size()) {
case 1:
@@ -109,4 +131,19 @@ public class GT_TextureBuilder implements ITextureBuilder {
throw new IllegalStateException("Invalid sideIconContainer count");
}
}
+
+ private boolean isCTMBlock(Block fromBlock, int fromMeta) {
+ return GT_Mod.gregtechproxy.mCTMBlockCache.computeIfAbsent(fromBlock, (byte) fromMeta, GT_TextureBuilder::apply);
+ }
+
+ private static Boolean apply(Block b, Byte m) {
+ Class<?> clazz = b.getClass();
+ while (clazz != Block.class) {
+ String className = clazz.getName();
+ if (GT_Values.mCTMDisabledBlock.contains(className)) return false;
+ if (GT_Values.mCTMEnabledBlock.contains(className)) return true;
+ clazz = clazz.getSuperclass();
+ }
+ return false;
+ }
}