From e4ea5b5fb974d44f8c73119ef876502359065a22 Mon Sep 17 00:00:00 2001 From: koolkrafter5 Date: Tue, 27 May 2025 15:41:34 -0400 Subject: [PATCH] The items rendered in casting tables and basins can now face all four cardinal directions rather than just one hard-coded direction. The direction chosen is based on the direction the player is facing when placing the block (the value is saved to the TE's NBT). --- .../smeltery/logic/CastingBlockLogic.java | 35 +++++++++++++++++-- .../model/CastingBasinSpecialRender.java | 13 +++++-- .../model/CastingTableSpecialRenderer.java | 25 +++++++++++-- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java b/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java index 521e843e..123b2097 100644 --- a/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java +++ b/src/main/java/tconstruct/smeltery/logic/CastingBlockLogic.java @@ -1,5 +1,6 @@ package tconstruct.smeltery.logic; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; @@ -9,6 +10,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; @@ -21,6 +23,7 @@ import net.minecraftforge.fluids.IFluidTank; import cpw.mods.fml.common.eventhandler.Event; import mantle.blocks.abstracts.InventoryLogic; +import mantle.blocks.iface.IFacingLogic; import tconstruct.TConstruct; import tconstruct.library.crafting.CastingRecipe; import tconstruct.library.crafting.LiquidCasting; @@ -30,9 +33,11 @@ import tconstruct.library.event.SmelteryEvent; import tconstruct.library.tools.AbilityHelper; import tconstruct.library.util.IPattern; -public abstract class CastingBlockLogic extends InventoryLogic implements IFluidTank, IFluidHandler, ISidedInventory { +public abstract class CastingBlockLogic extends InventoryLogic + implements IFluidTank, IFluidHandler, ISidedInventory, IFacingLogic { public FluidStack liquid; + protected byte direction; protected int maxCastingDelay = 0; protected int castingDelay = 0; protected int renderOffset = 0; @@ -289,7 +294,7 @@ public abstract class CastingBlockLogic extends InventoryLogic implements IFluid player); MinecraftForge.EVENT_BUS.post(event); - // try to transfer thes tack to the player inventory + // try to transfer the stack to the player inventory ItemStack output = event.item; AbilityHelper.spawnItemAtPlayer(player, output); @@ -431,6 +436,7 @@ public abstract class CastingBlockLogic extends InventoryLogic implements IFluid this.castingDelay = tags.getInteger("castingDelay"); this.maxCastingDelay = tags.getInteger("maxCastingDelay"); this.renderOffset = tags.getInteger("RenderOffset"); + this.direction = tags.getByte("direction"); } @Override @@ -451,6 +457,7 @@ public abstract class CastingBlockLogic extends InventoryLogic implements IFluid tags.setInteger("castingDelay", castingDelay); tags.setInteger("maxCastingDelay", maxCastingDelay); tags.setInteger("RenderOffset", renderOffset); + tags.setByte("direction", direction); } /* Packets */ @@ -474,4 +481,28 @@ public abstract class CastingBlockLogic extends InventoryLogic implements IFluid return (int) (((maxCastingDelay - castingDelay) / (double) maxCastingDelay) * 100); } + + @Override + public byte getRenderDirection() { + return direction; + } + + @Override + public ForgeDirection getForgeDirection() { + return ForgeDirection.VALID_DIRECTIONS[direction]; + } + + @Override + public void setDirection(int side) {} + + @Override + public void setDirection(float yaw, float pitch, EntityLivingBase player) { + int facing = MathHelper.floor_double((double) (yaw / 360) + 0.5D) & 3; + switch (facing) { + case 1 -> direction = 5; + case 2 -> direction = 3; + case 3 -> direction = 4; + default -> direction = 2; + } + } } diff --git a/src/main/java/tconstruct/smeltery/model/CastingBasinSpecialRender.java b/src/main/java/tconstruct/smeltery/model/CastingBasinSpecialRender.java index 14c68c9b..a8df2114 100644 --- a/src/main/java/tconstruct/smeltery/model/CastingBasinSpecialRender.java +++ b/src/main/java/tconstruct/smeltery/model/CastingBasinSpecialRender.java @@ -47,11 +47,20 @@ public class CastingBasinSpecialRender extends TileEntitySpecialRenderer { entityitem.hoverStart = 0.0F; GL11.glPushMatrix(); GL11.glTranslatef(1F, 0.675F, 1.0F); - // GL11.glRotatef(90F, 1, 0F, 0F); + + float rotationY = switch (logic.getRenderDirection()) { + case 2 -> 90F; + case 3 -> 270F; + case 4 -> 180F; + default -> 0F; + }; + + GL11.glRotatef(rotationY, 0F, 1F, 0F); GL11.glScalef(1.75F, 1.75F, 1.75F); + if (stack.getItem() instanceof ItemBlock) { GL11.glScalef(1.6F, 1.6F, 1.6F); - GL11.glTranslatef(0F, 0.045F, 0.0f); + GL11.glTranslatef(0F, 0.045F, 0F); } else if (!(stack.getItem() instanceof ItemBlocklike)) { GL11.glRotatef(90F, 1F, 0F, 0F); GL11.glRotatef(90F, 0F, 0F, 1F); diff --git a/src/main/java/tconstruct/smeltery/model/CastingTableSpecialRenderer.java b/src/main/java/tconstruct/smeltery/model/CastingTableSpecialRenderer.java index ac9d44c2..40376c4f 100644 --- a/src/main/java/tconstruct/smeltery/model/CastingTableSpecialRenderer.java +++ b/src/main/java/tconstruct/smeltery/model/CastingTableSpecialRenderer.java @@ -53,11 +53,30 @@ public class CastingTableSpecialRenderer extends TileEntitySpecialRenderer { entityitem.hoverStart = 0.0F; GL11.glPushMatrix(); GL11.glTranslatef(1F, 1.48F, 0.55F); - GL11.glRotatef(90F, 1, 0F, 0F); + + float rotationY = switch (logic.getRenderDirection()) { + case 3 -> 180F; + case 4 -> 90F; + case 5 -> 270F; + default -> 0F; + }; + GL11.glRotatef(rotationY, 0F, 1F, 0F); + + if (logic.getRenderDirection() == 3) { + GL11.glTranslatef(0F, 0F, -0.9F); + } else if (logic.getRenderDirection() == 4) { + GL11.glTranslatef(-0.45F, 0F, -0.45F); + } else if (logic.getRenderDirection() == 5) { + GL11.glTranslatef(0.45F, 0F, -0.45F); + } + + GL11.glRotatef(90F, 1F, 0F, 0F); GL11.glScalef(2F, 2F, 2F); + if (stack.getItem() instanceof ItemBlock || stack.getItem() instanceof ItemBlocklike) { - GL11.glRotatef(90F, -1, 0F, 0F); - GL11.glTranslatef(0F, -0.1F, 0.2275F); + GL11.glRotatef(-90F, 0F, 0F, 1F); + GL11.glRotatef(90F, -1F, 0F, 0F); + GL11.glTranslatef(-0.2275F, -0.1F, 0F); } if (stack.isItemEqual(new ItemStack(TinkerSmeltery.glassPane))) {