Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rendering): UV Mapping on tiles #1587

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;

import static gregtech.api.enums.GT_Values.V;

public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredMachineBlock {
private static final int OUTPUT_INDEX = 0;
private static final int ARROW_RIGHT_INDEX = 1;
private static final int ARROW_DOWN_INDEX = 2;
private static final int ARROW_LEFT_INDEX = 3;
private static final int ARROW_UP_INDEX = 4;
private static final int FRONT_INDEX = 5;

public boolean bOutput = false, bRedstoneIfFull = false, bInvert = false;
public int mSuccess = 0, mTargetStackSize = 0;

Expand All @@ -33,74 +41,85 @@ public GT_MetaTileEntity_Buffer(String aName, int aTier, int aInvSlotCount, Stri

@Override
public ITexture[][][] getTextureSet(ITexture[] aTextures) {
ITexture[][][] rTextures = new ITexture[6][17][];
ITexture tIcon = getOverlayIcon(), tOut = new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT), tUp = new GT_RenderedTexture(Textures.BlockIcons.ARROW_UP), tDown = new GT_RenderedTexture(Textures.BlockIcons.ARROW_DOWN), tLeft = new GT_RenderedTexture(Textures.BlockIcons.ARROW_LEFT), tRight = new GT_RenderedTexture(Textures.BlockIcons.ARROW_RIGHT);
for (byte i = -1; i < 16; i++) {
rTextures[0][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], tOut};
rTextures[1][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], tRight, tIcon};
rTextures[2][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], tDown, tIcon};
rTextures[3][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], tLeft, tIcon};
rTextures[4][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], tUp, tIcon};
rTextures[5][i + 1] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i + 1], tIcon};
ITexture[][][] rTextures = new ITexture[ForgeDirection.VALID_DIRECTIONS.length][17][];
ITexture tIcon = getOverlayIcon();
ITexture tOut = new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_PIPE_OUT);
ITexture tUp = new GT_RenderedTexture(Textures.BlockIcons.ARROW_UP);
ITexture tDown = new GT_RenderedTexture(Textures.BlockIcons.ARROW_DOWN);
ITexture tLeft = new GT_RenderedTexture(Textures.BlockIcons.ARROW_LEFT);
ITexture tRight = new GT_RenderedTexture(Textures.BlockIcons.ARROW_RIGHT);
for (int i = 0; i < rTextures[0].length; i++) {
rTextures[OUTPUT_INDEX][i] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i], tOut};
rTextures[ARROW_RIGHT_INDEX][i] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i], tRight, tIcon};
rTextures[ARROW_DOWN_INDEX][i] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i], tDown, tIcon};
rTextures[ARROW_LEFT_INDEX][i] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i], tLeft, tIcon};
rTextures[ARROW_UP_INDEX][i] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i], tUp, tIcon};
rTextures[FRONT_INDEX][i] = new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][i], tIcon};
}
return rTextures;
}

