diff --git a/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricServerCommand.java b/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricServerCommand.java new file mode 100644 index 00000000..935d9a2f --- /dev/null +++ b/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricServerCommand.java @@ -0,0 +1,35 @@ +package mcp.mobius.waila.fabric; + +import mcp.mobius.waila.command.ServerCommand; +import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; +import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import org.jetbrains.annotations.Nullable; + +public class FabricServerCommand extends ServerCommand { + + @Override + protected @Nullable String fillContainer(ServerLevel world, BlockPos pos, ServerPlayer player) { + var storage = ItemStorage.SIDED.find(world, pos, Direction.UP); + if (storage == null) return "No storage at " + pos.toShortString(); + + try (var tx = Transaction.openOuter()) { + while (true) { + var offHandStack = player.getOffhandItem(); + var item = !offHandStack.isEmpty() + ? offHandStack.getItem() + : BuiltInRegistries.ITEM.getRandom(world.random).orElseThrow().value(); + + if (storage.insert(ItemVariant.of(item), item.getDefaultMaxStackSize(), tx) == 0L) break; + } + tx.commit(); + return null; + } + } + +} diff --git a/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricWaila.java b/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricWaila.java index 7a90e3c0..de28ae3a 100644 --- a/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricWaila.java +++ b/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricWaila.java @@ -1,7 +1,6 @@ package mcp.mobius.waila.fabric; import mcp.mobius.waila.Waila; -import mcp.mobius.waila.command.ServerCommand; import mcp.mobius.waila.config.PluginConfig; import mcp.mobius.waila.debug.DumpGenerator; import mcp.mobius.waila.network.Packets; @@ -27,7 +26,7 @@ public void onInitialize() { Packets.initServer(); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> - new ServerCommand().register(dispatcher)); + new FabricServerCommand().register(dispatcher)); ServerLifecycleEvents.SERVER_STARTING.register(server -> PluginConfig.reload()); ServerLifecycleEvents.SERVER_STOPPED.register(server -> onServerStopped()); diff --git a/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoServerCommand.java b/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoServerCommand.java new file mode 100644 index 00000000..3879e931 --- /dev/null +++ b/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoServerCommand.java @@ -0,0 +1,32 @@ +package mcp.mobius.waila.neo; + +import mcp.mobius.waila.command.ServerCommand; +import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.capabilities.Capabilities; +import org.jetbrains.annotations.Nullable; + +public class NeoServerCommand extends ServerCommand { + + @Override + protected @Nullable String fillContainer(ServerLevel world, BlockPos pos, ServerPlayer player) { + var handler = world.getCapability(Capabilities.ItemHandler.BLOCK, pos, null); + if (handler == null) return "No storage at " + pos.toShortString(); + var offHandStack = player.getOffhandItem(); + + var size = handler.getSlots(); + for (var i = 0; i < size; i++) { + var item = !offHandStack.isEmpty() + ? offHandStack.getItem() + : BuiltInRegistries.ITEM.getRandom(world.random).orElseThrow().value(); + + handler.insertItem(i, new ItemStack(item, item.getDefaultMaxStackSize()), false); + } + + return null; + } + +} diff --git a/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoWaila.java b/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoWaila.java index 696c3967..9f5aa2b9 100644 --- a/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoWaila.java +++ b/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoWaila.java @@ -2,7 +2,6 @@ import mcp.mobius.waila.Waila; import mcp.mobius.waila.api.WailaConstants; -import mcp.mobius.waila.command.ServerCommand; import mcp.mobius.waila.config.PluginConfig; import mcp.mobius.waila.debug.DumpGenerator; import mcp.mobius.waila.network.Packets; @@ -60,7 +59,7 @@ static void tagReload(TagsUpdatedEvent event) { @SubscribeEvent static void registerCommands(RegisterCommandsEvent event) { - new ServerCommand().register(event.getDispatcher()); + new NeoServerCommand().register(event.getDispatcher()); } } diff --git a/src/api/java/mcp/mobius/waila/api/component/ItemListComponent.java b/src/api/java/mcp/mobius/waila/api/component/ItemListComponent.java index d88d3c8d..195ae436 100644 --- a/src/api/java/mcp/mobius/waila/api/component/ItemListComponent.java +++ b/src/api/java/mcp/mobius/waila/api/component/ItemListComponent.java @@ -20,12 +20,18 @@ public ItemListComponent(List items) { } public ItemListComponent(List items, int maxHeight) { + this(items, maxHeight, 1f); + } + + public ItemListComponent(List items, int maxHeight, float scale) { this.items = items; this.maxHeight = maxHeight; + this.scale = scale; } private final List items; private final int maxHeight; + private final float scale; private int gridWidth; private int gridHeight; @@ -33,32 +39,39 @@ public ItemListComponent(List items, int maxHeight) { @Override public int getMinimalWidth() { - return Math.min(items.size(), 9) * 18; + return (int) (Math.min(items.size(), 9) * 18 * scale); } @Override public void setGrownWidth(int grownWidth) { - gridWidth = grownWidth / 18; + gridWidth = Mth.ceil(grownWidth / (18 * scale)); gridHeight = items.isEmpty() ? 0 : Math.min(Mth.positiveCeilDiv(items.size(), gridWidth), maxHeight); maxIndex = gridWidth * gridHeight - 1; } @Override public int getHeight() { - return gridHeight * 18; + return Mth.ceil(gridHeight * 18 * scale); } @Override public void render(GuiGraphics ctx, int x, int y, DeltaTracker delta) { + var pose = ctx.pose(); + pose.pushPose(); + pose.translate(x, y, 0); + pose.scale(scale, scale, 0f); + for (var i = 0; i < items.size(); i++) { var item = items.get(i); - var ix = x + (18 * (i % gridWidth)) + 1; - var iy = y + (18 * (i / gridWidth)) + 1; + var ix = (18 * (i % gridWidth)) + 1; + var iy = (18 * (i / gridWidth)) + 1; ctx.renderItem(item, ix, iy); ItemComponent.renderItemDecorations(ctx, item, ix, iy); if (i == maxIndex) break; } + + pose.popPose(); } } diff --git a/src/api/java/mcp/mobius/waila/api/data/ItemData.java b/src/api/java/mcp/mobius/waila/api/data/ItemData.java index 290c7d86..02e4b2e2 100644 --- a/src/api/java/mcp/mobius/waila/api/data/ItemData.java +++ b/src/api/java/mcp/mobius/waila/api/data/ItemData.java @@ -26,6 +26,7 @@ public abstract class ItemData implements IData { public static final ResourceLocation CONFIG_DISPLAY_MODE = BuiltinDataUtil.rl("item.display_mode"); public static final ResourceLocation CONFIG_MAX_HEIGHT = BuiltinDataUtil.rl("item.max_height"); public static final ResourceLocation CONFIG_SORT_BY_COUNT = BuiltinDataUtil.rl("item.sort_by_count"); + public static final ResourceLocation CONFIG_GRID_MODE_SCALE = BuiltinDataUtil.rl("item.grid_mode_scale"); public enum ItemDisplayMode { GRID, LIST, DYNAMIC diff --git a/src/main/java/mcp/mobius/waila/command/ServerCommand.java b/src/main/java/mcp/mobius/waila/command/ServerCommand.java index 04214f58..af9a635b 100644 --- a/src/main/java/mcp/mobius/waila/command/ServerCommand.java +++ b/src/main/java/mcp/mobius/waila/command/ServerCommand.java @@ -18,21 +18,26 @@ import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.commands.arguments.coordinates.BlockPosArgument; +import net.minecraft.core.BlockPos; import net.minecraft.core.component.DataComponentPredicate; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.LockCode; +import org.jetbrains.annotations.Nullable; -public class ServerCommand extends CommonCommand { +public abstract class ServerCommand extends CommonCommand { public ServerCommand() { super(WailaConstants.NAMESPACE); } + protected abstract @Nullable String fillContainer(ServerLevel world, BlockPos pos, ServerPlayer player); + @Override protected boolean pluginCommandRequirement(CommandSourceStack source) { return source.hasPermission(Commands.LEVEL_ADMINS); @@ -138,6 +143,25 @@ protected void register(ArgumentBuilderBuilder command) { }) .pop("pos", "lockContainer") + .then(Commands.literal("fillContainer")) + .then(Commands.argument("pos", BlockPosArgument.blockPos())) + .executes(context -> { + var source = context.getSource(); + var world = source.getLevel(); + var player = source.getPlayer(); + var pos = BlockPosArgument.getLoadedBlockPos(context, "pos"); + + var err = fillContainer(world, pos, player); + if (err != null) { + source.sendFailure(Component.literal(err)); + return 0; + } else { + source.sendSuccess(() -> Component.literal("Filled " + pos.toShortString()), false); + return 1; + } + }) + .pop("pos", "fillContainer") + .pop("debug"); } diff --git a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/ItemProvider.java b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/ItemProvider.java index 5a196225..a49b19ce 100644 --- a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/ItemProvider.java +++ b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/ItemProvider.java @@ -41,6 +41,7 @@ protected void registerAdditions(ICommonRegistrar registrar, int priority) { registrar.localConfig(ItemData.CONFIG_DISPLAY_MODE, ItemData.ItemDisplayMode.DYNAMIC); registrar.localConfig(ItemData.CONFIG_MAX_HEIGHT, 3); registrar.localConfig(ItemData.CONFIG_SORT_BY_COUNT, true); + registrar.localConfig(ItemData.CONFIG_GRID_MODE_SCALE, 1f); } @Override @@ -96,12 +97,13 @@ protected void appendBody(ITooltip tooltip, ItemDataImpl data, IPluginConfig con var list = stream.toList(); var maxHeight = config.getInt(ItemData.CONFIG_MAX_HEIGHT); + var scale = (float) config.getDouble(ItemData.CONFIG_GRID_MODE_SCALE); lastItemsComponent = switch (config.getEnum(ItemData.CONFIG_DISPLAY_MODE)) { case DYNAMIC -> list.size() <= maxHeight ? new NamedItemListComponent(list, maxHeight) - : new ItemListComponent(list, maxHeight); - case GRID -> new ItemListComponent(list, maxHeight); + : new ItemListComponent(list, maxHeight, scale); + case GRID -> new ItemListComponent(list, maxHeight, scale); case LIST -> new NamedItemListComponent(list, maxHeight); }; diff --git a/src/resources/resources/assets/waila/lang/en_us.json b/src/resources/resources/assets/waila/lang/en_us.json index 2221eabd..6da73b45 100644 --- a/src/resources/resources/assets/waila/lang/en_us.json +++ b/src/resources/resources/assets/waila/lang/en_us.json @@ -374,6 +374,7 @@ "config.waila.plugin_wailax.item.display_mode_dynamic" : "Dynamic", "config.waila.plugin_wailax.item.max_height" : "Max Height", "config.waila.plugin_wailax.item.sort_by_count" : "Sort by Count", + "config.waila.plugin_wailax.item.grid_mode_scale" : "Grid Mode Scale", "config.waila.plugin_wailax.item.blacklist" : "Item Contents Blacklist", "config.waila.plugin_wailax.fluid" : "Fluid", "config.waila.plugin_wailax.fluid.enabled_block" : "Show Block Fluid Contents",