Skip to content

Commit

Permalink
add EnderChest previews
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Nov 14, 2024
1 parent 3facd8e commit 7c71f77
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/java/fi/dy/masa/tweakeroo/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 41 additions & 5 deletions src/main/java/fi/dy/masa/tweakeroo/event/RenderHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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() &&
Expand Down Expand Up @@ -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() &&
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/fi/dy/masa/tweakeroo/util/RayTraceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 7c71f77

Please sign in to comment.