@Override
public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) {
if (aSide == aFacing) return mTextures[5][aColorIndex + 1];
if (GT_Utility.getOppositeSide(aSide) == aFacing) return mTextures[0][aColorIndex + 1];
switch (aFacing) {
case 0:
return mTextures[4][aColorIndex + 1];
case 1:
return mTextures[2][aColorIndex + 1];
case 2:
switch (aSide) {
case 0:
return mTextures[2][aColorIndex + 1];
case 1:
return mTextures[2][aColorIndex + 1];
case 4:
return mTextures[1][aColorIndex + 1];
case 5:
return mTextures[3][aColorIndex + 1];
int colorIndex = aColorIndex + 1;
ForgeDirection side = ForgeDirection.VALID_DIRECTIONS[aSide];
ForgeDirection facing = ForgeDirection.VALID_DIRECTIONS[aFacing];
if (side == facing) return mTextures[FRONT_INDEX][colorIndex];
if (ForgeDirection.OPPOSITES[aSide] == aFacing) return mTextures[OUTPUT_INDEX][colorIndex];
switch (facing) {
case DOWN:
return mTextures[ARROW_UP_INDEX][colorIndex]; // ARROW_UP
case UP:
return mTextures[ARROW_DOWN_INDEX][colorIndex]; // ARROW_DOWN
case NORTH:
switch (side) {
case DOWN:
case UP:
return mTextures[ARROW_DOWN_INDEX][colorIndex]; // ARROW_DOWN
case WEST:
return mTextures[ARROW_RIGHT_INDEX][colorIndex]; // ARROW_RIGHT
case EAST:
return mTextures[ARROW_LEFT_INDEX][colorIndex]; // ARROW_LEFT
default:
}
case 3:
switch (aSide) {
case 0:
return mTextures[4][aColorIndex + 1];
case 1:
return mTextures[4][aColorIndex + 1];
case 4:
return mTextures[3][aColorIndex + 1];
case 5:
return mTextures[1][aColorIndex + 1];
break;
case SOUTH:
switch (side) {
case DOWN:
case UP:
return mTextures[ARROW_UP_INDEX][colorIndex]; // ARROW_UP
case WEST:
return mTextures[ARROW_LEFT_INDEX][colorIndex]; // ARROW_LEFT
case EAST:
return mTextures[ARROW_RIGHT_INDEX][colorIndex]; // ARROW_RIGHT
default:
}
case 4:
switch (aSide) {
case 0:
return mTextures[3][aColorIndex + 1];
case 1:
return mTextures[1][aColorIndex + 1];
case 2:
return mTextures[3][aColorIndex + 1];
case 3:
return mTextures[1][aColorIndex + 1];
break;
case WEST:
switch (side) {
case DOWN:
case UP:
case SOUTH:
return mTextures[ARROW_RIGHT_INDEX][colorIndex]; // ARROW_RIGHT
case NORTH:
return mTextures[ARROW_LEFT_INDEX][colorIndex]; // ARROW_LEFT
default:
}
case 5:
switch (aSide) {
case 0:
return mTextures[1][aColorIndex + 1];
case 1:
return mTextures[3][aColorIndex + 1];
case 2:
return mTextures[1][aColorIndex + 1];
case 3:
return mTextures[3][aColorIndex + 1];
break;
case EAST:
switch (side) {
case DOWN:
case UP:
case SOUTH:
return mTextures[ARROW_LEFT_INDEX][colorIndex]; // ARROW_LEFT
case NORTH:
return mTextures[ARROW_RIGHT_INDEX][colorIndex]; // ARROW_RIGHT
default:
}
break;
default:
}
return mTextures[5][aColorIndex + 1];
return mTextures[FRONT_INDEX][colorIndex];
}

@Override
Expand Down
104 changes: 67 additions & 37 deletions src/main/java/gregtech/api/objects/GT_RenderedTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,94 +37,124 @@ public GT_RenderedTexture(IIconContainer aIcon) {

@Override
public void renderXPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
Tessellator.instance.setColorRGBA((int) (mRGBa[0] * 0.6F), (int) (mRGBa[1] * 0.6F), (int) (mRGBa[2] * 0.6F), mAllowAlpha ? 255 - mRGBa[3] : 255);
final Tessellator tesselator = Tessellator.instance;
tesselator.setColorRGBA((int) (mRGBa[0] * 0.6F), (int) (mRGBa[1] * 0.6F), (int) (mRGBa[2] * 0.6F), mAllowAlpha ? 255 - mRGBa[3] : 255);
aRenderer.field_152631_f = true;
aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getIcon());
if (mIconContainer.getOverlayIcon() != null) {
Tessellator.instance.setColorRGBA(153, 153, 153, 255);
tesselator.setColorRGBA(153, 153, 153, 255);
aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon());
}
aRenderer.field_152631_f = false;
}


@Override
public void renderXNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
Tessellator.instance.setColorRGBA((int) (mRGBa[0] * 0.6F), (int) (mRGBa[1] * 0.6F), (int) (mRGBa[2] * 0.6F), mAllowAlpha ? 255 - mRGBa[3] : 255);
final Tessellator tesselator = Tessellator.instance;
tesselator.setColorRGBA((int) (mRGBa[0] * 0.6F), (int) (mRGBa[1] * 0.6F), (int) (mRGBa[2] * 0.6F), mAllowAlpha ? 255 - mRGBa[3] : 255);
aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon());
if (mIconContainer.getOverlayIcon() != null) {
Tessellator.instance.setColorRGBA(153, 153, 153, 255);
tesselator.setColorRGBA(153, 153, 153, 255);
aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon());
}
}

@Override
public void renderYPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
Tessellator.instance.setColorRGBA((int) (mRGBa[0] * 1.0F), (int) (mRGBa[1] * 1.0F), (int) (mRGBa[2] * 1.0F), mAllowAlpha ? 255 - mRGBa[3] : 255);
final Tessellator tesselator = Tessellator.instance;
tesselator.setColorRGBA((int) (mRGBa[0] * 1.0F), (int) (mRGBa[1] * 1.0F), (int) (mRGBa[2] * 1.0F), mAllowAlpha ? 255 - mRGBa[3] : 255);
aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, mIconContainer.getIcon());
if (mIconContainer.getOverlayIcon() != null) {
Tessellator.instance.setColorRGBA(255, 255, 255, 255);
tesselator.setColorRGBA(255, 255, 255, 255);
aRenderer.renderFaceYPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon());
}
}

