Skip to content

Commit

Permalink
Mostly working shulker box container screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Permdog99 committed Jan 25, 2025
1 parent 537e125 commit acf107f
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package xyz.violaflower.legacy_tweaks.client.gui.element;

public class LegacyListRenderable {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
Expand Down Expand Up @@ -30,4 +31,9 @@ public LegacyAbstractContainerScreen(T menu, Inventory playerInventory, Componen
public float lt$scale() {
return 1.25f;
}

@Override
public void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
this.renderBg(guiGraphics, partialTick, mouseX, mouseY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,4 @@ protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
guiGraphics.drawString(this.font, this.title, this.titleLabelX + 6, yPos + containerOffset, 4210752, false);
guiGraphics.drawString(this.font, Lang.Container.INVENTORY.getString(), this.titleLabelX + 6, yPos + inventoryOffset, 0x404040, false);
}

@Override
public void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
this.renderBg(guiGraphics, partialTick, mouseX, mouseY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia
this.yMouse = (float)mouseY;
}

@Override
public void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
this.renderBg(guiGraphics, partialTick, mouseX, mouseY);
}

@Override
protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
int i = this.leftPos;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.ShulkerBoxMenu;
import net.minecraft.world.inventory.Slot;
import xyz.violaflower.legacy_tweaks.client.gui.extention.SlotExtension;
import xyz.violaflower.legacy_tweaks.util.client.screen.graphics.GraphicsUtil;
import xyz.violaflower.legacy_tweaks.util.common.assets.Sprites;
import xyz.violaflower.legacy_tweaks.util.common.lang.Lang;

public class LegacyShulkerBoxScreen extends LegacyAbstractContainerScreen<ShulkerBoxMenu> {
public LegacyShulkerBoxScreen(ShulkerBoxMenu menu, Inventory playerInventory, Component title) {
super(manipulateSlots(menu), playerInventory, title);
this.imageWidth = 430 / 2;
this.imageHeight = (282 / 2) + (3 * 42);
}

private static ShulkerBoxMenu manipulateSlots(ShulkerBoxMenu shulkerBoxMenu) {
int i = 0;
for (Slot slot : shulkerBoxMenu.slots) {
if (slot instanceof SlotExtension extension) {
int slotOffset = (21 * 3) /2;
if (i <= (9 * 3) - 1) {
extension.lt$setVisualX(slot.x * 18.66667f / 16 + 4.66667f);
extension.lt$setVisualY(slot.y * 18.66667f / 16 + 5.6f + slotOffset);
} else if (i > ((9 * 3) - 1) && i <= (9 * 3) + 36) {
extension.lt$setVisualX(slot.x * 18.66667f / 16 + 4.66667f);
extension.lt$setVisualY(slot.y * 18.66667f / 16 + 4.56667f + (isHotbarSlot(i) ? 6.46667f : 4.54444f) + slotOffset - 0.33333f);
}
extension.lt$setSize(19);
}
i++;
}
return shulkerBoxMenu;
}

public static boolean isHotbarSlot(int index) {
int chest = (9 * 3);
return index >= chest + 27 && index < chest + 36 || index == chest + 36;
}

public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
super.render(guiGraphics, mouseX, mouseY, partialTick);
this.renderTooltip(guiGraphics, mouseX, mouseY);
}

protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
int xPos = (this.width - this.imageWidth) / 2;
int yPos = ((this.height - this.imageHeight) / 2) + (21 * 3)/2;
GraphicsUtil.blit(guiGraphics, Sprites.CHEST_SMALL, xPos, yPos, this.imageWidth, 208.5f, 0, 0, 430, 417, 440, 440);
}

@Override
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
int yPos = ((this.height - this.imageHeight) / 2) + (21 * 3);
int containerOffset = -105 + (10 * 3);
int inventoryOffset = containerOffset + (21 * 3) + 19;
guiGraphics.drawString(this.font, this.title, this.titleLabelX + 6, yPos + containerOffset, 4210752, false);
guiGraphics.drawString(this.font, Lang.Container.INVENTORY.getString(), this.titleLabelX + 6, yPos + inventoryOffset, 0x404040, false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package xyz.violaflower.legacy_tweaks.mixin.client.accessor;

import net.minecraft.client.gui.components.Renderable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.List;

@Mixin(targets = "net/minecraft/client/gui/screens/Screen")
public interface ScreenAccessor {

@Accessor("renderables")
List<Renderable> legacyTweaks$getRenderables();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.LegacyContainerScreen;
import xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.LegacyFurnaceScreen;
import xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.LegacyShulkerBoxScreen;
import xyz.violaflower.legacy_tweaks.client.gui.screen.legacy.screens.inventory.crafting.LegacyQuickCraftingScreen;
import xyz.violaflower.legacy_tweaks.tweaks.Tweaks;

Expand Down Expand Up @@ -43,13 +44,15 @@ private static void changeMenuScreens(CallbackInfo ci) {
register(MenuType.GENERIC_9x4, LegacyContainerScreen::new);
register(MenuType.GENERIC_9x5, LegacyContainerScreen::new);
register(MenuType.GENERIC_9x6, LegacyContainerScreen::new);
register(MenuType.SHULKER_BOX, LegacyShulkerBoxScreen::new);
} else {
register(MenuType.GENERIC_9x1, ContainerScreen::new);
register(MenuType.GENERIC_9x2, ContainerScreen::new);
register(MenuType.GENERIC_9x3, ContainerScreen::new);
register(MenuType.GENERIC_9x4, ContainerScreen::new);
register(MenuType.GENERIC_9x5, ContainerScreen::new);
register(MenuType.GENERIC_9x6, ContainerScreen::new);
register(MenuType.SHULKER_BOX, ShulkerBoxScreen::new);
}
register(MenuType.GENERIC_3x3, DispenserScreen::new);
register(MenuType.CRAFTER_3x3, CrafterScreen::new);
Expand All @@ -65,7 +68,6 @@ private static void changeMenuScreens(CallbackInfo ci) {
register(MenuType.LECTERN, LecternScreen::new);
register(MenuType.LOOM, LoomScreen::new);
register(MenuType.MERCHANT, MerchantScreen::new);
register(MenuType.SHULKER_BOX, ShulkerBoxScreen::new);
register(MenuType.SMITHING, SmithingScreen::new);
register(MenuType.SMOKER, SmokerScreen::new);
register(MenuType.CARTOGRAPHY_TABLE, CartographyTableScreen::new);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/legacy_tweaks.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"client.accessor.FogDataAccessor",
"client.accessor.GuiGraphicsAccessor",
"client.accessor.PostChainAccessor",
"client.accessor.ScreenAccessor",
"client.accessor.TextureStateShardAccessor",
"client.networking.NetworkRegistryMixin",
"client.screen.AbstractContainerScreenMixin",
Expand Down

0 comments on commit acf107f

Please sign in to comment.