add support for placing drawers facing upwards and downwards (#74)

This commit is contained in:
ABKQPO authored and GitHub committed 2026-08-05 08:11:32 +07:00
1 parent 9bbcdc765b
commit 7741ab8628
19 files changed
+1070 -401

No files matched your search

+3 -1
View File
@@ -1,6 +1,8 @@
// Add your dependencies here
dependencies {
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.8.103-GTNH:dev")
implementation("com.github.GTNewHorizons:GTNHLib:0.11.35:dev")
compileOnlyApi('com.github.GTNewHorizons:Angelica:2.1.60:api')
compileOnly('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-999-GTNH:api') {transitive=false}
@@ -13,4 +15,4 @@ dependencies {
compileOnly("com.github.GTNewHorizons:Avaritia:1.97:dev")
compileOnly("com.github.GTNewHorizons:Backhand:1.8.13:dev")
compileOnly("org.jetbrains:annotations:26.0.2")
}
}
@@ -47,11 +47,11 @@ public class BlockCompDrawers extends BlockDrawers implements INetworked {
}
@Override
public int getDrawerSlot(int side, float hitX, float hitY, float hitZ) {
if (hitTop(hitY)) return 0;
if (hitLeft(side, hitX, hitZ)) return 1;
else return 2;
public int getDrawerSlot(int side, int rotation, float hitX, float hitY, float hitZ) {
float u = faceLocalU(side, rotation, hitX, hitY, hitZ);
float v = faceLocalV(side, rotation, hitX, hitY, hitZ);
if (v > .5f) return 0;
return (u < .5f) ? 1 : 2;
}
@Override
@@ -12,7 +12,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@@ -80,23 +79,6 @@ public class BlockController extends BlockContainer implements INetworked {
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
TileEntityController tile = getTileEntitySafe(world, x, y, z);
if (tile.getDirection() > 1) return;
int quadrant = MathHelper.floor_double((entity.rotationYaw * 4f / 360f) + .5) & 3;
switch (quadrant) {
case 0:
tile.setDirection(2);
break;
case 1:
tile.setDirection(5);
break;
case 2:
tile.setDirection(3);
break;
case 3:
tile.setDirection(4);
break;
}
if (itemStack.hasDisplayName()) tile.setInventoryName(itemStack.getDisplayName());
@@ -161,9 +143,8 @@ public class BlockController extends BlockContainer implements INetworked {
if (tile.getDirection() == axis.ordinal()) return false;
if (axis == ForgeDirection.UP || axis == ForgeDirection.DOWN) return false;
tile.setDirection(axis.ordinal());
tile.setRotation(0);
world.markBlockForUpdate(x, y, z);
return true;
@@ -30,7 +30,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
@@ -262,6 +261,12 @@ public class BlockDrawers extends BlockContainer implements INetworked {
float depth = halfDepth ? .5f : 1;
switch (tile.getDirection()) {
case 0:
setBlockBounds(0, 1 - depth, 0, 1, 1, 1);
break;
case 1:
setBlockBounds(0, 0, 0, 1, depth, 1);
break;
case 2:
setBlockBounds(0, 0, 1 - depth, 1, 1, 1);
break;
@@ -293,23 +298,6 @@ public class BlockDrawers extends BlockContainer implements INetworked {
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
TileEntityDrawers tile = getTileEntitySafe(world, x, y, z);
if (tile.getDirection() > 1) return;
int quadrant = MathHelper.floor_double((entity.rotationYaw * 4f / 360f) + .5) & 3;
switch (quadrant) {
case 0:
tile.setDirection(2);
break;
case 1:
tile.setDirection(5);
break;
case 2:
tile.setDirection(3);
break;
case 3:
tile.setDirection(4);
break;
}
if (itemStack.hasDisplayName()) tile.setInventoryName(itemStack.getDisplayName());
@@ -390,7 +378,7 @@ public class BlockDrawers extends BlockContainer implements INetworked {
if (tileDrawers.isSealed()) return false;
int slot = getDrawerSlot(side, hitX, hitY, hitZ);
int slot = getDrawerSlot(side, tileDrawers.getRotation(), hitX, hitY, hitZ);
IDrawer drawer = tileDrawers.getDrawer(slot);
if (drawer != null) {
ItemStack currentStack = drawer.getStoredItemPrototype();
@@ -408,7 +396,7 @@ public class BlockDrawers extends BlockContainer implements INetworked {
boolean locked = tileDrawers.isLocked(LockAttribute.LOCK_POPULATED);
if (locked) {
int slot = getDrawerSlot(side, hitX, hitY, hitZ);
int slot = getDrawerSlot(side, tileDrawers.getRotation(), hitX, hitY, hitZ);
IDrawer drawer = tileDrawers.getDrawer(slot);
if (drawer != null) {
ItemStack stack = drawer.getStoredItemPrototype();
@@ -448,32 +436,121 @@ public class BlockDrawers extends BlockContainer implements INetworked {
}
public int getDrawerSlot(int side, float hitX, float hitY, float hitZ) {
return getDrawerSlot(side, 0, hitX, hitY, hitZ);
}
public int getDrawerSlot(int side, int rotation, float hitX, float hitY, float hitZ) {
if (drawerCount == 1) return 0;
if (drawerCount == 2) return hitTop(hitY) ? 0 : 1;
if (hitLeft(side, hitX, hitZ)) return hitTop(hitY) ? 0 : 1;
else return hitTop(hitY) ? 2 : 3;
float u = faceLocalU(side, rotation, hitX, hitY, hitZ);
float v = faceLocalV(side, rotation, hitX, hitY, hitZ);
boolean top = v > .5f;
if (drawerCount == 2) return top ? 0 : 1;
boolean left = u < .5f;
if (left) return top ? 0 : 1;
else return top ? 2 : 3;
}
protected boolean hitTop(float hitY) {
return hitY > .5;
}
protected boolean hitLeft(int side, float hitX, float hitZ) {
switch (side) {
/**
* Maps a block hit position to face-local coordinates of the drawer front, where {@code u} runs left (0) to right
* (1) and {@code v} runs bottom (0) to top (1) as the front is seen by the player. The horizontal cases reproduce
* the legacy hit mapping exactly; up/down cases honor the placement {@code rotation} so slot picking matches what
* is rendered.
*/
protected static float faceLocalU(int direction, int rotation, float hitX, float hitY, float hitZ) {
int rot = normalizeQuarterTurn(rotation);
switch (direction) {
case 1: // UP: front is the top face; mapping is the inverse of the item/texture rigid tilt.
switch (rot) {
case 1 -> {
return 1 - hitZ;
}
case 2 -> {
return 1 - hitX;
}
case 3 -> {
return hitZ;
}
default -> {
return hitX;
}
}
case 0: // DOWN: front is the bottom face.
switch (rot) {
case 1 -> {
return 1 - hitZ;
}
case 2 -> {
return 1 - hitX;
}
case 3 -> {
return hitZ;
}
default -> {
return hitX;
}
}
case 2:
return hitX > .5;
return 1 - hitX;
case 3:
return hitX < .5;
return hitX;
case 4:
return hitZ < .5;
return hitZ;
case 5:
return hitZ > .5;
return 1 - hitZ;
default:
return true;
return hitX;
}
}
protected static float faceLocalV(int direction, int rotation, float hitX, float hitY, float hitZ) {
int rot = normalizeQuarterTurn(rotation);
switch (direction) {
case 1: // UP: front is the top face; mapping is the inverse of the item/texture rigid tilt.
switch (rot) {
case 1 -> {
return 1 - hitX;
}
case 2 -> {
return hitZ;
}
case 3 -> {
return hitX;
}
default -> {
return 1 - hitZ;
}
}
case 0: // DOWN: front is the bottom face.
switch (rot) {
case 1 -> {
return hitX;
}
case 2 -> {
return 1 - hitZ;
}
case 3 -> {
return 1 - hitX;
}
default -> {
return hitZ;
}
}
case 2:
case 3:
case 4:
case 5:
default:
return hitY;
}
}
protected static int normalizeQuarterTurn(int rotation) {
int normalized = rotation % 4;
return normalized >= 0 ? normalized : normalized + 4;
}
@Override
public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) {
TileEntityDrawers tile = getTileEntitySafe(world, x, y, z);
@@ -485,9 +562,8 @@ public class BlockDrawers extends BlockContainer implements INetworked {
if (tile.getDirection() == axis.ordinal()) return false;
if (axis == ForgeDirection.UP || axis == ForgeDirection.DOWN) return false;
tile.setDirection(axis.ordinal());
tile.setRotation(0);
world.markBlockForUpdate(x, y, z);
@@ -914,6 +990,9 @@ public class BlockDrawers extends BlockContainer implements INetworked {
case 1:
if (halfDepth) {
switch (tile.getDirection()) {
case 0:
case 1:
return (level > 0) ? iconOverlay[level] : iconSide[meta];
case 2:
case 3:
case 4:
@@ -926,6 +1005,9 @@ public class BlockDrawers extends BlockContainer implements INetworked {
case 3:
if (halfDepth) {
switch (tile.getDirection()) {
case 0:
case 1:
return (level > 0) ? iconOverlayH[level] : iconSideH[meta];
case 2:
case 3:
return (level > 0) ? iconOverlay[level] : iconSide[meta];
@@ -939,6 +1021,9 @@ public class BlockDrawers extends BlockContainer implements INetworked {
case 5:
if (halfDepth) {
switch (tile.getDirection()) {
case 0:
case 1:
return (level > 0) ? iconOverlayH[level] : iconSideH[meta];
case 2:
case 3:
return (level > 0) ? iconOverlayV[level] : iconSideV[meta];
@@ -144,6 +144,7 @@ public class TileEntityController extends TileEntity
private int[] drawerSlots = new int[0];
private int[] autoSides = new int[] { 0, 1, 2, 3, 4, 5 };
private int direction;
private int rotation;
private int drawerSize = 0;
private int range;
@@ -170,6 +171,14 @@ public class TileEntityController extends TileEntity
this.direction = direction % 6;
}
public int getRotation() {
return rotation;
}
public void setRotation(int rotation) {
this.rotation = ((rotation % 4) + 4) % 4;
}
public int interactPutItemsIntoInventory(EntityPlayer player) {
if (inventorySlots.length == 0) updateCache();
@@ -652,6 +661,7 @@ public class TileEntityController extends TileEntity
super.readFromNBT(tag);
setDirection(tag.getByte("Dir"));
rotation = tag.hasKey("Rot") ? tag.getByte("Rot") : 0;
if (tag.hasKey("CustomName", Constants.NBT.TAG_STRING)) customName = tag.getString("CustomName");
@@ -663,6 +673,7 @@ public class TileEntityController extends TileEntity
super.writeToNBT(tag);
tag.setByte("Dir", (byte) direction);
if (rotation != 0) tag.setByte("Rot", (byte) rotation);
if (hasCustomInventoryName()) tag.setString("CustomName", customName);
}
@@ -62,6 +62,7 @@ public abstract class TileEntityDrawers extends BaseTileEntity
private IDrawerInventory inventory;
private int direction;
private int rotation;
private int drawerCapacity = 1;
private boolean shrouded = false;
private boolean quantified = false;
@@ -112,6 +113,14 @@ public abstract class TileEntityDrawers extends BaseTileEntity
this.direction = direction % 6;
}
public int getRotation() {
return rotation;
}
public void setRotation(int rotation) {
this.rotation = ((rotation % 4) + 4) % 4;
}
public int getMaxStorageLevel() {
// Could use iterables and lambdas instead
int maxLevel = 1;
@@ -387,7 +396,7 @@ public abstract class TileEntityDrawers extends BaseTileEntity
}
BlockDrawers block = (BlockDrawers) worldObj.getBlock(xCoord, yCoord, zCoord);
int slot = block.getDrawerSlot(face, hitX, hitY, hitZ);
int slot = block.getDrawerSlot(face, getRotation(), hitX, hitY, hitZ);
IDrawer drawer = getDrawer(slot);
if (drawer == null) {
@@ -739,6 +748,7 @@ public abstract class TileEntityDrawers extends BaseTileEntity
super.readFromFixedNBT(tag);
setDirection(tag.getByte("Dir"));
rotation = tag.hasKey("Rot") ? tag.getByte("Rot") : 0;
taped = false;
if (tag.hasKey("Tape")) taped = tag.getBoolean("Tape");
@@ -754,6 +764,7 @@ public abstract class TileEntityDrawers extends BaseTileEntity
super.writeToFixedNBT(tag);
tag.setByte("Dir", (byte) direction);
if (rotation != 0) tag.setByte("Rot", (byte) rotation);
if (taped) tag.setBoolean("Tape", taped);
@@ -19,7 +19,9 @@ import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
@ThreadSafeISBRH(perThread = true)
public class ControllerRenderer implements ISimpleBlockRenderingHandler {
private static final double unit = .0625f;
private static final double UNIT = .0625f;
private static final int INVENTORY_SIDE = 4;
private ModularBoxRenderer boxRenderer = new ModularBoxRenderer();
private RenderHelper renderHelper = RenderHelper.instances.get();
@@ -32,24 +34,19 @@ public class ControllerRenderer implements ISimpleBlockRenderingHandler {
}
private void renderInventoryBlock(BlockController block, int metadata, int modelId, RenderBlocks renderer) {
int side = 4;
boxRenderer.setUnit(unit);
boxRenderer.setColor(ModularBoxRenderer.COLOR_WHITE);
for (int i = 0; i < 6; i++) boxRenderer.setIcon(block.getIcon(i, metadata), i);
initInventoryBoxRenderer(block, metadata);
GL11.glRotatef(90, 0, 1, 0);
GL11.glTranslatef(-.5f, -.5f, -.5f);
renderHelper.state
.setUVRotation(RenderHelper.YPOS, RenderHelperState.ROTATION_BY_FACE_FACE[RenderHelper.ZNEG][side]);
applyTopUvRotation(INVENTORY_SIDE, 0);
renderExterior(block, 0, 0, 0, side, renderer);
renderExterior(block, 0, 0, 0, INVENTORY_SIDE, renderer);
boxRenderer.setUnit(0);
boxRenderer.setInteriorIcon(block.getIcon(side, metadata), ForgeDirection.OPPOSITES[side]);
boxRenderer.setInteriorIcon(block.getIcon(INVENTORY_SIDE, metadata), ForgeDirection.OPPOSITES[INVENTORY_SIDE]);
renderInterior(block, 0, 0, 0, side, renderer);
renderInterior(block, 0, 0, 0, INVENTORY_SIDE, renderer);
renderHelper.state.clearUVRotation(RenderHelper.YPOS);
@@ -70,13 +67,11 @@ public class ControllerRenderer implements ISimpleBlockRenderingHandler {
if (tile == null) return false;
int side = tile.getDirection();
int rotation = tile.getRotation();
renderHelper.state
.setUVRotation(RenderHelper.YPOS, RenderHelperState.ROTATION_BY_FACE_FACE[RenderHelper.ZNEG][side]);
applyTopUvRotation(side, rotation);
boxRenderer.setUnit(unit);
boxRenderer.setColor(ModularBoxRenderer.COLOR_WHITE);
for (int i = 0; i < 6; i++) boxRenderer.setExteriorIcon(block.getIcon(world, x, y, z, i), i);
initWorldBoxRenderer(world, x, y, z, block);
boxRenderer.setCutIcon(block.getIconTrim(0));
boxRenderer.setInteriorIcon(block.getIconTrim(0));
@@ -93,82 +88,68 @@ public class ControllerRenderer implements ISimpleBlockRenderingHandler {
return true;
}
private void initInventoryBoxRenderer(BlockController block, int metadata) {
boxRenderer.setUnit(UNIT);
boxRenderer.setColor(ModularBoxRenderer.COLOR_WHITE);
for (int i = 0; i < 6; i++) boxRenderer.setIcon(block.getIcon(i, metadata), i);
}
private void initWorldBoxRenderer(IBlockAccess world, int x, int y, int z, BlockController block) {
boxRenderer.setUnit(UNIT);
boxRenderer.setColor(ModularBoxRenderer.COLOR_WHITE);
for (int i = 0; i < 6; i++) boxRenderer.setExteriorIcon(block.getIcon(world, x, y, z, i), i);
}
private void applyTopUvRotation(int side, int rotation) {
int uvRotation = side <= 1 ? rotation : RenderHelperState.ROTATION_BY_FACE_FACE[RenderHelper.ZNEG][side];
renderHelper.state.setUVRotation(RenderHelper.YPOS, uvRotation);
}
private void renderExterior(BlockController block, int x, int y, int z, int side, RenderBlocks renderer) {
double depth = 1;
double xMin = 0, xMax = 0, zMin = 0, zMax = 0;
switch (side) {
case 2:
xMin = 0;
xMax = 1;
zMin = 1 - depth;
zMax = 1;
break;
case 3:
xMin = 0;
xMax = 1;
zMin = 0;
zMax = depth;
break;
case 4:
xMin = 1 - depth;
xMax = 1;
zMin = 0;
zMax = 1;
break;
case 5:
xMin = 0;
xMax = depth;
zMin = 0;
zMax = 1;
break;
}
boxRenderer.renderExterior(
renderer.blockAccess,
block,
x,
y,
z,
xMin,
0,
zMin,
xMax,
0,
0,
1,
1,
1,
zMax,
0,
ModularBoxRenderer.sideCut[side]);
}
private void renderInterior(BlockController block, int x, int y, int z, int side, RenderBlocks renderer) {
double unit = .0625;
double depth = 1;
double xMin = 0, xMax = 0, zMin = 0, zMax = 0;
double unit = UNIT;
double xMin = unit, xMax = 1 - unit, yMin = unit, yMax = 1 - unit, zMin = unit, zMax = 1 - unit;
switch (side) {
case 0:
yMin = 0;
yMax = unit;
break;
case 1:
yMin = 1 - unit;
yMax = 1;
break;
case 2:
xMin = unit;
xMax = 1 - unit;
zMin = 1 - depth;
zMax = 1 - depth + unit;
zMin = 0;
zMax = unit;
break;
case 3:
xMin = unit;
xMax = 1 - unit;
zMin = depth - unit;
zMax = depth;
zMin = 1 - unit;
zMax = 1;
break;
case 4:
xMin = 1 - depth;
xMax = 1 - depth + unit;
zMin = unit;
zMax = 1 - unit;
xMin = 0;
xMax = unit;
break;
case 5:
xMin = depth - unit;
xMax = depth;
zMin = unit;
zMax = 1 - unit;
xMin = 1 - unit;
xMax = 1;
break;
}
@@ -179,10 +160,10 @@ public class ControllerRenderer implements ISimpleBlockRenderingHandler {
y,
z,
xMin,
unit,
yMin,
zMin,
xMax,
1 - unit,
yMax,
zMax,
0,
ModularBoxRenderer.sideCut[side]);
@@ -24,31 +24,48 @@ public class DrawersCustomRenderer extends DrawersRenderer {
RenderBlocks renderer) {
BlockDrawersCustom custom = (BlockDrawersCustom) block;
ItemStack materialSide = tile.getMaterialSide();
if (materialSide == null) materialSide = new ItemStack(block);
ItemStack materialSide = getMaterialOrDefault(tile.getMaterialSide(), new ItemStack(block));
ItemStack materialFront = getMaterialOrDefault(tile.getMaterialFront(), materialSide);
ItemStack materialTrim = getMaterialOrDefault(tile.getMaterialTrim(), materialSide);
ItemStack materialFront = tile.getMaterialFront();
if (materialFront == null) materialFront = materialSide;
IIcon trimIcon = getIconOrDefault(materialTrim, custom.getDefaultTrimIcon());
IIcon panelIcon = getIconOrDefault(materialSide, custom.getDefaultFaceIcon());
IIcon frontIcon = getIconOrDefault(materialFront, custom.getDefaultFaceIcon());
ItemStack materialTrim = tile.getMaterialTrim();
if (materialTrim == null) materialTrim = materialSide;
IIcon trimIcon = Block.getBlockFromItem(materialTrim.getItem()).getIcon(4, materialTrim.getItemDamage());
IIcon panelIcon = Block.getBlockFromItem(materialSide.getItem()).getIcon(4, materialSide.getItemDamage());
IIcon frontIcon = Block.getBlockFromItem(materialFront.getItem()).getIcon(4, materialFront.getItemDamage());
if (trimIcon == null) trimIcon = custom.getDefaultTrimIcon();
if (panelIcon == null) panelIcon = custom.getDefaultFaceIcon();
if (frontIcon == null) frontIcon = custom.getDefaultFaceIcon();
if (ForgeHooksClient.getWorldRenderPass() == 0)
commonRender.renderBasePass(world, x, y, z, custom, tile.getDirection(), panelIcon, trimIcon, frontIcon);
else if (ForgeHooksClient.getWorldRenderPass() == 1)
commonRender.renderOverlayPass(world, x, y, z, custom, tile.getDirection(), trimIcon, frontIcon);
if (ForgeHooksClient.getWorldRenderPass() == 0) commonRender.renderBasePass(
world,
x,
y,
z,
custom,
tile.getDirection(),
tile.getRotation(),
panelIcon,
trimIcon,
frontIcon);
else if (ForgeHooksClient.getWorldRenderPass() == 1) commonRender.renderOverlayPass(
world,
x,
y,
z,
custom,
tile.getDirection(),
tile.getRotation(),
trimIcon,
frontIcon);
}
@Override
public int getRenderId() {
return StorageDrawers.proxy.drawersCustomRenderID;
}
private ItemStack getMaterialOrDefault(ItemStack material, ItemStack fallback) {
return material != null ? material : fallback;
}
private IIcon getIconOrDefault(ItemStack material, IIcon fallback) {
IIcon icon = Block.getBlockFromItem(material.getItem()).getIcon(4, material.getItemDamage());
return icon != null ? icon : fallback;
}
}
@@ -22,6 +22,8 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
private static final double unit = .0625f;
private ModularBoxRenderer boxRenderer = new ModularBoxRenderer();
private final double[] frontDecorationMin = new double[2];
private final double[] frontDecorationMax = new double[2];
private RenderHelper renderHelper = RenderHelper.instances.get();
@@ -50,21 +52,25 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
return true;
int side = tile.getDirection();
int rotation = tile.getRotation();
if (StorageDrawers.config.cache.enableIndicatorUpgrades)
renderIndicator(block, x, y, z, side, renderer, tile.getEffectiveStatusLevel());
renderIndicator(block, x, y, z, side, rotation, renderer, tile.getEffectiveStatusLevel());
if (StorageDrawers.config.cache.enableLockUpgrades) renderLock(
block,
x,
y,
z,
side,
rotation,
renderer,
tile.isLocked(LockAttribute.LOCK_POPULATED),
tile.getOwner() != null);
if (StorageDrawers.config.cache.enableVoidUpgrades) renderVoid(block, x, y, z, side, renderer, tile.isVoid());
if (StorageDrawers.config.cache.enableTape) renderTape(block, x, y, z, side, renderer, tile.isSealed());
if (StorageDrawers.config.cache.enableVoidUpgrades)
renderVoid(block, x, y, z, side, rotation, renderer, tile.isVoid());
if (StorageDrawers.config.cache.enableTape)
renderTape(block, x, y, z, side, rotation, renderer, tile.isSealed());
renderShroud(block, x, y, z, side, renderer, tile.isShrouded());
renderShroud(block, x, y, z, side, rotation, renderer, tile.isShrouded());
return true;
}
@@ -72,12 +78,20 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
protected void renderBaseBlock(IBlockAccess world, TileEntityDrawers tile, int x, int y, int z, BlockDrawers block,
RenderBlocks renderer) {
int side = tile.getDirection();
int rotation = tile.getRotation();
int meta = world.getBlockMetadata(x, y, z);
renderHelper.state
.setUVRotation(RenderHelper.YPOS, RenderHelperState.ROTATION_BY_FACE_FACE[RenderHelper.YPOS][side]);
renderHelper.state
.setUVRotation(RenderHelper.YNEG, RenderHelperState.ROTATION_BY_FACE_FACE[RenderHelper.YNEG][side]);
if (side <= 1) {
// Front points up or down; the front/back Y faces carry the front grain spun to match the rigid tilt that
// the item and decoration renderers use (see RenderHelperState orientation matrix).
if (side == 1) renderHelper.state.setUVRotation(RenderHelper.YPOS, (4 - rotation) % 4);
else renderHelper.state.setUVRotation(RenderHelper.YNEG, (rotation + 2) % 4);
} else {
renderHelper.state
.setUVRotation(RenderHelper.YPOS, RenderHelperState.ROTATION_BY_FACE_FACE[RenderHelper.YPOS][side]);
renderHelper.state
.setUVRotation(RenderHelper.YNEG, RenderHelperState.ROTATION_BY_FACE_FACE[RenderHelper.YNEG][side]);
}
boxRenderer.setUnit(block.getTrimWidth());
boxRenderer.setColor(ModularBoxRenderer.COLOR_WHITE);
@@ -88,8 +102,6 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
renderExterior(block, x, y, z, side, renderer);
renderHelper.state.clearUVRotation(RenderHelper.YPOS);
int maxStorageLevel = tile.getMaxStorageLevel();
if (maxStorageLevel > 1 && StorageDrawers.config.cache.renderStorageUpgrades && !tile.shouldHideUpgrades()) {
for (int i = 0; i < 6; i++)
@@ -107,41 +119,158 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
renderInterior(block, x, y, z, side, renderer);
}
private void renderLock(BlockDrawers block, int x, int y, int z, int side, RenderBlocks renderer, boolean locked,
boolean owned) {
private void renderLock(BlockDrawers block, int x, int y, int z, int side, int rotation, RenderBlocks renderer,
boolean locked, boolean owned) {
if (!locked && !owned) return;
double depth = block.halfDepth ? .5 : 1;
IIcon iconLock = block.getLockIcon(locked, owned);
renderHelper.setRenderBounds(0.46875, 0.9375, 0, 0.53125, 1, depth + .005);
renderHelper.state.setRotateTransform(RenderHelper.ZPOS, side);
renderHelper.renderPartialFace(RenderHelper.ZPOS, renderer.blockAccess, block, x, y, z, iconLock, 0, 0, 1, 1);
renderHelper.state.clearRotateTransform();
renderFrontDecoration(block, x, y, z, side, rotation, renderer, iconLock, 0.46875, 0.9375, 0.53125, 1);
}
private void renderVoid(BlockDrawers block, int x, int y, int z, int side, RenderBlocks renderer, boolean voided) {
private void renderVoid(BlockDrawers block, int x, int y, int z, int side, int rotation, RenderBlocks renderer,
boolean voided) {
if (!voided) return;
double depth = block.halfDepth ? .5 : 1;
IIcon iconVoid = block.getVoidIcon();
renderHelper.setRenderBounds(1 - .0625, 0.9375, 0, 1, 1, depth + .005);
renderHelper.state.setRotateTransform(RenderHelper.ZPOS, side);
renderHelper.renderPartialFace(RenderHelper.ZPOS, renderer.blockAccess, block, x, y, z, iconVoid, 0, 0, 1, 1);
renderHelper.state.clearRotateTransform();
renderFrontDecoration(block, x, y, z, side, rotation, renderer, iconVoid, 1 - .0625, 0.9375, 1, 1);
}
private void renderTape(BlockDrawers block, int x, int y, int z, int side, RenderBlocks renderer, boolean taped) {
private void renderTape(BlockDrawers block, int x, int y, int z, int side, int rotation, RenderBlocks renderer,
boolean taped) {
if (!taped) return;
double depth = block.halfDepth ? .5 : 1;
IIcon iconTape = block.getTapeIcon();
renderHelper.setRenderBounds(0, 0, 0, 1, 1, depth + .005);
renderHelper.state.setRotateTransform(RenderHelper.ZPOS, side);
renderHelper.renderFace(RenderHelper.ZPOS, renderer.blockAccess, block, x, y, z, iconTape);
renderOrientedFrontFace(block, x, y, z, side, rotation, renderer, iconTape);
}
private void renderFrontDecoration(BlockDrawers block, int x, int y, int z, int side, int rotation,
RenderBlocks renderer, IIcon icon, double uMin, double vMin, double uMax, double vMax) {
double depth = block.halfDepth ? .5 : 1;
if (side > 1) {
renderOrientedFrontPartialFace(
block,
x,
y,
z,
side,
rotation,
renderer,
icon,
uMin,
vMin,
uMax,
vMax,
depth);
return;
}
setVerticalFrontDecorationBounds(depth, side, rotation, uMin, vMin, uMax, vMax);
applyVerticalFrontDecorationRotation(side, rotation);
renderHelper.renderPartialFace(side, renderer.blockAccess, block, x, y, z, icon, 0, 0, 1, 1);
clearVerticalFrontDecorationRotation(side);
}
private void setVerticalFrontDecorationBounds(double depth, int side, int rotation, double uMin, double vMin,
double uMax, double vMax) {
mapVerticalFrontPoint(side, rotation, uMin, vMin, frontDecorationMin);
mapVerticalFrontPoint(side, rotation, uMax, vMax, frontDecorationMax);
double minX = Math.min(frontDecorationMin[0], frontDecorationMax[0]);
double maxX = Math.max(frontDecorationMin[0], frontDecorationMax[0]);
double minZ = Math.min(frontDecorationMin[1], frontDecorationMax[1]);
double maxZ = Math.max(frontDecorationMin[1], frontDecorationMax[1]);
if (side == RenderHelper.YPOS) {
renderHelper.setRenderBounds(minX, 0, minZ, maxX, depth + .005, maxZ);
} else {
renderHelper.setRenderBounds(minX, 1 - depth - .005, minZ, maxX, 1, maxZ);
}
}
private void mapVerticalFrontPoint(int side, int rotation, double u, double v, double[] out) {
int rot = normalizeQuarterTurn(rotation);
if (side == RenderHelper.YPOS) {
switch (rot) {
case 1:
out[0] = 1 - v;
out[1] = 1 - u;
return;
case 2:
out[0] = 1 - u;
out[1] = v;
return;
case 3:
out[0] = v;
out[1] = u;
return;
default:
out[0] = u;
out[1] = 1 - v;
return;
}
}
switch (rot) {
case 1:
out[0] = v;
out[1] = 1 - u;
return;
case 2:
out[0] = 1 - u;
out[1] = 1 - v;
return;
case 3:
out[0] = 1 - v;
out[1] = u;
return;
default:
out[0] = u;
out[1] = v;
return;
}
}
private void applyVerticalFrontDecorationRotation(int side, int rotation) {
int uvRotation;
if (side == RenderHelper.YPOS) {
uvRotation = (4 - rotation) % 4;
if ((rotation & 1) == 1) uvRotation = (uvRotation + 2) % 4;
renderHelper.state.setUVRotation(RenderHelper.YPOS, uvRotation);
} else {
uvRotation = (rotation + 2) % 4;
if ((rotation & 1) == 1) uvRotation = (uvRotation + 2) % 4;
renderHelper.state.setUVRotation(RenderHelper.YNEG, uvRotation);
}
}
private void clearVerticalFrontDecorationRotation(int side) {
renderHelper.state.clearRotateTransform();
renderHelper.state.clearUVRotation(side);
}
private void renderOrientedFrontPartialFace(BlockDrawers block, int x, int y, int z, int side, int rotation,
RenderBlocks renderer, IIcon icon, double uMin, double vMin, double uMax, double vMax, double depth) {
renderHelper.setRenderBounds(uMin, vMin, 0, uMax, vMax, depth + .005);
renderHelper.state.setOrientation(RenderHelper.ZPOS, side, rotation);
renderHelper.renderPartialFace(RenderHelper.ZPOS, renderer.blockAccess, block, x, y, z, icon, 0, 0, 1, 1);
renderHelper.state.clearRotateTransform();
}
private void renderOrientedFrontFace(BlockDrawers block, int x, int y, int z, int side, int rotation,
RenderBlocks renderer, IIcon icon) {
renderHelper.state.setOrientation(RenderHelper.ZPOS, side, rotation);
renderHelper.renderFace(RenderHelper.ZPOS, renderer.blockAccess, block, x, y, z, icon);
renderHelper.state.clearRotateTransform();
}
private static int normalizeQuarterTurn(int rotation) {
int normalized = rotation % 4;
return normalized >= 0 ? normalized : normalized + 4;
}
private static final int[] cut = new int[] {
@@ -171,9 +300,9 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
private static final float[][] drawerXYWH3 = new float[][] { { 0, 8, 16, 8 }, { 0, 0, 8, 8 }, { 8, 0, 8, 8 }, };
private void renderShroud(BlockDrawers block, int x, int y, int z, int side, RenderBlocks renderer,
private void renderShroud(BlockDrawers block, int x, int y, int z, int side, int rotation, RenderBlocks renderer,
boolean shrouded) {
if (!shrouded || side < 2 || side > 5) return;
if (!shrouded) return;
TileEntityDrawers tile = block.getTileEntity(renderer.blockAccess, x, y, z);
@@ -218,14 +347,13 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
(subX + w) * unit,
(subY + h) * unit,
(depth - depthAdj + .05) * unit);
renderHelper.state.setRotateTransform(RenderHelper.ZPOS, side);
renderHelper.renderFace(RenderHelper.ZPOS, renderer.blockAccess, block, x, y, z, icon);
renderHelper.state.clearRotateTransform();
renderOrientedFrontFace(block, x, y, z, side, rotation, renderer, icon);
}
}
private void renderIndicator(BlockDrawers block, int x, int y, int z, int side, RenderBlocks renderer, int level) {
if (level <= 0 || side < 2 || side > 5) return;
private void renderIndicator(BlockDrawers block, int x, int y, int z, int side, int rotation, RenderBlocks renderer,
int level) {
if (level <= 0) return;
TileEntityDrawers tile = block.getTileEntity(renderer.blockAccess, x, y, z);
@@ -263,9 +391,7 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
(xywh[0] + xywh[2]) * unit,
(xywh[1] + xywh[3]) * unit,
(depth - depthAdj + .05) * unit);
renderHelper.state.setRotateTransform(RenderHelper.ZPOS, side);
renderHelper.renderFace(RenderHelper.ZPOS, renderer.blockAccess, block, x, y, z, iconOff);
renderHelper.state.clearRotateTransform();
renderOrientedFrontFace(block, x, y, z, side, rotation, renderer, iconOff);
if (level == 1 && drawer.getMaxCapacity() > 0 && drawer.getRemainingCapacity() == 0) {
renderHelper.state.setColorMult(1, 1, .9f, 1);
@@ -276,9 +402,7 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
(xywh[0] + xywh[2]) * unit,
(xywh[1] + xywh[3]) * unit,
(depth - depthAdj + .06) * unit);
renderHelper.state.setRotateTransform(RenderHelper.ZPOS, side);
renderHelper.renderFace(RenderHelper.ZPOS, renderer.blockAccess, block, x, y, z, iconOn);
renderHelper.state.clearRotateTransform();
renderOrientedFrontFace(block, x, y, z, side, rotation, renderer, iconOn);
renderHelper.state.resetColorMult();
} else if (level >= 2) {
double indXStart = xywh[0] + block.getIndStart() / unit;
@@ -299,9 +423,7 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
indXCur * unit,
indYCur * unit,
(depth - depthAdj + .06) * unit);
renderHelper.state.setRotateTransform(RenderHelper.ZPOS, side);
renderHelper.renderFace(RenderHelper.ZPOS, renderer.blockAccess, block, x, y, z, iconOn);
renderHelper.state.clearRotateTransform();
renderOrientedFrontFace(block, x, y, z, side, rotation, renderer, iconOn);
renderHelper.state.resetColorMult();
}
}
@@ -324,32 +446,32 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
private void renderExterior(BlockDrawers block, int x, int y, int z, int side, RenderBlocks renderer) {
double depth = block.halfDepth ? .5 : 1;
double xMin = 0, xMax = 0, zMin = 0, zMax = 0;
double xMin = 0, xMax = 1, yMin = 0, yMax = 1, zMin = 0, zMax = 1;
switch (side) {
case 0:
yMin = 1 - depth;
yMax = 1;
break;
case 1:
yMin = 0;
yMax = depth;
break;
case 2:
xMin = 0;
xMax = 1;
zMin = 1 - depth;
zMax = 1;
break;
case 3:
xMin = 0;
xMax = 1;
zMin = 0;
zMax = depth;
break;
case 4:
xMin = 1 - depth;
xMax = 1;
zMin = 0;
zMax = 1;
break;
case 5:
xMin = 0;
xMax = depth;
zMin = 0;
zMax = 1;
break;
}
@@ -360,10 +482,10 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
y,
z,
xMin,
0,
yMin,
zMin,
xMax,
1,
yMax,
zMax,
0,
ModularBoxRenderer.sideCut[side]);
@@ -372,32 +494,32 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
private void renderInterior(BlockDrawers block, int x, int y, int z, int side, RenderBlocks renderer) {
double unit = block.getTrimDepth();
double depth = block.halfDepth ? .5 : 1;
double xMin = 0, xMax = 0, zMin = 0, zMax = 0;
double xMin = unit, xMax = 1 - unit, yMin = unit, yMax = 1 - unit, zMin = unit, zMax = 1 - unit;
switch (side) {
case 0:
yMin = 1 - depth;
yMax = 1 - depth + unit;
break;
case 1:
yMin = depth - unit;
yMax = depth;
break;
case 2:
xMin = unit;
xMax = 1 - unit;
zMin = 1 - depth;
zMax = 1 - depth + unit;
break;
case 3:
xMin = unit;
xMax = 1 - unit;
zMin = depth - unit;
zMax = depth;
break;
case 4:
xMin = 1 - depth;
xMax = 1 - depth + unit;
zMin = unit;
zMax = 1 - unit;
break;
case 5:
xMin = depth - unit;
xMax = depth;
zMin = unit;
zMax = 1 - unit;
break;
}
@@ -408,10 +530,10 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler {
y,
z,
xMin,
unit,
yMin,
zMin,
xMax,
1 - unit,
yMax,
zMax,
0,
ModularBoxRenderer.sideCut[side]);
@@ -147,16 +147,15 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer {
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator
.addVertexWithUV(x + 0, y + h, 0, (u + (float) h * hScale) * uScale, (v + (float) h) * vScale);
tessellator.addVertexWithUV(x, y + h, 0, (u + (float) h * hScale) * uScale, (v + (float) h) * vScale);
tessellator.addVertexWithUV(
x + w,
y + h,
0,
(u + (float) w + (float) h * hScale) * uScale,
(v + (float) h) * vScale);
tessellator.addVertexWithUV(x + w, y + 0, 0, (u + (float) w) * uScale, (v + 0.0F) * vScale);
tessellator.addVertexWithUV(x + 0, y + 0, 0, (u + 0.0F) * uScale, (v + 0.0F) * vScale);
tessellator.addVertexWithUV(x + w, y, 0, (u + (float) w) * uScale, (v + 0.0F) * vScale);
tessellator.addVertexWithUV(x, y, 0, (u + 0.0F) * uScale, (v + 0.0F) * vScale);
tessellator.draw();
}
}
@@ -252,6 +251,17 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer {
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
// Up/down placements reuse the horizontal rendering path: rotate the block-local frame so the canonical south
// face maps onto the top or bottom face, spun by the placement rotation, then render as if facing south.
ForgeDirection renderSide = side;
if (side == ForgeDirection.UP || side == ForgeDirection.DOWN) {
GL11.glTranslatef(.5f, .5f, .5f);
GL11.glRotatef(tileDrawers.getRotation() * 90f, 0, 1, 0);
GL11.glRotatef(side == ForgeDirection.UP ? -90f : 90f, 1, 0, 0);
GL11.glTranslatef(-.5f, -.5f, -.5f);
renderSide = ForgeDirection.SOUTH;
}
itemRenderer.setRenderManager(RenderManager.instance);
int ambLight = tile.getWorldObj().getLightBrightnessForSkyBlocks(
@@ -273,34 +283,35 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer {
mc.gameSettings.fancyGraphics = true;
try {
if (StorageDrawers.config.isFancyItemRenderEnabled()) {
renderFancyItemSet(tileDrawers, side, depth);
} else {
renderFastItemSet(tileDrawers, side, depth, partialTickTime);
}
} catch (Exception e) {
// Swallow exception
}
if (StorageDrawers.config.cache.enableQuantifyUpgrades && tileDrawers.isQuantified()) {
float alpha = 1.0f;
double distance = Math.sqrt(distanceSq);
if (distance > 4.0) {
alpha = Math.max(1.0f - (float) ((distance - 4.0) / 6.0), 0.05f);
try {
if (StorageDrawers.config.isFancyItemRenderEnabled()) {
renderFancyItemSet(tileDrawers, renderSide, depth);
} else {
renderFastItemSet(tileDrawers, renderSide, depth, partialTickTime);
}
} catch (Exception e) {
// Swallow exception
}
if (distance < 10.0) {
for (int i = 0; i < tileDrawers.getDrawerCount(); i++) {
if (!tileDrawers.isDrawerEnabled(i)) continue;
if (StorageDrawers.config.cache.enableQuantifyUpgrades && tileDrawers.isQuantified()) {
float alpha = 1.0f;
double distance = Math.sqrt(distanceSq);
if (distance > 4.0) {
alpha = Math.max(1.0f - (float) ((distance - 4.0) / 6.0), 0.05f);
}
drawDrawerTexts(tileDrawers, i, side, depth, alpha);
if (distance < 10.0) {
for (int i = 0; i < tileDrawers.getDrawerCount(); i++) {
if (!tileDrawers.isDrawerEnabled(i)) continue;
drawDrawerTexts(tileDrawers, i, renderSide, depth, alpha);
}
}
}
} finally {
mc.gameSettings.fancyGraphics = cache;
GL11.glPopMatrix();
}
mc.gameSettings.fancyGraphics = cache;
GL11.glPopMatrix();
}
private void renderFancyItemSet(TileEntityDrawers tile, ForgeDirection side, float depth) {
@@ -480,27 +491,28 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer {
double zDepth = 1 / relScale - itemBlock.getBlockBoundsMaxZ();
itemDepth += zDepth * zunit;
} catch (Exception e) {}
} catch (Exception ignored) {}
}
switch (tile.getDirection()) {
case 3:
zc = switch (side.ordinal()) {
case 3 -> {
xc = xunit;
zc = itemDepth - zunit;
break;
case 2:
yield itemDepth - zunit;
}
case 2 -> {
xc = 1 - xunit;
zc = 1 - itemDepth + zunit;
break;
case 5:
yield 1 - itemDepth + zunit;
}
case 5 -> {
xc = itemDepth - zunit;
zc = 1 - xunit;
break;
case 4:
yield 1 - xunit;
}
case 4 -> {
xc = 1 - itemDepth + zunit;
zc = xunit;
break;
}
yield xunit;
}
default -> zc;
};
float yAdj = 0;
if (drawerCount == 2 || drawerCount == 4) yAdj = -.5f;
@@ -520,6 +532,9 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer {
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_LIGHTING);
// The block-local frame may be tilted for up/down drawers; renormalize so directional item lighting is not
// skewed by the rotation and does not bleed into adjacent slots.
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
IDrawer drawer = tile.getDrawer(slot);
try {
@@ -527,6 +542,7 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer {
itemRenderer.doRender(itemEnt, 0, 0, 0, 0, 0);
} catch (Exception ignored) {}
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
}
@@ -557,8 +573,8 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer {
1f - depth + block.getTrimDepth() - .005f);
List<IRenderLabel> renderHandlers = StorageDrawers.renderRegistry.getRenderHandlers();
for (int i = 0, n = renderHandlers.size(); i < n; i++) {
renderHandlers.get(i).render(tile, tile, slot, brightness, partialTickTime);
for (IRenderLabel renderHandler : renderHandlers) {
renderHandler.render(tile, tile, slot, brightness, partialTickTime);
}
GL11.glPushMatrix();
@@ -582,7 +598,7 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer {
if (skipRenderHook || !ForgeHooksClient
.renderInventoryItem(this.renderBlocks, mc.renderEngine, itemStack, true, 0, 0, 0))
itemRenderer.renderItemIntoGUI(mc.fontRenderer, mc.renderEngine, itemStack, 0, 0, true);
} catch (Exception e) {}
} catch (Exception ignored) {}
GL11.glPopMatrix();
}
@@ -607,33 +623,23 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer {
}
private float getXOffset(int drawerCount, int slot) {
switch (drawerCount) {
case 1:
return 0.5f;
case 2:
return itemOffset2X[slot];
case 3:
return itemOffset3X[slot];
case 4:
return itemOffset4X[slot];
default:
return 0;
}
return switch (drawerCount) {
case 1 -> 0.5f;
case 2 -> itemOffset2X[slot];
case 3 -> itemOffset3X[slot];
case 4 -> itemOffset4X[slot];
default -> 0;
};
}
private float getYOffset(int drawerCount, int slot) {
switch (drawerCount) {
case 1:
return 8.25f;
case 2:
return itemOffset2Y[slot];
case 3:
return itemOffset3Y[slot];
case 4:
return itemOffset4Y[slot];
default:
return 0;
}
return switch (drawerCount) {
case 1 -> 8.25f;
case 2 -> itemOffset2Y[slot];
case 3 -> itemOffset3Y[slot];
case 4 -> itemOffset4Y[slot];
default -> 0;
};
}
private void alignRendering(ForgeDirection side) {
@@ -11,21 +11,20 @@ import com.jaquadro.minecraft.storagedrawers.util.RenderHelperState;
public class CommonDrawerRenderer {
private static final double UNIT_7_16 = 0.4375;
private static final double UNIT_9_16 = 0.5625;
private PanelBoxRenderer panelRenderer = new PanelBoxRenderer();
private double depth;
private double trimWidth;
private double trimDepth;
private static double unit7 = 0.4375;
private static double unit9 = 0.5625;
private RenderHelper start(IBlockAccess world, int x, int y, int z, BlockDrawersCustom block, int direction) {
private RenderHelper start(IBlockAccess world, int x, int y, int z, BlockDrawersCustom block, int direction,
int rotation) {
depth = block.halfDepth ? .5 : 0;
trimWidth = block.getTrimWidth();
trimDepth = block.getTrimDepth();
unit7 = 0.4375;
unit9 = 0.5625;
panelRenderer.setTrimWidth(trimWidth);
panelRenderer.setTrimDepth(0);
@@ -35,10 +34,16 @@ public class CommonDrawerRenderer {
RenderHelper renderHelper = RenderHelper.instances.get();
if (world != null) renderHelper.setColorAndBrightness(world, block, x, y, z);
renderHelper.state.setRotateTransform(RenderHelper.ZNEG, direction);
renderHelper.state.setUVRotation(
RenderHelper.YPOS,
RenderHelperState.ROTATION_BY_FACE_FACE[RenderHelper.ZNEG][direction]);
renderHelper.state.setOrientation(RenderHelper.ZNEG, direction, rotation);
if (direction > 1) {
renderHelper.state.setUVRotation(
RenderHelper.YPOS,
RenderHelperState.ROTATION_BY_FACE_FACE[RenderHelper.ZNEG][direction]);
} else if (direction == RenderHelper.YPOS) {
renderHelper.state.setUVRotation(RenderHelper.YPOS, (4 - rotation) % 4);
} else {
renderHelper.state.setUVRotation(RenderHelper.YNEG, (rotation + 2) % 4);
}
return renderHelper;
}
@@ -48,11 +53,29 @@ public class CommonDrawerRenderer {
renderHelper.state.clearRotateTransform();
renderHelper.state.clearUVRotation(RenderHelper.YPOS);
renderHelper.state.clearUVRotation(RenderHelper.YNEG);
}
private void renderFrontFace(RenderHelper renderHelper, IBlockAccess world, int x, int y, int z,
BlockDrawersCustom block, double xMin, double yMin, double xMax, double yMax, IIcon icon) {
renderHelper.setRenderBounds(xMin, yMin, depth + trimDepth, xMax, yMax, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, icon);
}
private void renderFrontOverlay(RenderHelper renderHelper, IBlockAccess world, int x, int y, int z,
BlockDrawersCustom block, double xMin, double yMin, double xMax, double yMax) {
renderFrontFace(renderHelper, world, x, y, z, block, xMin, yMin, xMax, yMax, block.getHandleOverlay());
renderFrontFace(renderHelper, world, x, y, z, block, xMin, yMin, xMax, yMax, block.getFaceShadowOverlay());
}
public void renderBasePass(IBlockAccess world, int x, int y, int z, BlockDrawersCustom block, int direction,
IIcon iconSide, IIcon iconTrim, IIcon iconFront) {
RenderHelper renderHelper = start(world, x, y, z, block, direction);
renderBasePass(world, x, y, z, block, direction, 0, iconSide, iconTrim, iconFront);
}
public void renderBasePass(IBlockAccess world, int x, int y, int z, BlockDrawersCustom block, int direction,
int rotation, IIcon iconSide, IIcon iconTrim, IIcon iconFront) {
RenderHelper renderHelper = start(world, x, y, z, block, direction, rotation);
panelRenderer.setTrimIcon(iconTrim);
panelRenderer.setPanelIcon(iconSide);
@@ -66,37 +89,122 @@ public class CommonDrawerRenderer {
panelRenderer.renderInteriorTrim(RenderHelper.ZNEG, world, block, x, y, z, 0, 0, depth, 1, 1, 1);
if (block.drawerCount == 1) {
renderHelper.setRenderBounds(trimWidth, trimWidth, depth + trimDepth, 1 - trimWidth, 1 - trimWidth, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconFront);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
trimWidth,
trimWidth,
1 - trimWidth,
1 - trimWidth,
iconFront);
} else if (block.drawerCount == 2) {
renderHelper.setRenderBounds(trimWidth, trimWidth, depth + trimDepth, 1 - trimWidth, unit7, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconFront);
renderHelper.setRenderBounds(trimWidth, unit9, depth + trimDepth, 1 - trimWidth, 1 - trimWidth, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconFront);
renderHelper.setRenderBounds(trimWidth, unit7, depth + trimDepth, 1 - trimWidth, unit9, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconTrim);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
trimWidth,
trimWidth,
1 - trimWidth,
UNIT_7_16,
iconFront);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
trimWidth,
UNIT_9_16,
1 - trimWidth,
1 - trimWidth,
iconFront);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
trimWidth,
UNIT_7_16,
1 - trimWidth,
UNIT_9_16,
iconTrim);
} else if (block.drawerCount == 4) {
renderHelper.state.flipTexture = true;
renderHelper.setRenderBounds(trimWidth, trimWidth, depth + trimDepth, unit7, unit7, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconFront);
renderHelper.setRenderBounds(trimWidth, unit9, depth + trimDepth, unit7, 1 - trimWidth, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconFront);
renderHelper.setRenderBounds(unit9, trimWidth, depth + trimDepth, 1 - trimWidth, unit7, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconFront);
renderHelper.setRenderBounds(unit9, unit9, depth + trimDepth, 1 - trimWidth, 1 - trimWidth, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconFront);
renderFrontFace(renderHelper, world, x, y, z, block, trimWidth, trimWidth, UNIT_7_16, UNIT_7_16, iconFront);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
trimWidth,
UNIT_9_16,
UNIT_7_16,
1 - trimWidth,
iconFront);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
UNIT_9_16,
trimWidth,
1 - trimWidth,
UNIT_7_16,
iconFront);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
UNIT_9_16,
UNIT_9_16,
1 - trimWidth,
1 - trimWidth,
iconFront);
renderHelper.setRenderBounds(trimWidth, unit7, depth + trimDepth, unit7, unit9, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconTrim);
renderHelper.setRenderBounds(unit9, unit7, depth + trimDepth, 1 - trimWidth, unit9, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconTrim);
renderHelper.setRenderBounds(unit7, trimWidth, depth + trimDepth, unit9, unit7, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconTrim);
renderHelper.setRenderBounds(unit7, unit9, depth + trimDepth, unit9, 1 - trimWidth, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconTrim);
renderHelper.setRenderBounds(unit7, unit7, depth + trimDepth, unit9, unit9, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, iconTrim);
renderFrontFace(renderHelper, world, x, y, z, block, trimWidth, UNIT_7_16, UNIT_7_16, UNIT_9_16, iconTrim);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
UNIT_9_16,
UNIT_7_16,
1 - trimWidth,
UNIT_9_16,
iconTrim);
renderFrontFace(renderHelper, world, x, y, z, block, UNIT_7_16, trimWidth, UNIT_9_16, UNIT_7_16, iconTrim);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
UNIT_7_16,
UNIT_9_16,
UNIT_9_16,
1 - trimWidth,
iconTrim);
renderFrontFace(renderHelper, world, x, y, z, block, UNIT_7_16, UNIT_7_16, UNIT_9_16, UNIT_9_16, iconTrim);
renderHelper.state.flipTexture = false;
}
@@ -105,7 +213,12 @@ public class CommonDrawerRenderer {
public void renderOverlayPass(IBlockAccess world, int x, int y, int z, BlockDrawersCustom block, int direction,
IIcon iconTrim, IIcon iconFront) {
RenderHelper renderHelper = start(world, x, y, z, block, direction);
renderOverlayPass(world, x, y, z, block, direction, 0, iconTrim, iconFront);
}
public void renderOverlayPass(IBlockAccess world, int x, int y, int z, BlockDrawersCustom block, int direction,
int rotation, IIcon iconTrim, IIcon iconFront) {
RenderHelper renderHelper = start(world, x, y, z, block, direction, rotation);
IIcon trimShadow = block.getTrimShadowOverlay(iconTrim == iconFront);
@@ -113,47 +226,88 @@ public class CommonDrawerRenderer {
panelRenderer.renderFaceTrim(RenderHelper.ZNEG, world, block, x, y, z, 0, 0, depth, 1, 1, 1);
if (block.drawerCount == 1) {
renderHelper.setRenderBounds(trimWidth, trimWidth, depth + trimDepth, 1 - trimWidth, 1 - trimWidth, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getHandleOverlay());
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getFaceShadowOverlay());
renderFrontOverlay(renderHelper, world, x, y, z, block, trimWidth, trimWidth, 1 - trimWidth, 1 - trimWidth);
} else if (block.drawerCount == 2) {
renderHelper.setRenderBounds(trimWidth, trimWidth, depth + trimDepth, 1 - trimWidth, unit7, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getHandleOverlay());
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getFaceShadowOverlay());
renderHelper.setRenderBounds(trimWidth, unit9, depth + trimDepth, 1 - trimWidth, 1 - trimWidth, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getHandleOverlay());
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getFaceShadowOverlay());
renderHelper.setRenderBounds(trimWidth, unit7, depth + trimDepth, 1 - trimWidth, unit9, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, trimShadow);
renderFrontOverlay(renderHelper, world, x, y, z, block, trimWidth, trimWidth, 1 - trimWidth, UNIT_7_16);
renderFrontOverlay(renderHelper, world, x, y, z, block, trimWidth, UNIT_9_16, 1 - trimWidth, 1 - trimWidth);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
trimWidth,
UNIT_7_16,
1 - trimWidth,
UNIT_9_16,
trimShadow);
} else if (block.drawerCount == 4) {
renderHelper.setRenderBounds(trimWidth, trimWidth, depth + trimDepth, unit7, unit7, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getHandleOverlay());
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getFaceShadowOverlay());
renderFrontOverlay(renderHelper, world, x, y, z, block, trimWidth, trimWidth, UNIT_7_16, UNIT_7_16);
renderFrontOverlay(renderHelper, world, x, y, z, block, trimWidth, UNIT_9_16, UNIT_7_16, 1 - trimWidth);
renderFrontOverlay(renderHelper, world, x, y, z, block, UNIT_9_16, trimWidth, 1 - trimWidth, UNIT_7_16);
renderFrontOverlay(renderHelper, world, x, y, z, block, UNIT_9_16, UNIT_9_16, 1 - trimWidth, 1 - trimWidth);
renderHelper.setRenderBounds(trimWidth, unit9, depth + trimDepth, unit7, 1 - trimWidth, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getHandleOverlay());
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getFaceShadowOverlay());
renderHelper.setRenderBounds(unit9, trimWidth, depth + trimDepth, 1 - trimWidth, unit7, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getHandleOverlay());
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getFaceShadowOverlay());
renderHelper.setRenderBounds(unit9, unit9, depth + trimDepth, 1 - trimWidth, 1 - trimWidth, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getHandleOverlay());
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, block.getFaceShadowOverlay());
renderHelper.setRenderBounds(trimWidth, unit7, depth + trimDepth, unit7, unit9, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, trimShadow);
renderHelper.setRenderBounds(unit9, unit7, depth + trimDepth, 1 - trimWidth, unit9, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, trimShadow);
renderHelper.setRenderBounds(unit7, trimWidth, depth + trimDepth, unit9, unit7, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, trimShadow);
renderHelper.setRenderBounds(unit7, unit9, depth + trimDepth, unit9, 1 - trimWidth, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, trimShadow);
renderHelper.setRenderBounds(unit7, unit7, depth + trimDepth, unit9, unit9, 1);
renderHelper.renderFace(RenderHelper.ZNEG, world, block, x, y, z, trimShadow);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
trimWidth,
UNIT_7_16,
UNIT_7_16,
UNIT_9_16,
trimShadow);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
UNIT_9_16,
UNIT_7_16,
1 - trimWidth,
UNIT_9_16,
trimShadow);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
UNIT_7_16,
trimWidth,
UNIT_9_16,
UNIT_7_16,
trimShadow);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
UNIT_7_16,
UNIT_9_16,
UNIT_9_16,
1 - trimWidth,
trimShadow);
renderFrontFace(
renderHelper,
world,
x,
y,
z,
block,
UNIT_7_16,
UNIT_7_16,
UNIT_9_16,
UNIT_9_16,
trimShadow);
} else RenderHelper.instances.get().renderEmptyPlane(x, y, z);
end();
@@ -34,8 +34,6 @@ public class ItemCompDrawers extends ItemDrawers {
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("tile"))
tile.readFromPortableNBT(stack.getTagCompound().getCompoundTag("tile"));
if (side > 1) tile.setDirection(side);
tile.setIsSealed(false);
}
@@ -10,6 +10,7 @@ import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityController;
import com.jaquadro.minecraft.storagedrawers.util.DrawerOrientation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -27,7 +28,9 @@ public class ItemController extends ItemBlock {
TileEntityController tile = (TileEntityController) world.getTileEntity(x, y, z);
if (tile != null) {
if (side > 1) tile.setDirection(side);
DrawerOrientation orientation = DrawerOrientation.forEntity(player);
tile.setDirection(orientation.direction());
tile.setRotation(orientation.rotation());
}
return true;
@@ -24,6 +24,7 @@ import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandard;
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
import com.jaquadro.minecraft.storagedrawers.core.ModItems;
import com.jaquadro.minecraft.storagedrawers.util.DrawerOrientation;
import com.jaquadro.minecraft.storagedrawers.util.ItemStackConversion;
import cpw.mods.fml.relauncher.Side;
@@ -52,7 +53,9 @@ public class ItemDrawers extends ItemBlock {
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("tile"))
tile.readFromPortableNBT(stack.getTagCompound().getCompoundTag("tile"));
if (side > 1) tile.setDirection(side);
DrawerOrientation orientation = DrawerOrientation.forEntity(player);
tile.setDirection(orientation.direction());
tile.setRotation(orientation.rotation());
tile.setIsSealed(false);
}
@@ -51,7 +51,8 @@ public abstract class MixinPlayerControllerMP {
float hitX = (float) (mop.hitVec.xCoord - mop.blockX);
float hitY = (float) (mop.hitVec.yCoord - mop.blockY);
float hitZ = (float) (mop.hitVec.zCoord - mop.blockZ);
IDrawer clickedDrawer = drawer.getDrawer(blockDrawer.getDrawerSlot(clickedSide, hitX, hitY, hitZ));
IDrawer clickedDrawer = drawer
.getDrawer(blockDrawer.getDrawerSlot(clickedSide, drawer.getRotation(), hitX, hitY, hitZ));
if (clickedDrawer == null || clickedDrawer.isEmpty()) {
return originalHardness;
}
@@ -70,4 +71,37 @@ public abstract class MixinPlayerControllerMP {
private void storageDrawers$resetHoldingClick(CallbackInfo ci) {
this.storageDrawers$isHoldingClick = false;
}
@Inject(method = "clickBlock", at = @At(value = "HEAD"), cancellable = true)
private void storageDrawers$creativeClickDrawer(int x, int y, int z, int clickedSide, CallbackInfo ci) {
if (mc.thePlayer == null || !mc.thePlayer.capabilities.isCreativeMode) return;
final TileEntity thisTile = mc.theWorld.getTileEntity(x, y, z);
final Block thisBlock = mc.theWorld.getBlock(x, y, z);
if (!(thisBlock instanceof BlockDrawers blockDrawer) || !(thisTile instanceof TileEntityDrawers drawer)
|| drawer.getDirection() != clickedSide) {
return;
}
// Creative left-click would instantly destroy the block; intercept clicks on the drawer front so the gesture
// takes items (like survival) instead. The break itself is already prevented by ForgeEventHandler, so an empty
// slot simply does nothing here.
MovingObjectPosition mop = mc.objectMouseOver;
float hitX = (float) (mop.hitVec.xCoord - mop.blockX);
float hitY = (float) (mop.hitVec.yCoord - mop.blockY);
float hitZ = (float) (mop.hitVec.zCoord - mop.blockZ);
IDrawer clickedDrawer = drawer
.getDrawer(blockDrawer.getDrawerSlot(clickedSide, drawer.getRotation(), hitX, hitY, hitZ));
if (clickedDrawer == null || clickedDrawer.isEmpty()) {
ci.cancel();
return;
}
boolean invertShift = StorageDrawers.config.cache.invertShift;
StorageDrawers.network
.sendToServer(new BlockClickMessage(x, y, z, clickedSide, hitX, hitY, hitZ, invertShift, false));
ci.cancel();
}
}
@@ -0,0 +1,58 @@
package com.jaquadro.minecraft.storagedrawers.util;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.MathHelper;
/**
* Resolved placement orientation of a drawer block.
*
* <p>
* {@code direction} is a {@link net.minecraftforge.common.util.ForgeDirection} ordinal (0-5) describing the face the
* drawer front points toward. {@code rotation} is the horizontal spin (0-3, quarter turns) applied around that face; it
* is only meaningful when the front points up or down, and stays 0 for horizontal placements so their saved data and
* rendering remain unchanged.
*/
public class DrawerOrientation {
/** Minimum pitch magnitude in degrees required to place facing up or down. */
private static final float VERTICAL_PITCH_THRESHOLD = 65f;
private final int direction;
private final int rotation;
public DrawerOrientation(int direction, int rotation) {
this.direction = direction;
this.rotation = rotation;
}
public int direction() {
return direction;
}
public int rotation() {
return rotation;
}
/**
* Computes the orientation a drawer should take when placed by the given entity, based entirely on where the entity
* is looking rather than which block face was clicked.
*/
public static DrawerOrientation forEntity(EntityLivingBase entity) {
int quadrant = MathHelper.floor_double((entity.rotationYaw * 4f / 360f) + 0.5) & 3;
int horizontal = switch (quadrant) {
case 0 -> 2;
case 1 -> 5;
case 2 -> 3;
default -> 4;
};
float pitch = entity.rotationPitch;
// Looking up places the drawer overhead with its front pointing back down at the player; looking down places it
// underfoot facing up. The spin is chosen so the front's bottom edge faces the player (matching how a
// horizontal drawer's bottom points down), derived from the rigid render tilt.
if (pitch < -VERTICAL_PITCH_THRESHOLD) return new DrawerOrientation(0, (4 - quadrant) % 4);
if (pitch > VERTICAL_PITCH_THRESHOLD) return new DrawerOrientation(1, (2 - quadrant + 4) % 4);
return new DrawerOrientation(horizontal, 0);
}
}
@@ -148,7 +148,7 @@ public class RenderHelper {
float r, float g, float b) {
setupColorMult(face, blockAccess, block, x, y, z, r, g, b);
face = RenderHelperState.FACE_BY_FACE_ROTATION[face][state.rotateTransform];
face = state.mapFace(face);
llHelper.drawFace(face, x, y, z, icon);
if (blockAccess == null) Tessellator.instance.draw();
@@ -158,7 +158,7 @@ public class RenderHelper {
float r, float g, float b) {
state.enableAO = true;
face = RenderHelperState.FACE_BY_FACE_ROTATION[face][state.rotateTransform];
face = state.mapFace(face);
switch (face) {
case YNEG:
@@ -234,7 +234,7 @@ public class RenderHelper {
IIcon icon, double uMin, double vMin, double uMax, double vMax, float r, float g, float b) {
state.enableAO = true;
switch (RenderHelperState.FACE_BY_FACE_ROTATION[face][state.rotateTransform]) {
switch (state.mapFace(face)) {
case YNEG:
aoHelper.setupYNegAOPartial(blockAccess, block, x, y, z, r, g, b);
break;
@@ -261,13 +261,13 @@ public class RenderHelper {
public void renderPartialFace(int face, IIcon icon, double uMin, double vMin, double uMax, double vMax) {
state.enableAO = false;
face = RenderHelperState.FACE_BY_FACE_ROTATION[face][state.rotateTransform];
face = state.mapFace(face);
llHelper.drawPartialFace(face, 0, 0, 0, icon, uMin, vMin, uMax, vMax);
}
public void renderPartialFace(int face, double x, double y, double z, IIcon icon, double uMin, double vMin,
double uMax, double vMax) {
face = RenderHelperState.FACE_BY_FACE_ROTATION[face][state.rotateTransform];
face = state.mapFace(face);
llHelper.drawPartialFace(face, x, y, z, icon, uMin, vMin, uMax, vMax);
}
@@ -355,10 +355,73 @@ public class RenderHelperLL {
public void drawPartialFace(int face, double x, double y, double z, IIcon icon, double uMin, double vMin,
double uMax, double vMax) {
setXYZ(x, y, z);
int rotate = state.uvRotate[face];
if (rotate == RenderHelperState.ROTATE180) {
setUV(icon, uMax, uMin, vMax, vMin);
if (state.enableAO) renderXYZUVAO(xyzuvMap[face], RenderHelperState.ROTATE0);
else renderXYZUV(xyzuvMap[face], RenderHelperState.ROTATE0);
return;
}
setUV(icon, uMin, uMax, vMin, vMax);
if (state.enableAO) renderXYZUVAO(xyzuvMap[face], state.uvRotate[face]);
else renderXYZUV(xyzuvMap[face], state.uvRotate[face]);
if (rotate == RenderHelperState.ROTATE90) {
if (state.enableAO)
renderXYZUVCustomAOPartial(xyzuvMap[face], uv[1], uv[2], uv[0], uv[2], uv[0], uv[3], uv[1], uv[3]);
else renderXYZUVCustomPartial(xyzuvMap[face], uv[1], uv[2], uv[0], uv[2], uv[0], uv[3], uv[1], uv[3]);
return;
}
if (rotate == RenderHelperState.ROTATE270) {
if (state.enableAO)
renderXYZUVCustomAOPartial(xyzuvMap[face], uv[0], uv[3], uv[1], uv[3], uv[1], uv[2], uv[0], uv[2]);
else renderXYZUVCustomPartial(xyzuvMap[face], uv[0], uv[3], uv[1], uv[3], uv[1], uv[2], uv[0], uv[2]);
return;
}
if (state.enableAO) renderXYZUVAO(xyzuvMap[face], rotate);
else renderXYZUV(xyzuvMap[face], rotate);
}
private void renderXYZUVCustomPartial(int[][] index, double tlU, double tlV, double blU, double blV, double brU,
double brV, double trU, double trV) {
Tessellator tessellator = Tessellator.instance;
int[] tl = index[TL];
int[] bl = index[BL];
int[] br = index[BR];
int[] tr = index[TR];
tessellator.addVertexWithUV(xyz[tl[0]], xyz[tl[1]], xyz[tl[2]], tlU, tlV);
tessellator.addVertexWithUV(xyz[bl[0]], xyz[bl[1]], xyz[bl[2]], blU, blV);
tessellator.addVertexWithUV(xyz[br[0]], xyz[br[1]], xyz[br[2]], brU, brV);
tessellator.addVertexWithUV(xyz[tr[0]], xyz[tr[1]], xyz[tr[2]], trU, trV);
}
private void renderXYZUVCustomAOPartial(int[][] index, double tlU, double tlV, double blU, double blV, double brU,
double brV, double trU, double trV) {
Tessellator tessellator = Tessellator.instance;
int[] tl = index[TL];
int[] bl = index[BL];
int[] br = index[BR];
int[] tr = index[TR];
tessellator.setColorOpaque_F(state.colorTopLeft[0], state.colorTopLeft[1], state.colorTopLeft[2]);
tessellator.setBrightness(state.brightnessTopLeft);
tessellator.addVertexWithUV(xyz[tl[0]], xyz[tl[1]], xyz[tl[2]], tlU, tlV);
tessellator.setColorOpaque_F(state.colorBottomLeft[0], state.colorBottomLeft[1], state.colorBottomLeft[2]);
tessellator.setBrightness(state.brightnessBottomLeft);
tessellator.addVertexWithUV(xyz[bl[0]], xyz[bl[1]], xyz[bl[2]], blU, blV);
tessellator.setColorOpaque_F(state.colorBottomRight[0], state.colorBottomRight[1], state.colorBottomRight[2]);
tessellator.setBrightness(state.brightnessBottomRight);
tessellator.addVertexWithUV(xyz[br[0]], xyz[br[1]], xyz[br[2]], brU, brV);
tessellator.setColorOpaque_F(state.colorTopRight[0], state.colorTopRight[1], state.colorTopRight[2]);
tessellator.setBrightness(state.brightnessTopRight);
tessellator.addVertexWithUV(xyz[tr[0]], xyz[tr[1]], xyz[tr[2]], trU, trV);
}
private void setupUVPoints(double uStart, double vStart, double uStop, double vStop, int rangeU, int rangeV,
@@ -7,12 +7,28 @@ public class RenderHelperState {
public static final int ROTATE180 = 2;
public static final int ROTATE270 = 3;
public static final int TILT_NONE = 0;
public static final int TILT_DOWN = 1;
public static final int TILT_UP = 2;
public static final int[][] ROTATION_BY_FACE_FACE = { { 0, 0, 0, 2, 1, 3 }, { 0, 0, 0, 2, 3, 1 },
{ 0, 0, 0, 2, 3, 1 }, { 0, 0, 2, 0, 1, 3 }, { 0, 0, 1, 3, 0, 2 }, { 0, 0, 3, 1, 2, 0 }, };
public static final int[][] FACE_BY_FACE_ROTATION = { { 0, 0, 0, 0 }, { 1, 1, 1, 1 }, { 2, 5, 3, 4 },
{ 3, 4, 2, 5 }, { 4, 2, 5, 3 }, { 5, 3, 4, 2 }, };
// Face normals indexed by face (YNEG, YPOS, ZNEG, ZPOS, XNEG, XPOS).
private static final int[][] FACE_NORMAL = { { 0, -1, 0 }, { 0, 1, 0 }, { 0, 0, -1 }, { 0, 0, 1 }, { -1, 0, 0 },
{ 1, 0, 0 }, };
private static final int[] IDENTITY = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
// Quarter-turn about the Y axis, matching the legacy transformCoord rotation by ROTATE90.
private static final int[] ROT_Y90 = { 0, 0, -1, 0, 1, 0, 1, 0, 0 };
// Quarter-turn about the X axis (sends +Z to -Y).
private static final int[] ROT_X90 = { 1, 0, 0, 0, 0, -1, 0, 1, 0 };
private static final int[][] ROT_Y_POWERS = buildRotationPowers(ROT_Y90);
private static final int[][] ROT_X_POWERS = buildRotationPowers(ROT_X90);
public double renderMinX;
public double renderMinY;
public double renderMinZ;
@@ -29,6 +45,10 @@ public class RenderHelperState {
public boolean enableAO;
public int rotateTransform;
public int tilt;
private final int[] orient = IDENTITY.clone();
private final int[] orientInv = IDENTITY.clone();
public float shiftU;
public float shiftV;
@@ -67,7 +87,11 @@ public class RenderHelperState {
renderMaxY = yMax;
renderMaxZ = zMax;
if (rotateTransform != 0) transformRenderBound(rotateTransform);
if (tilt == TILT_NONE) {
if (rotateTransform != 0) transformRenderBound(rotateTransform);
} else {
transformRenderBoundMatrix();
}
}
public void setRenderOffset(double xOffset, double yOffset, double zOffset) {
@@ -75,7 +99,11 @@ public class RenderHelperState {
renderOffsetY = yOffset;
renderOffsetZ = zOffset;
if (rotateTransform != 0) transformRenderOffset(rotateTransform);
if (tilt == TILT_NONE) {
if (rotateTransform != 0) transformRenderOffset(rotateTransform);
} else {
transformRenderOffsetMatrix();
}
}
public void clearRenderOffset() {
@@ -103,22 +131,15 @@ public class RenderHelperState {
}
public float getColorMult(int side) {
switch (side) {
case 0:
return colorMultYNeg;
case 1:
return colorMultYPos;
case 2:
return colorMultZNeg;
case 3:
return colorMultZPos;
case 4:
return colorMultXNeg;
case 5:
return colorMultXPos;
default:
return 0;
}
return switch (side) {
case 0 -> colorMultYNeg;
case 1 -> colorMultYPos;
case 2 -> colorMultZNeg;
case 3 -> colorMultZPos;
case 4 -> colorMultXNeg;
case 5 -> colorMultXPos;
default -> 0;
};
}
public void setTextureOffset(float u, float v) {
@@ -162,23 +183,142 @@ public class RenderHelperState {
}
public void setRotateTransform(int faceFrom, int faceTo) {
rotateTransform = ROTATION_BY_FACE_FACE[faceFrom][faceTo];
if (rotateTransform != 0) {
transformRenderBound(rotateTransform);
transformRenderOffset(rotateTransform);
setOrientation(faceFrom, faceTo, 0);
}
/**
* Configures the geometry transform that maps the canonical drawer (front facing {@code faceFrom}) onto a block
* whose front points toward {@code direction}, spun by {@code rotation} quarter turns. Horizontal directions use
* the legacy Y-rotation path unchanged; up/down directions use a general integer rotation matrix.
*/
public void setOrientation(int faceFrom, int direction, int rotation) {
if (direction > 1) {
tilt = TILT_NONE;
rotateTransform = ROTATION_BY_FACE_FACE[faceFrom][direction];
if (rotateTransform != 0) {
transformRenderBound(rotateTransform);
transformRenderOffset(rotateTransform);
}
return;
}
tilt = (direction == 1) ? TILT_UP : TILT_DOWN;
rotateTransform = 0;
buildOrientation(faceFrom, direction, rotation);
}
public void undoRotateTransform() {
if (rotateTransform != 0) {
transformRenderBound(4 - rotateTransform);
transformRenderOffset(4 - rotateTransform);
if (tilt == TILT_NONE) {
if (rotateTransform != 0) {
transformRenderBound(4 - rotateTransform);
transformRenderOffset(4 - rotateTransform);
}
}
clearRotateTransform();
}
public void clearRotateTransform() {
rotateTransform = 0;
tilt = TILT_NONE;
System.arraycopy(IDENTITY, 0, orient, 0, 9);
System.arraycopy(IDENTITY, 0, orientInv, 0, 9);
}
/**
* Builds the orientation matrix for a vertical placement: tilt the canonical front to vertical, then spin about the
* (now vertical) face normal.
*/
private void buildOrientation(int faceFrom, int direction, int rotation) {
int[] tiltMatrix;
if (faceFrom == RenderHelper.ZPOS) tiltMatrix = (direction == 1) ? rotXPow(3) : rotXPow(1);
else tiltMatrix = (direction == 1) ? rotXPow(1) : rotXPow(3);
int[] spin = rotYPow(((rotation % 4) + 4) % 4);
matMul(spin, tiltMatrix, orient);
transpose(orient, orientInv);
transformRenderBoundMatrix();
transformRenderOffsetMatrix();
}
/** Maps a canonical face to the world face it occupies under the current orientation. */
public int mapFace(int face) {
if (tilt == TILT_NONE) return FACE_BY_FACE_ROTATION[face][rotateTransform];
int[] n = FACE_NORMAL[face];
int nx = orient[0] * n[0] + orient[1] * n[1] + orient[2] * n[2];
int ny = orient[3] * n[0] + orient[4] * n[1] + orient[5] * n[2];
int nz = orient[6] * n[0] + orient[7] * n[1] + orient[8] * n[2];
return faceForNormal(nx, ny, nz);
}
private static int faceForNormal(int x, int y, int z) {
if (y < 0) return RenderHelper.YNEG;
if (y > 0) return RenderHelper.YPOS;
if (z < 0) return RenderHelper.ZNEG;
if (z > 0) return RenderHelper.ZPOS;
if (x < 0) return RenderHelper.XNEG;
return RenderHelper.XPOS;
}
private static int[] rotYPow(int times) {
return ROT_Y_POWERS[normalizeQuarterTurn(times)];
}
private static int[] rotXPow(int times) {
return ROT_X_POWERS[normalizeQuarterTurn(times)];
}
private static int[][] buildRotationPowers(int[] quarterTurn) {
int[][] powers = new int[4][9];
System.arraycopy(IDENTITY, 0, powers[0], 0, 9);
for (int i = 1; i < powers.length; i++) matMul(quarterTurn, powers[i - 1], powers[i]);
return powers;
}
private static int normalizeQuarterTurn(int times) {
int normalized = times % 4;
return normalized >= 0 ? normalized : normalized + 4;
}
private static void matMul(int[] a, int[] b, int[] out) {
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
out[row * 3 + col] = a[row * 3] * b[col] + a[row * 3 + 1] * b[3 + col] + a[row * 3 + 2] * b[6 + col];
}
}
}
private static void transpose(int[] in, int[] out) {
for (int row = 0; row < 3; row++) for (int col = 0; col < 3; col++) out[col * 3 + row] = in[row * 3 + col];
}
private void applyOrient(double x, double y, double z, double[] out) {
double cx = x - 0.5, cy = y - 0.5, cz = z - 0.5;
out[0] = orient[0] * cx + orient[1] * cy + orient[2] * cz + 0.5;
out[1] = orient[3] * cx + orient[4] * cy + orient[5] * cz + 0.5;
out[2] = orient[6] * cx + orient[7] * cy + orient[8] * cz + 0.5;
}
private void transformRenderBoundMatrix() {
applyOrient(renderMinX, renderMinY, renderMinZ, scratchOut);
double aX = scratchOut[0], aY = scratchOut[1], aZ = scratchOut[2];
applyOrient(renderMaxX, renderMaxY, renderMaxZ, scratchOut);
double bX = scratchOut[0], bY = scratchOut[1], bZ = scratchOut[2];
renderMinX = Math.min(aX, bX);
renderMaxX = Math.max(aX, bX);
renderMinY = Math.min(aY, bY);
renderMaxY = Math.max(aY, bY);
renderMinZ = Math.min(aZ, bZ);
renderMaxZ = Math.max(aZ, bZ);
}
private void transformRenderOffsetMatrix() {
double ox = renderOffsetX, oy = renderOffsetY, oz = renderOffsetZ;
renderOffsetX = orient[0] * ox + orient[1] * oy + orient[2] * oz;
renderOffsetY = orient[3] * ox + orient[4] * oy + orient[5] * oz;
renderOffsetZ = orient[6] * ox + orient[7] * oy + orient[8] * oz;
}
private void transformRenderOffset(int rotation) {