@Override
public void renderYNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
Tessellator.instance.setColorRGBA((int) (mRGBa[0] * 0.5F), (int) (mRGBa[1] * 0.5F), (int) (mRGBa[2] * 0.5F), mAllowAlpha ? 255 - mRGBa[3] : 255);
final Tessellator tessellator = Tessellator.instance;
tessellator.setColorRGBA((int) (mRGBa[0] * 0.5F), (int) (mRGBa[1] * 0.5F), (int) (mRGBa[2] * 0.5F), mAllowAlpha ? 255 - mRGBa[3] : 255);
IIcon aIcon = mIconContainer.getIcon();

float d_16 = 16.0F;
float d3 = (float)aIcon.getInterpolatedU(aRenderer.renderMaxX * d_16);
float d4 = (float)aIcon.getInterpolatedU(aRenderer.renderMinX * d_16);
float d5 = (float)aIcon.getInterpolatedV(aRenderer.renderMinZ * d_16);
float d6 = (float)aIcon.getInterpolatedV(aRenderer.renderMaxZ * d_16);
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) {
d3 = aIcon.getMaxU();
d4 = aIcon.getMinU();
minU = 16.0F - aIcon.getMaxU();
maxU = 16.0F - aIcon.getMinU();
}

if (aRenderer.renderMinZ < 0.0D || aRenderer.renderMaxZ > 1.0D) {
d5 = aIcon.getMinV();
d6 = aIcon.getMaxV();
minV = aIcon.getMinV();
maxV = aIcon.getMaxV();
}

float d11 = aX + (float)aRenderer.renderMinX;
float d12 = aX + (float)aRenderer.renderMaxX;
float d13 = aY + (float)aRenderer.renderMinY;
float d14 = aZ + (float)aRenderer.renderMinZ;
float d15 = aZ + (float)aRenderer.renderMaxZ;

Tessellator.instance.addVertexWithUV((double)d11, (double)d13, (double)d15, (double)d3, (double)d6);
Tessellator.instance.addVertexWithUV((double)d11, (double)d13, (double)d14, (double)d3, (double)d5);
Tessellator.instance.addVertexWithUV((double)d12, (double)d13, (double)d14, (double)d4, (double)d5);
Tessellator.instance.addVertexWithUV((double)d12, (double)d13, (double)d15, (double)d4, (double)d6);
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;

if ((aIcon = mIconContainer.getOverlayIcon()) != null) {
Tessellator.instance.setColorRGBA(128, 128, 128, 255);

Tessellator.instance.addVertexWithUV((double)d11, (double)d13, (double)d15, (double)d3, (double)d6);
Tessellator.instance.addVertexWithUV((double)d11, (double)d13, (double)d14, (double)d3, (double)d5);
Tessellator.instance.addVertexWithUV((double)d12, (double)d13, (double)d14, (double)d4, (double)d5);
Tessellator.instance.addVertexWithUV((double)d12, (double)d13, (double)d15, (double)d4, (double)d6);
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) {
tessellator.setColorRGBA(128, 128, 128, 255);

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.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);
}
}

@Override
public void renderZPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
Tessellator.instance.setColorRGBA((int) (mRGBa[0] * 0.8F), (int) (mRGBa[1] * 0.8F), (int) (mRGBa[2] * 0.8F), mAllowAlpha ? 255 - mRGBa[3] : 255);
final Tessellator tesselator = Tessellator.instance;
tesselator.setColorRGBA((int) (mRGBa[0] * 0.8F), (int) (mRGBa[1] * 0.8F), (int) (mRGBa[2] * 0.8F), mAllowAlpha ? 255 - mRGBa[3] : 255);
aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, mIconContainer.getIcon());
if (mIconContainer.getOverlayIcon() != null) {
Tessellator.instance.setColorRGBA(204, 204, 204, 255);
tesselator.setColorRGBA(204, 204, 204, 255);
aRenderer.renderFaceZPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon());
}
}

@Override
public void renderZNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
Tessellator.instance.setColorRGBA((int) (mRGBa[0] * 0.8F), (int) (mRGBa[1] * 0.8F), (int) (mRGBa[2] * 0.8F), mAllowAlpha ? 255 - mRGBa[3] : 255);
final Tessellator tesselator = Tessellator.instance;
tesselator.setColorRGBA((int) (mRGBa[0] * 0.8F), (int) (mRGBa[1] * 0.8F), (int) (mRGBa[2] * 0.8F), mAllowAlpha ? 255 - mRGBa[3] : 255);
aRenderer.field_152631_f = true;
aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon());
if (mIconContainer.getOverlayIcon() != null) {
Tessellator.instance.setColorRGBA(204, 204, 204, 255);
tesselator.setColorRGBA(204, 204, 204, 255);
aRenderer.renderFaceZNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon());
}
aRenderer.field_152631_f = false;
}

@Override
Expand Down
Loading