From 678c9a6e1e7a3a1127c40ae5c3dda7ef4519bfb7 Mon Sep 17 00:00:00 2001 From: Léa Gris Date: Thu, 20 May 2021 22:57:12 +0200 Subject: feat(render): implementation-free api texture factory Provides an implementation-free API Texture factory an builder. Deprecates gregtech.api.objects.GT_*Texture.java classes Once all GregTech add-on will be migrated to the new implemnetation-free API, changes to the implementation will not affect the add-on. For now, this API allow rendering of in-world glow textures. In-inventory/hand rendering of glow texture require implementation changes that are postponed until no add-on uses the deprecated embedded implementation API. --- .../gregtech/api/interfaces/ITextureBuilder.java | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/main/java/gregtech/api/interfaces/ITextureBuilder.java (limited to 'src/main/java/gregtech/api/interfaces/ITextureBuilder.java') diff --git a/src/main/java/gregtech/api/interfaces/ITextureBuilder.java b/src/main/java/gregtech/api/interfaces/ITextureBuilder.java new file mode 100644 index 0000000000..fde7f2e27b --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/ITextureBuilder.java @@ -0,0 +1,72 @@ +package gregtech.api.interfaces; + +import gregtech.api.render.TextureFactory; +import net.minecraft.block.Block; +import net.minecraftforge.common.util.ForgeDirection; + +/** + *

This Interface defines operations to configure and build instances of the {@link ITexture} implementations

+ *

Use the {@link TextureFactory#builder()} method to get an instance of the {@link ITextureBuilder} implementation.

+ */ +public interface ITextureBuilder { + /** + * Build the {@link ITexture} + * + * @return The built {@link ITexture} + */ + ITexture build(); + + /** + * @param block The {@link Block} + * @param meta The meta value for the Block + * @return {@link ITextureBuilder} for chaining + */ + ITextureBuilder setFromBlock(Block block, int meta); + + /** + * @param side

The {@link ForgeDirection} side providing the texture

+ *

Default is {@link ForgeDirection#UNKNOWN} to use same side as rendered

+ * @return {@link ITextureBuilder} for chaining + */ + ITextureBuilder setFromSide(ForgeDirection side); + + /** + * @param iconContainers The {@link IIconContainer}s to add + * @return {@link ITextureBuilder} for chaining + */ + ITextureBuilder addIcon(IIconContainer... iconContainers); + + /** + * @param rgba The RGBA tint for this {@link ITexture} + * @return {@link ITextureBuilder} for chaining + */ + ITextureBuilder setRGBA(short[] rgba); + + /** + * @param iTextures The {@link ITexture} layers to add + * @return {@link ITextureBuilder} for chaining + */ + ITextureBuilder addLayer(ITexture... iTextures); + + /** + * Set alpha blending + * @param allowAlpha to set + * + * @return {@link ITextureBuilder} for chaining + */ + ITextureBuilder setAllowAlpha(boolean allowAlpha); + + /** + * Texture will render with same orientation as with vanilla blocks + * + * @return {@link ITextureBuilder} for chaining + */ + ITextureBuilder stdOrient(); + + /** + * Texture always render with full brightness to glow in the dark + * + * @return {@link ITextureBuilder} for chaining + */ + ITextureBuilder glow(); +} -- cgit From 6adfad819f014bbf86afa36fd32849d772b0efb4 Mon Sep 17 00:00:00 2001 From: Léa Gris Date: Fri, 21 May 2021 14:06:47 +0200 Subject: code layout --- .../gregtech/api/interfaces/ITextureBuilder.java | 12 +-- .../java/gregtech/api/render/TextureFactory.java | 91 +++++++++------------- .../gregtech/common/render/GT_TextureBuilder.java | 12 +-- 3 files changed, 47 insertions(+), 68 deletions(-) (limited to 'src/main/java/gregtech/api/interfaces/ITextureBuilder.java') diff --git a/src/main/java/gregtech/api/interfaces/ITextureBuilder.java b/src/main/java/gregtech/api/interfaces/ITextureBuilder.java index fde7f2e27b..8a4d715ccb 100644 --- a/src/main/java/gregtech/api/interfaces/ITextureBuilder.java +++ b/src/main/java/gregtech/api/interfaces/ITextureBuilder.java @@ -21,32 +21,32 @@ public interface ITextureBuilder { * @param meta The meta value for the Block * @return {@link ITextureBuilder} for chaining */ - ITextureBuilder setFromBlock(Block block, int meta); + ITextureBuilder setFromBlock(final Block block, final int meta); /** * @param side

The {@link ForgeDirection} side providing the texture

*

Default is {@link ForgeDirection#UNKNOWN} to use same side as rendered

* @return {@link ITextureBuilder} for chaining */ - ITextureBuilder setFromSide(ForgeDirection side); + ITextureBuilder setFromSide(final ForgeDirection side); /** * @param iconContainers The {@link IIconContainer}s to add * @return {@link ITextureBuilder} for chaining */ - ITextureBuilder addIcon(IIconContainer... iconContainers); + ITextureBuilder addIcon(final IIconContainer... iconContainers); /** * @param rgba The RGBA tint for this {@link ITexture} * @return {@link ITextureBuilder} for chaining */ - ITextureBuilder setRGBA(short[] rgba); + ITextureBuilder setRGBA(final short[] rgba); /** * @param iTextures The {@link ITexture} layers to add * @return {@link ITextureBuilder} for chaining */ - ITextureBuilder addLayer(ITexture... iTextures); + ITextureBuilder addLayer(final ITexture... iTextures); /** * Set alpha blending @@ -54,7 +54,7 @@ public interface ITextureBuilder { * * @return {@link ITextureBuilder} for chaining */ - ITextureBuilder setAllowAlpha(boolean allowAlpha); + ITextureBuilder setAllowAlpha(final boolean allowAlpha); /** * Texture will render with same orientation as with vanilla blocks diff --git a/src/main/java/gregtech/api/render/TextureFactory.java b/src/main/java/gregtech/api/render/TextureFactory.java index 8c0c46f2c6..8c67cd6740 100644 --- a/src/main/java/gregtech/api/render/TextureFactory.java +++ b/src/main/java/gregtech/api/render/TextureFactory.java @@ -8,7 +8,7 @@ import net.minecraft.block.Block; import net.minecraftforge.common.util.ForgeDirection; /** - * This class contains a collection of static factory methods to help to use the New Texture API + *

This class contains a collection of static factory methods to access the New Texture API.

*

The {@link #of} methods directly returns ready-to-use instances of {@link ITexture} implementations.

*

To get more specific implementations of {@link ITexture} instances, use the {@link #builder()} method.

*

Example of the {@link #builder()}:

@@ -24,11 +24,12 @@ import net.minecraftforge.common.util.ForgeDirection; @SuppressWarnings("unused") public final class TextureFactory { private TextureFactory() { - throw new AssertionError("Non instantiable class"); + throw new AssertionError("Non-instantiable class"); } /** * Multi-layered {@link ITexture} factory + * * @param textures The layers of {@link ITexture} from bottom to top * @return The instance of an {@link ITexture} implementation */ @@ -38,71 +39,53 @@ public final class TextureFactory { /** * All-Sided {@link ITexture} factory - * @param bottomIconContainers The {@link IIconContainer} Icon for the Bottom Side. - * @param topIconContainers The {@link IIconContainer} Icon for the Top Side. - * @param northIconContainers The {@link IIconContainer} Icon for the North Side. - * @param southIconContainers The {@link IIconContainer} Icon for the South Side. - * @param westIconContainers The {@link IIconContainer} Icon for the West Side. - * @param eastIconContainers The {@link IIconContainer} Icon for the East Side. - * @param rgba The {@code short[]} tint for all sides. + * + * @param bottom The {@link IIconContainer} Icon for the Bottom Side. + * @param top The {@link IIconContainer} Icon for the Top Side. + * @param north The {@link IIconContainer} Icon for the North Side. + * @param south The {@link IIconContainer} Icon for the South Side. + * @param west The {@link IIconContainer} Icon for the West Side. + * @param east The {@link IIconContainer} Icon for the East Side. + * @param rgba The {@code short[]} RGBA tint for all sides. * @return The instance of an {@link ITexture} implementation */ - public static ITexture of(final IIconContainer bottomIconContainers, - final IIconContainer topIconContainers, - final IIconContainer northIconContainers, - final IIconContainer southIconContainers, - final IIconContainer westIconContainers, - final IIconContainer eastIconContainers, + public static ITexture of(final IIconContainer bottom, final IIconContainer top, final IIconContainer north, + final IIconContainer south, final IIconContainer west, final IIconContainer east, final short[] rgba) { - return builder().addIcon(bottomIconContainers, - topIconContainers, - northIconContainers, - southIconContainers, - westIconContainers, - eastIconContainers) - .setRGBA(rgba) - .setAllowAlpha(true) - .build(); + return builder().addIcon(bottom, top, north, south, west, east).setRGBA(rgba).setAllowAlpha(true).build(); } /** * Bottom-Top-Sides-Sided {@link ITexture} factory - * @param aBottomIconContainers The {@link IIconContainer} Icon for the Bottom Side. - * @param aTopIconContainers The {@link IIconContainer} Icon for the Top Side. - * @param aSideIconContainers The {@link IIconContainer} Icon for the North, South, West and East Sides. - * @param rgba The {@code short[]} tint for all sides. + * + * @param bottom The {@link IIconContainer} Icon for the Bottom Side. + * @param top The {@link IIconContainer} Icon for the Top Side. + * @param sides The {@link IIconContainer} Icon for the North, South, West and East Sides. + * @param rgba The {@code short[]} RGBA tint for all sides. * @return The instance of an {@link ITexture} implementation */ - public static ITexture of(IIconContainer aBottomIconContainers, - IIconContainer aTopIconContainers, - IIconContainer aSideIconContainers, short[] rgba) { - return builder().addIcon(aBottomIconContainers, - aTopIconContainers, - aSideIconContainers, - aSideIconContainers, - aSideIconContainers, - aSideIconContainers) - .setRGBA(rgba) - .setAllowAlpha(true) - .build(); + public static ITexture of(final IIconContainer bottom, final IIconContainer top, final IIconContainer sides, + final short[] rgba) { + return builder().addIcon(bottom, top, sides, sides, sides, sides).setRGBA(rgba).setAllowAlpha(true).build(); } /** * Rendered {@link ITexture} factory + * * @param iconContainer The {@link IIconContainer} to render - * @param rgba The {@code short[]} tint for the texture. - * @param allowAlpha Determine if texture will use alpha blending (Not yet implemented) + * @param rgba The {@code short[]} RGBA tint for the texture. + * @param allowAlpha Determine if texture will use alpha blending (Not yet implemented) * @return The instance of an {@link ITexture} implementation */ - public static ITexture of(IIconContainer iconContainer, short[] rgba, boolean allowAlpha) { + public static ITexture of(final IIconContainer iconContainer, final short[] rgba, final boolean allowAlpha) { return builder().addIcon(iconContainer).setRGBA(rgba).setAllowAlpha(allowAlpha).build(); } - public static ITexture of(IIconContainer iconContainer, short[] rgba) { + public static ITexture of(final IIconContainer iconContainer, final short[] rgba) { return builder().addIcon(iconContainer).setRGBA(rgba).build(); } - public static ITexture of(IIconContainer iconContainer) { + public static ITexture of(final IIconContainer iconContainer) { return builder().addIcon(iconContainer).build(); } @@ -116,29 +99,25 @@ public final class TextureFactory { * @param rgba The RGBA tint to apply * @return The instance of an {@link ITexture} implementation */ - public static ITexture of(Block block, int meta, ForgeDirection side, short[] rgba) { - return builder().setFromBlock(block, meta) - .setFromSide(side) - .setRGBA(rgba) - .build(); + public static ITexture of(final Block block, final int meta, final ForgeDirection side, final short[] rgba) { + return builder().setFromBlock(block, meta).setFromSide(side).setRGBA(rgba).build(); } - public static ITexture of(Block block, int meta, ForgeDirection side) { - return builder().setFromBlock(block, meta) - .setFromSide(side) - .build(); + public static ITexture of(final Block block, final int meta, final ForgeDirection side) { + return builder().setFromBlock(block, meta).setFromSide(side).build(); } - public static ITexture of(Block block, int meta) { + public static ITexture of(final Block block, final int meta) { return builder().setFromBlock(block, meta).build(); } - public static ITexture of(Block block) { + public static ITexture of(final Block block) { return of(block, 0); } /** * {@link ITextureBuilder} factory + * * @return An instance of the {@link ITextureBuilder} implementation */ public static ITextureBuilder builder() { diff --git a/src/main/java/gregtech/common/render/GT_TextureBuilder.java b/src/main/java/gregtech/common/render/GT_TextureBuilder.java index 58df85123b..22446f99a5 100644 --- a/src/main/java/gregtech/common/render/GT_TextureBuilder.java +++ b/src/main/java/gregtech/common/render/GT_TextureBuilder.java @@ -33,7 +33,7 @@ public class GT_TextureBuilder implements ITextureBuilder { } @Override - public ITextureBuilder setFromBlock(Block block, int meta) { + public ITextureBuilder setFromBlock(final Block block, final int meta) { this.fromBlock = block; this.fromMeta = meta; this.fromSide = ForgeDirection.UNKNOWN; @@ -41,31 +41,31 @@ public class GT_TextureBuilder implements ITextureBuilder { } @Override - public ITextureBuilder setFromSide(ForgeDirection side) { + public ITextureBuilder setFromSide(final ForgeDirection side) { this.fromSide = side; return this; } @Override - public ITextureBuilder addIcon(IIconContainer... iconContainers) { + public ITextureBuilder addIcon(final IIconContainer... iconContainers) { this.iconContainerList.addAll(Arrays.asList(iconContainers)); return this; } @Override - public ITextureBuilder setRGBA(short[] rgba) { + public ITextureBuilder setRGBA(final short[] rgba) { this.rgba = rgba; return this; } @Override - public ITextureBuilder addLayer(ITexture... iTextures) { + public ITextureBuilder addLayer(final ITexture... iTextures) { this.textureLayers.addAll(Arrays.asList(iTextures)); return this; } @Override - public ITextureBuilder setAllowAlpha(boolean allowAlpha) { + public ITextureBuilder setAllowAlpha(final boolean allowAlpha) { this.allowAlpha = allowAlpha; return this; } -- cgit From 86f69a4300e0bdb5c9921f37c84bb446e464ec78 Mon Sep 17 00:00:00 2001 From: Léa Gris Date: Mon, 31 May 2021 10:13:56 +0200 Subject: feat(texture API): integrate ExtendedFacing rotation Add ExtendedFacing rotation to the texture API. Rotatable ExtendedFacing textures can be created with: ```java TextureFactory.builder().addIcon(IICon).extFacing().build(); ``` Improve and unify internal implementation of standard oriented and glow textures. --- src/main/java/gregtech/GT_Mod.java | 3 +- .../gregtech/api/interfaces/ITextureBuilder.java | 8 + .../java/gregtech/api/util/LightingHelper.java | 1 + .../common/render/GT_RenderedGlowTexture.java | 213 ------------ .../gregtech/common/render/GT_RenderedTexture.java | 383 +++++++++++++++------ .../common/render/GT_StdRenderedTexture.java | 36 -- .../gregtech/common/render/GT_TextureBuilder.java | 11 +- 7 files changed, 290 insertions(+), 365 deletions(-) delete mode 100644 src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java delete mode 100644 src/main/java/gregtech/common/render/GT_StdRenderedTexture.java (limited to 'src/main/java/gregtech/api/interfaces/ITextureBuilder.java') diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index d9a8d72ecd..278908b9a0 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -1,6 +1,7 @@ package gregtech; import com.google.common.base.Stopwatch; +import com.gtnewhorizon.structurelib.StructureLib; import cpw.mods.fml.common.*; import cpw.mods.fml.common.event.*; import cpw.mods.fml.common.registry.EntityRegistry; @@ -74,7 +75,7 @@ import static gregtech.api.enums.GT_Values.MOD_ID_FR; @SuppressWarnings("ALL") @Mod(modid = "gregtech", name = "GregTech", version = "MC1710", useMetadata = false, dependencies = " required-after:IC2;" + - " required-after:structurelib;" + + " required-after:" + StructureLib.MOD_ID + ";" + " after:dreamcraft;" + " after:Forestry;" + " after:PFAAGeologica;" + diff --git a/src/main/java/gregtech/api/interfaces/ITextureBuilder.java b/src/main/java/gregtech/api/interfaces/ITextureBuilder.java index 8a4d715ccb..d72b538243 100644 --- a/src/main/java/gregtech/api/interfaces/ITextureBuilder.java +++ b/src/main/java/gregtech/api/interfaces/ITextureBuilder.java @@ -1,5 +1,6 @@ package gregtech.api.interfaces; +import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; import gregtech.api.render.TextureFactory; import net.minecraft.block.Block; import net.minecraftforge.common.util.ForgeDirection; @@ -63,6 +64,13 @@ public interface ITextureBuilder { */ ITextureBuilder stdOrient(); + /** + * Texture will orientate from block's {@link ExtendedFacing} + * + * @return {@link ITextureBuilder} for chaining + */ + ITextureBuilder extFacing(); + /** * Texture always render with full brightness to glow in the dark * diff --git a/src/main/java/gregtech/api/util/LightingHelper.java b/src/main/java/gregtech/api/util/LightingHelper.java index 598253b7d7..f131ef74a0 100644 --- a/src/main/java/gregtech/api/util/LightingHelper.java +++ b/src/main/java/gregtech/api/util/LightingHelper.java @@ -255,6 +255,7 @@ public class LightingHelper { } else { + if (hasBrightnessOverride) tessellator.setBrightness(brightnessOverride); tessellator.setColorOpaque_F(rgb[0] * lightness, rgb[1] * lightness, rgb[2] * lightness); } diff --git a/src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java b/src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java deleted file mode 100644 index 899e4d7c5d..0000000000 --- a/src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java +++ /dev/null @@ -1,213 +0,0 @@ -package gregtech.common.render; - -import gregtech.GT_Mod; -import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.interfaces.IColorModulationContainer; -import gregtech.api.interfaces.IIconContainer; -import gregtech.api.interfaces.ITexture; -import net.minecraft.block.Block; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.util.IIcon; - -import static gregtech.api.util.LightingHelper.MAX_BRIGHTNESS; - -/** - * This {@link ITexture} implementation renders texture with max brightness to glow in the dark. - */ - -class GT_RenderedGlowTexture implements ITexture, IColorModulationContainer { - protected final IIconContainer mIconContainer; - private final short[] mRGBa; - - GT_RenderedGlowTexture(IIconContainer aIcon, short[] aRGBa, boolean allowAlpha) { - if (aRGBa.length != 4) throw new IllegalArgumentException("RGBa doesn't have 4 Values @ GT_RenderedTexture"); - mIconContainer = GT_Mod.gregtechproxy.mRenderGlowTextures ? aIcon : BlockIcons.VOID; - mRGBa = aRGBa; - } - - @Override - public short[] getRGBA() { - return mRGBa; - } - - @Override - public void renderXNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - final boolean enableAO = aRenderer.enableAO; - aRenderer.enableAO = false; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, -1.0f, 0.0f, 0.0f); - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - Tessellator.instance.setColorOpaque(255, 255, 255); - aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.enableAO = enableAO; - } - - @Override - public void renderXPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - aRenderer.field_152631_f = true; - final boolean enableAO = aRenderer.enableAO; - aRenderer.enableAO = false; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, 1.0f, 0.0f, 0.0f); - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - Tessellator.instance.setColorOpaque(255, 255, 255); - aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.field_152631_f = false; - aRenderer.enableAO = enableAO; - } - - @Override - public void renderYNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - final boolean enableAO = aRenderer.enableAO; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, 0.0f, -1.0f, 0.0f); - final Tessellator tessellator = Tessellator.instance; - IIcon aIcon = mIconContainer.getIcon(); - - float minU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMaxX) * 16.0D); - float maxU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMinX) * 16.0D); - float minV = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0D); - float maxV = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0D); - - if (aRenderer.renderMinX < 0.0D || aRenderer.renderMaxX > 1.0D) { - minU = 16.0F - aIcon.getMaxU(); - maxU = 16.0F - aIcon.getMinU(); - } - - if (aRenderer.renderMinZ < 0.0D || aRenderer.renderMaxZ > 1.0D) { - minV = aIcon.getMinV(); - maxV = aIcon.getMaxV(); - } - - double minX = aX + aRenderer.renderMinX; - double maxX = aX + aRenderer.renderMaxX; - double minY = aY + aRenderer.renderMinY; - double minZ = aZ + aRenderer.renderMinZ; - double maxZ = aZ + aRenderer.renderMaxZ; - - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - tessellator.addVertexWithUV(maxX, minY, maxZ, minU, maxV); - - if (mIconContainer.getOverlayIcon() != null) { - minU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMaxX) * 16.0D); - maxU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMinX) * 16.0D); - minV = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0D); - maxV = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0D); - - if (aRenderer.renderMinX < 0.0D || aRenderer.renderMaxX > 1.0D) { - minU = 16.0F - aIcon.getMaxU(); - maxU = 16.0F - aIcon.getMinU(); - } - - if (aRenderer.renderMinZ < 0.0D || aRenderer.renderMaxZ > 1.0D) { - minV = aIcon.getMinV(); - maxV = aIcon.getMaxV(); - } - - minX = aX + (float) aRenderer.renderMinX; - maxX = aX + (float) aRenderer.renderMaxX; - minY = aY + (float) aRenderer.renderMinY; - minZ = aZ + (float) aRenderer.renderMinZ; - maxZ = aZ + (float) aRenderer.renderMaxZ; - - Tessellator.instance.setColorOpaque(255, 255, 255); - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - tessellator.addVertexWithUV(maxX, minY, maxZ, minU, maxV); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.enableAO = enableAO; - } - - @Override - public void renderYPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - final boolean enableAO = aRenderer.enableAO; - aRenderer.enableAO = false; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, 0.0f, 1.0f, 0.0f); - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - Tessellator.instance.setColorOpaque(255, 255, 255); - aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.enableAO = enableAO; - } - - @Override - public void renderZNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - final boolean enableAO = aRenderer.enableAO; - aRenderer.enableAO = false; - aRenderer.field_152631_f = true; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, 0.0f, 0.0f, -1.0f); - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - Tessellator.instance.setColorOpaque(255, 255, 255); - aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.field_152631_f = false; - aRenderer.enableAO = enableAO; - } - - @Override - public void renderZPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API - if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; - final boolean enableAO = aRenderer.enableAO; - aRenderer.enableAO = false; - // TODO: Uncomment this once all addons have migrated to the new Texture API - //startDrawingQuads(aRenderer, 0.0f, 0.0f, 1.0f); - Tessellator.instance.setBrightness(MAX_BRIGHTNESS); - Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]); - aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - aRenderer.enableAO = enableAO; - } - - @Override - public boolean isValidTexture() { - return mIconContainer != null; - } -} diff --git a/src/main/java/gregtech/common/render/GT_RenderedTexture.java b/src/main/java/gregtech/common/render/GT_RenderedTexture.java index 9e76634385..135ebf28c6 100644 --- a/src/main/java/gregtech/common/render/GT_RenderedTexture.java +++ b/src/main/java/gregtech/common/render/GT_RenderedTexture.java @@ -1,55 +1,92 @@ package gregtech.common.render; +import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; +import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; +import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation; +import gregtech.GT_Mod; import gregtech.api.interfaces.IColorModulationContainer; import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.LightingHelper; import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.IconFlipped; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import static gregtech.api.util.LightingHelper.MAX_BRIGHTNESS; + class GT_RenderedTexture implements ITexture, IColorModulationContainer { protected final IIconContainer mIconContainer; private final short[] mRGBa; + private final boolean glow; + private final boolean stdOrient; + private final boolean useExtFacing; - GT_RenderedTexture(IIconContainer aIcon, short[] aRGBa, boolean allowAlpha) { + GT_RenderedTexture(IIconContainer aIcon, short[] aRGBa, boolean allowAlpha, boolean glow, boolean stdOrient, boolean extFacing) { if (aRGBa.length != 4) throw new IllegalArgumentException("RGBa doesn't have 4 Values @ GT_RenderedTexture"); mIconContainer = aIcon; mRGBa = aRGBa; + this.glow = glow; + this.stdOrient = stdOrient; + this.useExtFacing = extFacing; } @Override public void renderXPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { - 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); + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingXPos(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.EAST.ordinal(), mRGBa); - aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingXPos(aBlock, aX, aY, aZ).setupColor(ForgeDirection.EAST.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceXPos(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { lighting.setupColor(ForgeDirection.EAST.ordinal(), 0xffffff); - aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); + renderFaceXPos(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // 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); + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingXNeg(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.WEST.ordinal(), mRGBa); - aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon()); + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingXNeg(aBlock, aX, aY, aZ).setupColor(ForgeDirection.WEST.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceXNeg(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { lighting.setupColor(ForgeDirection.WEST.ordinal(), 0xffffff); - aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); + renderFaceXNeg(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // TODO: Uncomment this once all addons have migrated to the new Texture API //draw(aRenderer); } @@ -58,14 +95,24 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { 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); + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingYPos(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.UP.ordinal(), mRGBa); - aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingYPos(aBlock, aX, aY, aZ).setupColor(ForgeDirection.UP.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceYPos(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { lighting.setupColor(ForgeDirection.UP.ordinal(), 0xffffff); - aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); + renderFaceYPos(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // TODO: Uncomment this once all addons have migrated to the new Texture API //draw(aRenderer); } @@ -74,96 +121,24 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { 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); - final Tessellator tessellator = Tessellator.instance; - IIcon aIcon = mIconContainer.getIcon(); - - float minU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMaxX) * 16.0D); - float maxU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMinX) * 16.0D); - float minV = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0D); - float maxV = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0D); - - if (aRenderer.renderMinX < 0.0D || aRenderer.renderMaxX > 1.0D) { - minU = 16.0F - aIcon.getMaxU(); - maxU = 16.0F - aIcon.getMinU(); - } - - if (aRenderer.renderMinZ < 0.0D || aRenderer.renderMaxZ > 1.0D) { - minV = aIcon.getMinV(); - maxV = aIcon.getMaxV(); - } - - double minX = aX + aRenderer.renderMinX; - double maxX = aX + aRenderer.renderMaxX; - double minY = aY + aRenderer.renderMinY; - double minZ = aZ + aRenderer.renderMinZ; - double maxZ = aZ + aRenderer.renderMaxZ; - + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingYNeg(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.DOWN.ordinal(), mRGBa); - - if (aRenderer.enableAO) { - tessellator.setColorOpaque_F(aRenderer.colorRedTopLeft, aRenderer.colorGreenTopLeft, aRenderer.colorBlueTopLeft); - tessellator.setBrightness(aRenderer.brightnessTopLeft); - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.setColorOpaque_F(aRenderer.colorRedBottomLeft, aRenderer.colorGreenBottomLeft, aRenderer.colorBlueBottomLeft); - tessellator.setBrightness(aRenderer.brightnessBottomLeft); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.setColorOpaque_F(aRenderer.colorRedBottomRight, aRenderer.colorGreenBottomRight, aRenderer.colorBlueBottomRight); - tessellator.setBrightness(aRenderer.brightnessBottomRight); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - tessellator.setColorOpaque_F(aRenderer.colorRedTopRight, aRenderer.colorGreenTopRight, aRenderer.colorBlueTopRight); - tessellator.setBrightness(aRenderer.brightnessTopRight); - } else { - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - } - tessellator.addVertexWithUV(maxX, minY, maxZ, minU, maxV); - + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingYNeg(aBlock, aX, aY, aZ).setupColor(ForgeDirection.DOWN.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceYNeg(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { - minU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMaxX) * 16.0D); - maxU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMinX) * 16.0D); - minV = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0D); - maxV = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0D); - - if (aRenderer.renderMinX < 0.0D || aRenderer.renderMaxX > 1.0D) { - minU = 16.0F - aIcon.getMaxU(); - maxU = 16.0F - aIcon.getMinU(); - } - - if (aRenderer.renderMinZ < 0.0D || aRenderer.renderMaxZ > 1.0D) { - minV = aIcon.getMinV(); - maxV = aIcon.getMaxV(); - } - - minX = aX + (float)aRenderer.renderMinX; - maxX = aX + (float)aRenderer.renderMaxX; - minY = aY + (float)aRenderer.renderMinY; - minZ = aZ + (float)aRenderer.renderMinZ; - maxZ = aZ + (float)aRenderer.renderMaxZ; - - lighting.setupColor(ForgeDirection.DOWN.ordinal(), 0xffffff); - - if (aRenderer.enableAO) { - tessellator.setColorOpaque_F(aRenderer.colorRedTopLeft, aRenderer.colorGreenTopLeft, aRenderer.colorBlueTopLeft); - tessellator.setBrightness(aRenderer.brightnessTopLeft); - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.setColorOpaque_F(aRenderer.colorRedBottomLeft, aRenderer.colorGreenBottomLeft, aRenderer.colorBlueBottomLeft); - tessellator.setBrightness(aRenderer.brightnessBottomLeft); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.setColorOpaque_F(aRenderer.colorRedBottomRight, aRenderer.colorGreenBottomRight, aRenderer.colorBlueBottomRight); - tessellator.setBrightness(aRenderer.brightnessBottomRight); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - tessellator.setColorOpaque_F(aRenderer.colorRedTopRight, aRenderer.colorGreenTopRight, aRenderer.colorBlueTopRight); - tessellator.setBrightness(aRenderer.brightnessTopRight); - } else { - tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV); - tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV); - tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV); - } - tessellator.addVertexWithUV(maxX, minY, maxZ, minU, maxV); + Tessellator.instance.setColorRGBA(255, 255, 255, 255); + renderFaceYNeg(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // TODO: Uncomment this once all addons have migrated to the new Texture API //draw(aRenderer); } @@ -172,14 +147,24 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { 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); + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingZPos(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.SOUTH.ordinal(), mRGBa); - aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, mIconContainer.getIcon()); + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingZPos(aBlock, aX, aY, aZ).setupColor(ForgeDirection.SOUTH.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceZPos(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { lighting.setupColor(ForgeDirection.SOUTH.ordinal(), 0xffffff); - aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); + renderFaceZPos(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // TODO: Uncomment this once all addons have migrated to the new Texture API //draw(aRenderer); } @@ -188,18 +173,26 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { 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); - aRenderer.field_152631_f = true; + final boolean enableAO = aRenderer.enableAO; LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingZNeg(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.NORTH.ordinal(), mRGBa); - aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon()); + if (glow) { + if (aRenderer.useInventoryTint) + return; // TODO: Remove this once all addons have migrated to the new Texture API + if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return; + aRenderer.enableAO = false; + lighting.setLightnessOverride(1.0F); + if (enableAO) lighting.setBrightnessOverride(MAX_BRIGHTNESS); + } + lighting.setupLightingZNeg(aBlock, aX, aY, aZ).setupColor(ForgeDirection.NORTH.ordinal(), mRGBa); + ExtendedFacing rotation = getExtendedFacing(aX, aY, aZ); + renderFaceZNeg(aRenderer, aX, aY, aZ, mIconContainer.getIcon(), rotation); if (mIconContainer.getOverlayIcon() != null) { lighting.setupColor(ForgeDirection.NORTH.ordinal(), 0xffffff); - aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); + renderFaceZNeg(aRenderer, aX, aY, aZ, mIconContainer.getOverlayIcon(), rotation); } + aRenderer.enableAO = enableAO; // TODO: Uncomment this once all addons have migrated to the new Texture API //draw(aRenderer); - aRenderer.field_152631_f = false; } @Override @@ -211,4 +204,170 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { public boolean isValidTexture() { return mIconContainer != null; } + + /** + * Renders the given texture to the bottom face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceYNeg(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateBottom = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateBottom = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateBottom = 3; + break; + default: + aRenderer.uvRotateBottom = 0; + break; + } + + aRenderer.renderFaceYNeg(Blocks.air, x, y, z, new IconFlipped(icon, !stdOrient, false)); + aRenderer.uvRotateBottom = 0; + } + + /** + * Renders the given texture to the top face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceYPos(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateTop = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateTop = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateTop = 3; + break; + default: + aRenderer.uvRotateTop = 0; + break; + } + + aRenderer.renderFaceYPos(Blocks.air, x, y, z, icon); + aRenderer.uvRotateTop = 0; + } + + /** + * Renders the given texture to the north (z-negative) face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceZNeg(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + aRenderer.field_152631_f = true; + // **NOT A BUG**: aRenderer.uvRotateEast REALLY CONTROLS THE ROTATION OF THE NORTH SIDE + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateEast = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateEast = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateEast = 3; + break; + default: + aRenderer.uvRotateEast = 0; + break; + } + + aRenderer.renderFaceZNeg(Blocks.air, x, y, z, icon); + aRenderer.uvRotateEast = 0; + aRenderer.field_152631_f = false; + } + + /** + * Renders the given texture to the south (z-positive) face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceZPos(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + // **NOT A BUG**: aRenderer.uvRotateWest REALLY CONTROLS THE ROTATION OF THE SOUTH SIDE + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateWest = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateWest = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateWest = 3; + break; + default: + aRenderer.uvRotateWest = 0; + break; + } + + aRenderer.renderFaceZPos(Blocks.air, x, y, z, icon); + aRenderer.uvRotateWest = 0; + } + + /** + * Renders the given texture to the west (x-negative) face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceXNeg(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + // **NOT A BUG**: aRenderer.uvRotateNorth REALLY CONTROLS THE ROTATION OF THE WEST SIDE + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateNorth = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateNorth = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateNorth = 3; + break; + default: + aRenderer.uvRotateNorth = 0; + break; + } + + aRenderer.renderFaceXNeg(Blocks.air, x, y, z, icon); + aRenderer.uvRotateNorth = 0; + } + + /** + * Renders the given texture to the east (x-positive) face of the block. Args: block, x, y, z, texture + */ + protected void renderFaceXPos(RenderBlocks aRenderer, double x, double y, double z, IIcon icon, ExtendedFacing extendedFacing) { + aRenderer.field_152631_f = true; + // **NOT A BUG**: aRenderer.uvRotateSouth REALLY CONTROLS THE ROTATION OF THE EAST SIDE + switch (useExtFacing ? extendedFacing.getRotation() : Rotation.NORMAL) { + case COUNTER_CLOCKWISE: + aRenderer.uvRotateSouth = 2; + break; + case CLOCKWISE: + aRenderer.uvRotateSouth = 1; + break; + case UPSIDE_DOWN: + aRenderer.uvRotateSouth = 3; + break; + default: + aRenderer.uvRotateSouth = 0; + break; + } + + aRenderer.renderFaceXPos(Blocks.air, x, y, z, icon); + aRenderer.uvRotateSouth = 0; + aRenderer.field_152631_f = false; + } + + private ExtendedFacing getExtendedFacing(int x, int y, int z) { + if (stdOrient) return ExtendedFacing.DEFAULT; + World w = Minecraft.getMinecraft().theWorld; + if (w == null) return ExtendedFacing.DEFAULT; + TileEntity te = w.getTileEntity(x, y, z); + if (te instanceof IGregTechTileEntity) { + IMetaTileEntity meta = ((IGregTechTileEntity) te).getMetaTileEntity(); + if (meta instanceof IAlignmentProvider) { + return ((IAlignmentProvider) meta).getAlignment().getExtendedFacing(); + } else if (meta != null) { + return ExtendedFacing.of(ForgeDirection.getOrientation(meta.getBaseMetaTileEntity().getFrontFacing())); + } + } else if (te instanceof IAlignmentProvider) { + return ((IAlignmentProvider) te).getAlignment().getExtendedFacing(); + } + return ExtendedFacing.DEFAULT; + } } diff --git a/src/main/java/gregtech/common/render/GT_StdRenderedTexture.java b/src/main/java/gregtech/common/render/GT_StdRenderedTexture.java deleted file mode 100644 index ba0f9d3a91..0000000000 --- a/src/main/java/gregtech/common/render/GT_StdRenderedTexture.java +++ /dev/null @@ -1,36 +0,0 @@ -package gregtech.common.render; - -import gregtech.api.interfaces.IIconContainer; -import gregtech.api.util.LightingHelper; -import net.minecraft.block.Block; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraftforge.common.util.ForgeDirection; - -/** - * This ITexture implementation extends the GT_RenderedTexture class - * to render with bottom side flipped as with dumb blocks rendering. - * It is used in Ore blocks rendering so they better blends with dumb block ores - * from vanilla or other mods, when seen from bottom. - */ -class GT_StdRenderedTexture extends GT_RenderedTexture{ - - GT_StdRenderedTexture(IIconContainer aIcon, short[] aRGBa, boolean allowAlpha) { - super(aIcon, aRGBa, allowAlpha); - } - - @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); - LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingYNeg(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.DOWN.ordinal(), getRGBA()); - aRenderer.renderFaceYNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon()); - if (mIconContainer.getOverlayIcon() != null) { - lighting.setupColor(ForgeDirection.DOWN.ordinal(), 0xffffff); - aRenderer.renderFaceYNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon()); - } - // TODO: Uncomment this once all addons have migrated to the new Texture API - //draw(aRenderer); - } -} diff --git a/src/main/java/gregtech/common/render/GT_TextureBuilder.java b/src/main/java/gregtech/common/render/GT_TextureBuilder.java index 22446f99a5..82bce4c8c4 100644 --- a/src/main/java/gregtech/common/render/GT_TextureBuilder.java +++ b/src/main/java/gregtech/common/render/GT_TextureBuilder.java @@ -21,6 +21,7 @@ public class GT_TextureBuilder implements ITextureBuilder { private short[] rgba; private boolean allowAlpha; private boolean stdOrient; + private boolean extFacing; private boolean glow; public GT_TextureBuilder() { @@ -76,6 +77,12 @@ public class GT_TextureBuilder implements ITextureBuilder { return this; } + @Override + public ITextureBuilder extFacing() { + this.extFacing = true; + return this; + } + @Override public ITextureBuilder glow() { glow = true; @@ -88,9 +95,7 @@ public class GT_TextureBuilder implements ITextureBuilder { if (!textureLayers.isEmpty()) return new GT_MultiTexture(textureLayers.toArray(new ITexture[0])); switch (iconContainerList.size()) { case 1: - if (stdOrient) return new GT_StdRenderedTexture(iconContainerList.get(0), rgba, allowAlpha); - if (glow) return new GT_RenderedGlowTexture(iconContainerList.get(0), rgba, allowAlpha); - return new GT_RenderedTexture(iconContainerList.get(0), rgba, allowAlpha); + return new GT_RenderedTexture(iconContainerList.get(0), rgba, allowAlpha, glow, stdOrient, extFacing); case 6: return new GT_SidedTexture( iconContainerList.get(ForgeDirection.DOWN.ordinal()), -- cgit