diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2021-06-16 16:15:18 +0800 |
---|---|---|
committer | Glease <4586901+Glease@users.noreply.github.com> | 2021-07-30 14:39:30 +0800 |
commit | 62f04c2893a66c4f80383da1a973fad4708171d4 (patch) | |
tree | e8fc2873c0fbba04c2732882826f273f53fa8f73 /src/main/java/gregtech | |
parent | b0903281c7f2688724335a0a0684f9faeb96d9fc (diff) | |
download | GT5-Unofficial-62f04c2893a66c4f80383da1a973fad4708171d4.tar.gz GT5-Unofficial-62f04c2893a66c4f80383da1a973fad4708171d4.tar.bz2 GT5-Unofficial-62f04c2893a66c4f80383da1a973fad4708171d4.zip |
draw flipped textures & flipping markers
Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech')
4 files changed, 153 insertions, 17 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java index e871146d4b..76dbca86b1 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java @@ -75,7 +75,9 @@ public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase<T extends GT_Meta if (aWrenchingSide != getBaseMetaTileEntity().getFrontFacing()) return super.onWrenchRightClick(aSide, aWrenchingSide, aPlayer, aX, aY, aZ); if (aPlayer.isSneaking()) { - toolSetFlip(null); + // we won't be allowing horizontal flips, as it can be perfectly emulated by rotating twice and flipping horizontally + // allowing an extra round of flip make it hard to draw meaningful flip markers in GT_Proxy#drawGrid + toolSetFlip(getFlip().isHorizontallyFlipped() ? Flip.NONE : Flip.HORIZONTAL); } else { toolSetRotation(null); } diff --git a/src/main/java/gregtech/common/GT_Client.java b/src/main/java/gregtech/common/GT_Client.java index 3a2fc8b50f..3578af5756 100644 --- a/src/main/java/gregtech/common/GT_Client.java +++ b/src/main/java/gregtech/common/GT_Client.java @@ -177,7 +177,7 @@ public class GT_Client extends GT_Proxy private static boolean checkedForChicken = false; - private static void drawGrid(DrawBlockHighlightEvent aEvent, boolean showCoverConnections) { + private static void drawGrid(DrawBlockHighlightEvent aEvent, boolean showCoverConnections, boolean aIsWrench, boolean aIsSneaking) { if (!checkedForChicken) { try { Class.forName("codechicken.lib.vec.Rotation"); @@ -280,25 +280,32 @@ public class GT_Client extends GT_Proxy } GL11.glEnd(); // draw turning indicator - if (tTile instanceof IGregTechTileEntity && + if (aIsWrench && tTile instanceof IGregTechTileEntity && ((IGregTechTileEntity) tTile).getMetaTileEntity() instanceof IAlignmentProvider) { IAlignment tAlignment = ((IAlignmentProvider) ((IGregTechTileEntity) tTile).getMetaTileEntity()).getAlignment(); if (tAlignment != null) { ForgeDirection direction = tAlignment.getDirection(); if (direction.ordinal() == tSideHit) - drawRotationMarker(ROTATION_MARKER_TRANSFORM_CENTER); + drawExtendedRotationMarker(ROTATION_MARKER_TRANSFORM_CENTER, aIsSneaking); else if (direction.getOpposite().ordinal() == tSideHit) { for (Transformation t : ROTATION_MARKER_TRANSFORMS_CORNER) { - drawRotationMarker(t); + drawExtendedRotationMarker(t, aIsSneaking); } } else { - drawRotationMarker(ROTATION_MARKER_TRANSFORMS_SIDES_TRANSFORMS[ROTATION_MARKER_TRANSFORMS_SIDES[tSideHit * 6 + direction.ordinal()]]); + drawExtendedRotationMarker(ROTATION_MARKER_TRANSFORMS_SIDES_TRANSFORMS[ROTATION_MARKER_TRANSFORMS_SIDES[tSideHit * 6 + direction.ordinal()]], aIsSneaking); } } } GL11.glPopMatrix(); // get back to player center } + private static void drawExtendedRotationMarker(Transformation transform, boolean sneaking) { + if (sneaking) + drawFlipMarker(transform); + else + drawRotationMarker(transform); + } + private static void drawRotationMarker(Transformation transform) { GL11.glPushMatrix(); transform.glApply(); @@ -319,6 +326,47 @@ public class GT_Client extends GT_Proxy GL11.glPopMatrix(); } + private static void drawFlipMarker(Transformation transform) { + GL11.glPushMatrix(); + transform.glApply(); + Tessellator t = Tessellator.instance; + // right shape + GL11.glLineStipple(4, (short) 0xAAAA); + GL11.glEnable(GL11.GL_LINE_STIPPLE); + t.startDrawing(GL11.GL_LINE_STRIP); + t.addVertex(0.1d, 0d, 0.04d); + t.addVertex(0.1d, 0d, 0.2d); + t.addVertex(0.35d, 0d, 0.35d); + t.addVertex(0.35d, 0d, -0.35d); + t.addVertex(0.1d, 0d, -0.2d); + t.addVertex(0.1d, 0d, -0.04d); + t.draw(); + GL11.glDisable(GL11.GL_LINE_STIPPLE); + // left shape + t.startDrawing(GL11.GL_LINE_STRIP); + t.addVertex(-0.1d, 0d, 0.04d); + t.addVertex(-0.1d, 0d, 0.2d); + t.addVertex(-0.35d, 0d, 0.35d); + t.addVertex(-0.35d, 0d, -0.35d); + t.addVertex(-0.1d, 0d, -0.2d); + t.addVertex(-0.1d, 0d, -0.04d); + t.draw(); + // arrow + t.startDrawing(GL11.GL_LINE_LOOP); + t.addVertex(0.15d, 0d, -0.04d); + t.addVertex(0.15d, 0d, -0.1d); + t.addVertex(0.25d, 0d, 0.d); + t.addVertex(0.15d, 0d, 0.1d); + t.addVertex(0.15d, 0d, 0.04d); + t.addVertex(-0.15d, 0d, 0.04d); + t.addVertex(-0.15d, 0d, 0.1d); + t.addVertex(-0.25d, 0d, 0.d); + t.addVertex(-0.15d, 0d, -0.1d); + t.addVertex(-0.15d, 0d, -0.04d); + t.draw(); + GL11.glPopMatrix(); + } + @Override public boolean isServerSide() { return true; @@ -507,7 +555,7 @@ public class GT_Client extends GT_Proxy if (GT_Utility.isStackInList(aEvent.currentItem, GregTech_API.sWrenchList)) { if (aTileEntity instanceof ITurnable || ROTATABLE_VANILLA_BLOCKS.contains(aBlock) || aTileEntity instanceof IWrenchable) - drawGrid(aEvent, false); + drawGrid(aEvent, false, true, aEvent.player.isSneaking()); return; } @@ -518,7 +566,7 @@ public class GT_Client extends GT_Proxy GT_Utility.isStackInList(aEvent.currentItem, GregTech_API.sSolderingToolList) ) { if (((ICoverable) aTileEntity).getCoverIDAtSide((byte) aEvent.target.sideHit) == 0) - drawGrid(aEvent, false); + drawGrid(aEvent, false, false, aEvent.player.isSneaking()); return; } @@ -529,7 +577,7 @@ public class GT_Client extends GT_Proxy if (((ICoverable) aTileEntity).getCoverIDAtSide((byte) aEvent.target.sideHit) == 0) for (byte i = 0; i < 6; i++) if (((ICoverable) aTileEntity).getCoverIDAtSide(i) > 0) { - drawGrid(aEvent, true); + drawGrid(aEvent, true, false, true); return; } return; @@ -538,7 +586,7 @@ public class GT_Client extends GT_Proxy if (GT_Utility.isStackInList(aEvent.currentItem, GregTech_API.sCovers.keySet())) { if (((ICoverable) aTileEntity).getCoverIDAtSide((byte) aEvent.target.sideHit) == 0) - drawGrid(aEvent, true); + drawGrid(aEvent, true, false, aEvent.player.isSneaking()); } } diff --git a/src/main/java/gregtech/common/render/GT_IconFlipped.java b/src/main/java/gregtech/common/render/GT_IconFlipped.java new file mode 100644 index 0000000000..c3eee2900f --- /dev/null +++ b/src/main/java/gregtech/common/render/GT_IconFlipped.java @@ -0,0 +1,80 @@ +package gregtech.common.render; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.util.IIcon; + +@SideOnly(Side.CLIENT) +public class GT_IconFlipped implements IIcon { + private final IIcon baseIcon; + private final boolean flipU; + private final boolean flipV; + + public GT_IconFlipped(IIcon baseIcon, boolean flipU, boolean flipV) { + this.baseIcon = baseIcon; + this.flipU = flipU; + this.flipV = flipV; + } + + /** + * Returns the width of the icon, in pixels. + */ + public int getIconWidth() { + return this.baseIcon.getIconWidth(); + } + + /** + * Returns the height of the icon, in pixels. + */ + public int getIconHeight() { + return this.baseIcon.getIconHeight(); + } + + /** + * Returns the minimum U coordinate to use when rendering with this icon. + */ + public float getMinU() { + return this.flipU ? this.baseIcon.getMaxU() : this.baseIcon.getMinU(); + } + + /** + * Returns the maximum U coordinate to use when rendering with this icon. + */ + public float getMaxU() { + return this.flipU ? this.baseIcon.getMinU() : this.baseIcon.getMaxU(); + } + + /** + * Gets a U coordinate on the icon. 0 returns uMin and 16 returns uMax. Other arguments return in-between values. + */ + public float getInterpolatedU(double p_94214_1_) { + float f = this.getMaxU() - this.getMinU(); + return this.getMinU() + f * ((float) p_94214_1_ / 16.0F); + } + + /** + * Returns the minimum V coordinate to use when rendering with this icon. + */ + public float getMinV() { + return this.flipV ? this.baseIcon.getMaxV() : this.baseIcon.getMinV(); + } + + /** + * Returns the maximum V coordinate to use when rendering with this icon. + */ + public float getMaxV() { + return this.flipV ? this.baseIcon.getMinV() : this.baseIcon.getMaxV(); + } + + /** + * Gets a V coordinate on the icon. 0 returns vMin and 16 returns vMax. Other arguments return in-between values. + */ + public float getInterpolatedV(double p_94207_1_) { + float f = this.getMaxV() - this.getMinV(); + return this.getMinV() + f * ((float) p_94207_1_ / 16.0F); + } + + public String getIconName() { + return this.baseIcon.getIconName(); + } +}
\ No newline at end of file diff --git a/src/main/java/gregtech/common/render/GT_RenderedTexture.java b/src/main/java/gregtech/common/render/GT_RenderedTexture.java index 135ebf28c6..e35e2dbb6b 100644 --- a/src/main/java/gregtech/common/render/GT_RenderedTexture.java +++ b/src/main/java/gregtech/common/render/GT_RenderedTexture.java @@ -2,6 +2,7 @@ package gregtech.common.render; import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; +import com.gtnewhorizon.structurelib.alignment.enumerable.Flip; import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation; import gregtech.GT_Mod; import gregtech.api.interfaces.IColorModulationContainer; @@ -12,7 +13,6 @@ 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; @@ -225,7 +225,8 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { break; } - aRenderer.renderFaceYNeg(Blocks.air, x, y, z, new IconFlipped(icon, !stdOrient, false)); + Flip aFlip = extendedFacing.getFlip(); + aRenderer.renderFaceYNeg(Blocks.air, x, y, z, useExtFacing ? new GT_IconFlipped(icon, aFlip.isHorizontallyFlipped() ^ !stdOrient, aFlip.isVerticallyFliped()) : icon); aRenderer.uvRotateBottom = 0; } @@ -249,7 +250,8 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { break; } - aRenderer.renderFaceYPos(Blocks.air, x, y, z, icon); + Flip aFlip = extendedFacing.getFlip(); + aRenderer.renderFaceYPos(Blocks.air, x, y, z, useExtFacing ? new GT_IconFlipped(icon, aFlip.isHorizontallyFlipped(), aFlip.isVerticallyFliped()) : icon); aRenderer.uvRotateTop = 0; } @@ -274,7 +276,8 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { break; } - aRenderer.renderFaceZNeg(Blocks.air, x, y, z, icon); + Flip aFlip = extendedFacing.getFlip(); + aRenderer.renderFaceZNeg(Blocks.air, x, y, z, useExtFacing ? new GT_IconFlipped(icon, aFlip.isHorizontallyFlipped(), aFlip.isVerticallyFliped()) : icon); aRenderer.uvRotateEast = 0; aRenderer.field_152631_f = false; } @@ -299,7 +302,8 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { break; } - aRenderer.renderFaceZPos(Blocks.air, x, y, z, icon); + Flip aFlip = extendedFacing.getFlip(); + aRenderer.renderFaceZPos(Blocks.air, x, y, z, useExtFacing ? new GT_IconFlipped(icon, aFlip.isHorizontallyFlipped(), aFlip.isVerticallyFliped()) : icon); aRenderer.uvRotateWest = 0; } @@ -323,7 +327,8 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { break; } - aRenderer.renderFaceXNeg(Blocks.air, x, y, z, icon); + Flip aFlip = extendedFacing.getFlip(); + aRenderer.renderFaceXNeg(Blocks.air, x, y, z, useExtFacing ? new GT_IconFlipped(icon, aFlip.isHorizontallyFlipped(), aFlip.isVerticallyFliped()) : icon); aRenderer.uvRotateNorth = 0; } @@ -348,7 +353,8 @@ class GT_RenderedTexture implements ITexture, IColorModulationContainer { break; } - aRenderer.renderFaceXPos(Blocks.air, x, y, z, icon); + Flip aFlip = extendedFacing.getFlip(); + aRenderer.renderFaceXPos(Blocks.air, x, y, z, useExtFacing ? new GT_IconFlipped(icon, aFlip.isHorizontallyFlipped(), aFlip.isVerticallyFliped()) : icon); aRenderer.uvRotateSouth = 0; aRenderer.field_152631_f = false; } |