Skip to content

Commit

Permalink
feat: ME Chest rendering
Browse files Browse the repository at this point in the history
reference issue: xsun2001#7
  • Loading branch information
leytilera committed Jan 23, 2023
1 parent db09e9d commit c1d911e
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/main/java/appeng/block/legacy/BlockLegacyChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import appeng.block.AEBaseTileBlock;
import appeng.client.render.BaseBlockRender;
import appeng.client.render.blocks.RenderBlockLegacyChest;
import appeng.client.texture.ExtraBlockTextures;
import appeng.core.features.AEFeature;
import appeng.core.localization.PlayerMessages;
import appeng.core.sync.GuiBridge;
Expand All @@ -18,6 +19,9 @@
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

Expand All @@ -26,7 +30,7 @@ public class BlockLegacyChest extends AEBaseTileBlock {
public BlockLegacyChest() {
super(Material.iron);
this.isFullSize = this.isOpaque = false;
this.setTileEntity(TileChest.class);
this.setTileEntity(TileLegacyChest.class);
this.setFeature(EnumSet.of(AEFeature.Legacy));
}

Expand Down Expand Up @@ -75,4 +79,22 @@ public boolean onActivated(
return false;
}

@Override
public IIcon getIcon(IBlockAccess w, int x, int y, int z, int s) {
TileEntity te = w.getTileEntity(x, y, z);
if (!(te instanceof TileLegacyChest)) {
return super.getIcon(w, x, y, z, s);
}

TileLegacyChest tlc = (TileLegacyChest) te;

ForgeDirection direction
= this.mapRotation(tlc, ForgeDirection.getOrientation(s));

if (direction == ForgeDirection.UP) {
return ExtraBlockTextures.HDChestTop.getIcon();
}
return super.getIcon(direction.ordinal(), w.getBlockMetadata(x, y, z));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import appeng.block.legacy.BlockLegacyChest;
import appeng.client.render.BaseBlockRender;
import appeng.client.texture.ExtraBlockTextures;
import appeng.tile.legacy.TileLegacyChest;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;

public class RenderBlockLegacyChest extends BaseBlockRender<BlockLegacyChest, TileLegacyChest> {
Expand All @@ -13,6 +17,65 @@ public boolean renderInWorld(BlockLegacyChest block, IBlockAccess world, int x,
renderer.setRenderBounds(0.02, 0.0, 0.02, 0.98, 0.98, 0.98);
renderer.renderAllFaces = true;
renderer.renderStandardBlock(block, x, y, z);
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileLegacyChest && ((TileLegacyChest)tile).getCellStatus(0) > 0) {
TileLegacyChest te = (TileLegacyChest)tile;
final int bn = 9;
float u = 6.0f;
float v = 1.0f;
int cheststatus = te.getCellStatus(0);
if (te.isPowered()) {
if (cheststatus == 1) {
u = 1.0f;
v = 9.0f;
}
else if (cheststatus == 2) {
u = 1.0f;
v = 5.0f;
}
else {
u = 1.0f;
v = 1.0f;
}
}
final IIcon parts = ExtraBlockTextures.HDChestTopParts.getIcon();
final float offsetPerPixel = 0.0625f;
final float[] p1 = new float[5];
final float[] p2 = new float[5];
final float[] p3 = new float[5];
final float[] p4 = new float[5];
p1[0] = 4.0f * offsetPerPixel;
p1[1] = 0.981f;
p1[2] = 4.0f * offsetPerPixel;
p1[3] = u;
p1[4] = v;
p2[0] = p1[0] + offsetPerPixel * 4.0f;
p2[1] = p1[1];
p2[2] = p1[2];
p2[3] = p1[3] + 4.0f;
p2[4] = p1[4];
p3[0] = p1[0] + offsetPerPixel * 4.0f;
p3[1] = p1[1];
p3[2] = p1[2] + offsetPerPixel * 3.0f;
p3[3] = p1[3] + 4.0f;
p3[4] = p1[4] + 3.0f;
p4[0] = p1[0];
p4[1] = p1[1];
p4[2] = p1[2] + offsetPerPixel * 3.0f;
p4[3] = p1[3];
p4[4] = p1[4] + 3.0f;
final Tessellator tess = Tessellator.instance;
if (te.isPowered()) {
tess.setBrightness(bn << 20 | bn << 4 | bn << 3);
}
else {
tess.setBrightness(block.getMixedBrightnessForBlock(world, x, y + 1, z));
}
tess.addVertexWithUV((double)(x + p4[0]), (double)(y + p4[1]), (double)(z + p4[2]), (double)parts.getInterpolatedU((double)p4[3]), (double)parts.getInterpolatedV((double)p4[4]));
tess.addVertexWithUV((double)(x + p3[0]), (double)(y + p3[1]), (double)(z + p3[2]), (double)parts.getInterpolatedU((double)p3[3]), (double)parts.getInterpolatedV((double)p3[4]));
tess.addVertexWithUV((double)(x + p2[0]), (double)(y + p2[1]), (double)(z + p2[2]), (double)parts.getInterpolatedU((double)p2[3]), (double)parts.getInterpolatedV((double)p2[4]));
tess.addVertexWithUV((double)(x + p1[0]), (double)(y + p1[1]), (double)(z + p1[2]), (double)parts.getInterpolatedU((double)p1[3]), (double)parts.getInterpolatedV((double)p1[4]));
}
renderer.renderAllFaces = false;
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/appeng/client/texture/ExtraBlockTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public enum ExtraBlockTextures {
Controller5("BlockLegacyControllerFront"),
ControllerLinked("ControllerLinked"),

HDChestTop("BlockHDChestTop"),
HDChestTopParts("BlockHDChestTopParts"),

BlockStorageMonitorFrontMatrix("BlockStorageMonitorFront_Matrix"),

BlockAssemblerWallMerged("BlockAssemblerWallMerged"),
Expand Down

0 comments on commit c1d911e

Please sign in to comment.