Skip to content

Commit

Permalink
Less juggling of byte where side enum is preferred
Browse files Browse the repository at this point in the history
  • Loading branch information
basdxz committed Jan 4, 2025
1 parent d0b8bd3 commit 4a92f54
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package gregtech.api.interfaces.tileentity;

import gregtech.api.interfaces.ITexture;
import net.minecraftforge.common.util.ForgeDirection;

public interface IPipeRenderedTileEntity extends ICoverable, ITexturedTileEntity {
float getThickNess();

byte getConnections();

ITexture[] getTextureUncovered(byte aSide);
ITexture[] getTextureUncovered(ForgeDirection side);

default ITexture[] getTextureCovered(byte aSide) {
return getTextureUncovered(aSide);
default ITexture[] getTextureCovered(ForgeDirection side) {
return getTextureUncovered(side);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import gregtech.api.interfaces.ITexture;
import net.minecraft.block.Block;
import net.minecraftforge.common.util.ForgeDirection;

public interface ITexturedTileEntity {
/**
* @return the Textures rendered by the GT IconRenderer
*/
ITexture[] getTexture(Block aBlock, byte aSide);
ITexture[] getTexture(Block block, ForgeDirection side);
}
20 changes: 10 additions & 10 deletions src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -823,16 +823,16 @@ public long getSteamCapacity() {
}

@Override
public ITexture[] getTexture(Block aBlock, byte aSide) {
ITexture rIcon = getCoverTexture(aSide);
public ITexture[] getTexture(Block block, ForgeDirection side) {
ITexture rIcon = getCoverTexture((byte) side.ordinal());
if (rIcon != null) return new ITexture[]{rIcon};
return getTextureUncovered(aSide);
return getTextureUncovered(side);
}

@Override
public ITexture[] getTextureCovered(byte aSide) {
ITexture coverTexture = getCoverTexture(aSide);
ITexture[] textureUncovered = getTextureUncovered(aSide);
public ITexture[] getTextureCovered(ForgeDirection side) {
ITexture coverTexture = getCoverTexture((byte) side.ordinal());
ITexture[] textureUncovered = getTextureUncovered(side);
ITexture[] textureCovered;
if (coverTexture != null) {
textureCovered = Arrays.copyOf(textureUncovered, textureUncovered.length + 1);
Expand All @@ -844,7 +844,7 @@ public ITexture[] getTextureCovered(byte aSide) {
}

@Override
public ITexture[] getTextureUncovered(byte aSide) {
public ITexture[] getTextureUncovered(ForgeDirection side) {
if ((mConnections & IConnectable.HAS_FRESHFOAM) != 0) return Textures.BlockIcons.FRESHFOAM;
if ((mConnections & IConnectable.HAS_HARDENEDFOAM) != 0) return Textures.BlockIcons.HARDENEDFOAMS[mColor];
if ((mConnections & IConnectable.HAS_FOAM) != 0) return Textures.BlockIcons.ERROR_RENDERING;
Expand All @@ -853,9 +853,9 @@ public ITexture[] getTextureUncovered(byte aSide) {
else if (tConnections == IConnectable.CONNECTED_DOWN || tConnections == IConnectable.CONNECTED_UP) tConnections = (byte) (IConnectable.CONNECTED_DOWN | IConnectable.CONNECTED_UP);
else if (tConnections == IConnectable.CONNECTED_NORTH || tConnections == IConnectable.CONNECTED_SOUTH) tConnections = (byte) (IConnectable.CONNECTED_NORTH | IConnectable.CONNECTED_SOUTH);
if (hasValidMetaTileEntity())
return mMetaTileEntity.getTexture(this, aSide, tConnections, (byte) (mColor - 1),
tConnections == 0 || (tConnections & (1 << aSide)) != 0,
getOutputRedstoneSignal(aSide) > 0);
return mMetaTileEntity.getTexture(this, (byte) side.ordinal(), tConnections, (byte) (mColor - 1),
tConnections == 0 || (tConnections & (1 << side.ordinal())) != 0,
getOutputRedstoneSignal((byte) side.ordinal()) > 0);
return Textures.BlockIcons.ERROR_RENDERING;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,10 +1252,10 @@ public long getSteamCapacity() {
}

@Override
public ITexture[] getTexture(Block aBlock, byte aSide) {
ITexture coverTexture = getCoverTexture(aSide);
public ITexture[] getTexture(Block block, ForgeDirection side) {
ITexture coverTexture = getCoverTexture((byte) side.ordinal());
ITexture[] textureUncovered = hasValidMetaTileEntity() ?
mMetaTileEntity.getTexture(this, aSide, mFacing, (byte) (mColor - 1), mActive, getOutputRedstoneSignal(aSide) > 0) :
mMetaTileEntity.getTexture(this, (byte)side.ordinal(), mFacing, (byte) (mColor - 1), mActive, getOutputRedstoneSignal((byte) side.ordinal()) > 0) :
Textures.BlockIcons.ERROR_RENDERING;
ITexture[] textureCovered;
if (coverTexture != null) {
Expand Down
44 changes: 26 additions & 18 deletions src/main/java/gregtech/common/render/GT_Renderer_Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ public static boolean renderStandardBlock(IBlockAccess world, int posX, int posY
val te = world.getTileEntity(posX, posY, posZ);
if ((te instanceof IPipeRenderedTileEntity pipeTile)) {
return renderStandardBlock(world, posX, posY, posZ, block, renderBlocks, new ITexture[][]{
pipeTile.getTextureCovered((byte) DOWN.ordinal()),
pipeTile.getTextureCovered((byte) UP.ordinal()),
pipeTile.getTextureCovered((byte) NORTH.ordinal()),
pipeTile.getTextureCovered((byte) SOUTH.ordinal()),
pipeTile.getTextureCovered((byte) WEST.ordinal()),
pipeTile.getTextureCovered((byte) EAST.ordinal())});
pipeTile.getTextureCovered(DOWN),
pipeTile.getTextureCovered(UP),
pipeTile.getTextureCovered(NORTH),
pipeTile.getTextureCovered(SOUTH),
pipeTile.getTextureCovered(WEST),
pipeTile.getTextureCovered(EAST)});
}
if (te instanceof ITexturedTileEntity texturedTile) {
return renderStandardBlock(world, posX, posY, posZ, block, renderBlocks, new ITexture[][]{
texturedTile.getTexture(block, (byte) DOWN.ordinal()),
texturedTile.getTexture(block, (byte) UP.ordinal()),
texturedTile.getTexture(block, (byte) NORTH.ordinal()),
texturedTile.getTexture(block, (byte) SOUTH.ordinal()),
texturedTile.getTexture(block, (byte) WEST.ordinal()),
texturedTile.getTexture(block, (byte) EAST.ordinal())});
texturedTile.getTexture(block, DOWN),
texturedTile.getTexture(block, UP),
texturedTile.getTexture(block, NORTH),
texturedTile.getTexture(block, SOUTH),
texturedTile.getTexture(block, WEST),
texturedTile.getTexture(block, EAST)});
}
return false;
}
Expand Down Expand Up @@ -119,12 +119,20 @@ public static boolean renderPipeBlock(IBlockAccess aWorld, int aX, int aY, int a
tIsCovered[i] = (aTileEntity.getCoverIDAtSide((byte) i) != 0);
}

final ITexture[][] tIcons = new ITexture[VALID_DIRECTIONS.length][];
final ITexture[][] tCovers = new ITexture[VALID_DIRECTIONS.length][];
for (int i = 0; i < VALID_DIRECTIONS.length; i++) {
tCovers[i] = aTileEntity.getTexture(aBlock, (byte) i);
tIcons[i] = aTileEntity.getTextureUncovered((byte) i);
}
final ITexture[][] tIcons = new ITexture[][]{
aTileEntity.getTextureUncovered(DOWN),
aTileEntity.getTextureUncovered(UP),
aTileEntity.getTextureUncovered(NORTH),
aTileEntity.getTextureUncovered(SOUTH),
aTileEntity.getTextureUncovered(WEST),
aTileEntity.getTextureUncovered(EAST)};
final ITexture[][] tCovers = new ITexture[][]{
aTileEntity.getTexture(aBlock, DOWN),
aTileEntity.getTexture(aBlock, UP),
aTileEntity.getTexture(aBlock, NORTH),
aTileEntity.getTexture(aBlock, SOUTH),
aTileEntity.getTexture(aBlock, WEST),
aTileEntity.getTexture(aBlock, EAST)};

switch (aConnections) {
case NO_CONNECTION:
Expand Down

0 comments on commit 4a92f54

Please sign in to comment.