From 7c71f7790e124643e94933656afc35fbe3c8ad93 Mon Sep 17 00:00:00 2001 From: Sakura Ryoko Date: Thu, 14 Nov 2024 01:07:58 -0500 Subject: [PATCH] add EnderChest previews --- .../fi/dy/masa/tweakeroo/config/Configs.java | 1 + .../masa/tweakeroo/event/RenderHandler.java | 46 +++++++++++++++++-- .../dy/masa/tweakeroo/util/RayTraceUtils.java | 17 +++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/main/java/fi/dy/masa/tweakeroo/config/Configs.java b/src/main/java/fi/dy/masa/tweakeroo/config/Configs.java index ff8ae4d13..ea55e3a8c 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/config/Configs.java +++ b/src/main/java/fi/dy/masa/tweakeroo/config/Configs.java @@ -146,6 +146,7 @@ public static class Generic POTION_WARNING_BENEFICIAL_ONLY, REMEMBER_FLEXIBLE, SHULKER_DISPLAY_BACKGROUND_COLOR, + SHULKER_DISPLAY_ENDER_CHEST, SHULKER_DISPLAY_REQUIRE_SHIFT, SLOT_SYNC_WORKAROUND, SLOT_SYNC_WORKAROUND_ALWAYS, diff --git a/src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java b/src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java index a14330bc1..7fecc594b 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java +++ b/src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java @@ -7,18 +7,22 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.EnderChestInventory; import net.minecraft.item.FilledMapItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.nbt.NbtCompound; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; +import net.minecraft.util.profiler.Profiler; +import net.minecraft.world.World; import fi.dy.masa.malilib.gui.GuiBase; import fi.dy.masa.malilib.interfaces.IRenderer; import fi.dy.masa.malilib.render.InventoryOverlay; -import fi.dy.masa.malilib.util.ActiveMode; -import fi.dy.masa.malilib.util.Color4f; -import fi.dy.masa.malilib.util.InventoryUtils; +import fi.dy.masa.malilib.util.*; import fi.dy.masa.tweakeroo.config.Configs; import fi.dy.masa.tweakeroo.config.FeatureToggle; import fi.dy.masa.tweakeroo.config.Hotkeys; @@ -27,6 +31,19 @@ public class RenderHandler implements IRenderer { + private static final RenderHandler INSTANCE = new RenderHandler(); + private final MinecraftClient mc; + + public RenderHandler() + { + this.mc = MinecraftClient.getInstance(); + } + + public static RenderHandler getInstance() + { + return INSTANCE; + } + @Override public void onRenderGameOverlayPost(DrawContext drawContext) { @@ -52,8 +69,6 @@ else if (FeatureToggle.TWEAK_HOTBAR_SCROLL.getBooleanValue() && { RenderUtils.renderInventoryOverlay(context, drawContext); } - - //RenderUtils.renderInventoryOverlay(mc, drawContext); } if (FeatureToggle.TWEAK_PLAYER_INVENTORY_PEEK.getBooleanValue() && @@ -99,6 +114,27 @@ else if (stack.getComponents().contains(DataComponentTypes.CONTAINER) && Invento fi.dy.masa.malilib.render.RenderUtils.renderShulkerBoxPreview(stack, x, y, Configs.Generic.SHULKER_DISPLAY_BACKGROUND_COLOR.getBooleanValue(), drawContext); } } + else if (stack.isOf(Items.ENDER_CHEST) && Configs.Generic.SHULKER_DISPLAY_ENDER_CHEST.getBooleanValue()) + { + if (FeatureToggle.TWEAK_SHULKERBOX_DISPLAY.getBooleanValue() && + (Configs.Generic.SHULKER_DISPLAY_REQUIRE_SHIFT.getBooleanValue() == false || GuiBase.isShiftDown())) + { + World world = WorldUtils.getBestWorld(this.mc); + if (world == null || this.mc.player == null) + { + return; + } + PlayerEntity player = world.getPlayerByUuid(this.mc.player.getUuid()); + + if (player != null) + { + EnderChestInventory inv = player.getEnderChestInventory(); + NbtCompound nbt = new NbtCompound(); + nbt.put(NbtKeys.ENDER_ITEMS, inv.toNbtList(world.getRegistryManager())); + fi.dy.masa.malilib.render.RenderUtils.renderNbtItemsPreview(stack, nbt, x, y, false, drawContext); + } + } + } else if (stack.getComponents().contains(DataComponentTypes.BUNDLE_CONTENTS) && InventoryUtils.bundleHasItems(stack)) { if (FeatureToggle.TWEAK_BUNDLE_DISPLAY.getBooleanValue() && diff --git a/src/main/java/fi/dy/masa/tweakeroo/util/RayTraceUtils.java b/src/main/java/fi/dy/masa/tweakeroo/util/RayTraceUtils.java index 3b9d1b8ad..6056163f2 100644 --- a/src/main/java/fi/dy/masa/tweakeroo/util/RayTraceUtils.java +++ b/src/main/java/fi/dy/masa/tweakeroo/util/RayTraceUtils.java @@ -10,6 +10,7 @@ import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.EnderChestBlockEntity; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; @@ -214,6 +215,22 @@ else if (trace.getType() == HitResult.Type.ENTITY) inv = ServerDataSyncer.getInstance().getBlockInventory(world, pos, false); } + if (be instanceof EnderChestBlockEntity) + { + //System.out.print("fetch self enderItems from EnderChest\n"); + if (MinecraftClient.getInstance().player != null) + { + PlayerEntity player = world.getPlayerByUuid(MinecraftClient.getInstance().player.getUuid()); + + if (player != null) + { + // Fetch your own EnderItems + inv = player.getEnderChestInventory(); + //System.out.printf("ENDER SIZE: %d\n", inv.size()); + } + } + } + if (nbt != null && !nbt.isEmpty()) { Inventory inv2 = fi.dy.masa.malilib.util.InventoryUtils.getNbtInventory(nbt, inv != null ? inv.size() : -1, world.getRegistryManager());