Preserve player model rotation when toggling baubles inventory (#39)

This commit is contained in:
jack authored and GitHub committed 2026-10-22 23:56:32 +02:00
1 parent 07794e82c7
commit 04b39a7e7d
3 files changed
+45 -2

No files matched your search

@@ -55,7 +55,13 @@ public class GuiEvents {
if (event.gui instanceof GuiPlayerExpanded) {
if (event.button.id == 55) {
event.gui.mc.displayGuiScreen(new GuiInventory(event.gui.mc.thePlayer));
GuiPlayerExpanded expandedInventory = (GuiPlayerExpanded) event.gui;
GuiInventory inventory = new GuiInventory(event.gui.mc.thePlayer);
GuiInventoryReflectionHelper.setMousePosition(
inventory,
expandedInventory.getMouseX(),
expandedInventory.getMouseY());
event.gui.mc.displayGuiScreen(inventory);
PacketHandler.INSTANCE.sendToServer(new PacketOpenNormalInventory(event.gui.mc.thePlayer));
}
}
@@ -0,0 +1,29 @@
package baubles.client.gui;
import java.lang.reflect.Field;
import cpw.mods.fml.relauncher.ReflectionHelper;
import net.minecraft.client.gui.inventory.GuiInventory;
final class GuiInventoryReflectionHelper {
private static final Field MOUSE_X = ReflectionHelper.findField(
GuiInventory.class,
"xSizeFloat",
"field_147048_u");
private static final Field MOUSE_Y = ReflectionHelper.findField(
GuiInventory.class,
"ySizeFloat",
"field_147047_v");
private GuiInventoryReflectionHelper() {}
static void setMousePosition(GuiInventory inventory, float mouseX, float mouseY) {
try {
MOUSE_X.setFloat(inventory, mouseX);
MOUSE_Y.setFloat(inventory, mouseY);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Could not initialize the inventory mouse position", e);
}
}
}
@@ -113,9 +113,9 @@ public class GuiPlayerExpanded extends GuiContainer implements INEIGuiHandler {
*/
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
xSizeFloat = (float) mouseX;
ySizeFloat = (float) mouseY;
super.drawScreen(mouseX, mouseY, partialTicks);
if(BaublesConfig.displayTooltipOnHover) {
handleMouseHover(mouseX, mouseY);
@@ -124,6 +124,14 @@ public class GuiPlayerExpanded extends GuiContainer implements INEIGuiHandler {
handleScrollbar(mouseX, mouseY);
}
float getMouseX() {
return xSizeFloat;
}
float getMouseY() {
return ySizeFloat;
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
if (!useOldGuiRendering) {