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 index 935d9a2f7..ab3ceb479 100644 --- a/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricServerCommand.java +++ b/platform/fabric/src/main/java/mcp/mobius/waila/fabric/FabricServerCommand.java @@ -11,6 +11,7 @@ import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.Nullable; +@SuppressWarnings("UnstableApiUsage") public class FabricServerCommand extends ServerCommand { @Override @@ -25,7 +26,7 @@ public class FabricServerCommand extends ServerCommand { ? offHandStack.getItem() : BuiltInRegistries.ITEM.getRandom(world.random).orElseThrow().value(); - if (storage.insert(ItemVariant.of(item), item.getDefaultMaxStackSize(), tx) == 0L) break; + if (storage.insert(ItemVariant.of(item), item.getMaxStackSize(), tx) == 0L) break; } tx.commit(); return null; diff --git a/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeServerCommand.java b/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeServerCommand.java index 6014eb739..cefe13ae6 100644 --- a/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeServerCommand.java +++ b/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeServerCommand.java @@ -25,7 +25,7 @@ public class ForgeServerCommand extends ServerCommand { ? offHandStack.getItem() : BuiltInRegistries.ITEM.getRandom(world.random).orElseThrow().value(); - handler.insertItem(i, new ItemStack(item, item.getDefaultMaxStackSize()), false); + handler.insertItem(i, new ItemStack(item, item.getMaxStackSize()), false); } return null; 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 deleted file mode 100644 index 3879e931f..000000000 --- a/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoServerCommand.java +++ /dev/null @@ -1,32 +0,0 @@ -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/NeoWailaDedicatedServer.java b/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoWailaDedicatedServer.java deleted file mode 100644 index ffd7c6f0a..000000000 --- a/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoWailaDedicatedServer.java +++ /dev/null @@ -1,22 +0,0 @@ -package mcp.mobius.waila.neo; - -import mcp.mobius.waila.WailaDedicatedServer; -import mcp.mobius.waila.api.WailaConstants; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.EventBusSubscriber; -import net.neoforged.neoforge.event.tick.ServerTickEvent; - -public class NeoWailaDedicatedServer extends WailaDedicatedServer { - - @EventBusSubscriber(modid = WailaConstants.WAILA, value = Dist.DEDICATED_SERVER) - static class Subscriber { - - @SubscribeEvent - static void clientTick(ServerTickEvent.Post event) { - onDedicatedServerTick(); - } - - } - -} diff --git a/platform/neo/src/main/resources/META-INF/services/mcp.mobius.waila.plugin.PluginLoader b/platform/neo/src/main/resources/META-INF/services/mcp.mobius.waila.plugin.PluginLoader deleted file mode 100644 index 7fa406382..000000000 --- a/platform/neo/src/main/resources/META-INF/services/mcp.mobius.waila.plugin.PluginLoader +++ /dev/null @@ -1 +0,0 @@ -mcp.mobius.waila.neo.NeoPluginLoader diff --git a/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/NeoCommonPlugin.java b/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/NeoCommonPlugin.java deleted file mode 100644 index 32553a7ad..000000000 --- a/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/NeoCommonPlugin.java +++ /dev/null @@ -1,19 +0,0 @@ -package mcp.mobius.waila.plugin.neo; - -import mcp.mobius.waila.api.ICommonRegistrar; -import mcp.mobius.waila.api.IWailaCommonPlugin; -import mcp.mobius.waila.plugin.neo.provider.EnergyCapabilityProvider; -import mcp.mobius.waila.plugin.neo.provider.FluidCapabilityProvider; -import mcp.mobius.waila.plugin.neo.provider.ItemCapabilityProvider; -import net.minecraft.world.level.block.entity.BlockEntity; - -public class NeoCommonPlugin implements IWailaCommonPlugin { - - @Override - public void register(ICommonRegistrar registrar) { - registrar.blockData(EnergyCapabilityProvider.INSTANCE, BlockEntity.class, 2000); - registrar.blockData(ItemCapabilityProvider.INSTANCE, BlockEntity.class, 2000); - registrar.blockData(FluidCapabilityProvider.INSTANCE, BlockEntity.class, 2000); - } - -} diff --git a/platform/quilt/build.gradle.kts b/platform/quilt/build.gradle.kts index 1630387c9..5ac7aa6be 100644 --- a/platform/quilt/build.gradle.kts +++ b/platform/quilt/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { modCompileRuntime("org.quiltmc.quilted-fabric-api:fabric-key-binding-api-v1:${rootProp["qfapi"]}") modCompileRuntime("org.quiltmc.quilted-fabric-api:fabric-rendering-v1:${rootProp["qfapi"]}") modCompileRuntime("org.quiltmc.quilted-fabric-api:fabric-mining-level-api-v1:${rootProp["qfapi"]}") + modCompileRuntime("org.quiltmc.quilted-fabric-api:fabric-transfer-api-v1:${rootProp["qfapi"]}") modCompileRuntime("com.terraformersmc:modmenu:${rootProp["modMenu"]}") diff --git a/platform/quilt/src/main/java/mcp/mobius/waila/quilt/QuiltServerCommand.java b/platform/quilt/src/main/java/mcp/mobius/waila/quilt/QuiltServerCommand.java new file mode 100644 index 000000000..984ebaaa6 --- /dev/null +++ b/platform/quilt/src/main/java/mcp/mobius/waila/quilt/QuiltServerCommand.java @@ -0,0 +1,36 @@ +package mcp.mobius.waila.quilt; + +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; + +@SuppressWarnings("UnstableApiUsage") +public class QuiltServerCommand 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.getMaxStackSize(), tx) == 0L) break; + } + tx.commit(); + return null; + } + } + +} diff --git a/platform/quilt/src/main/java/mcp/mobius/waila/quilt/QuiltWaila.java b/platform/quilt/src/main/java/mcp/mobius/waila/quilt/QuiltWaila.java index cc5fcff25..063c1afce 100644 --- a/platform/quilt/src/main/java/mcp/mobius/waila/quilt/QuiltWaila.java +++ b/platform/quilt/src/main/java/mcp/mobius/waila/quilt/QuiltWaila.java @@ -19,7 +19,7 @@ public void onInitialize(ModContainer mod) { Packets.initServer(); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> - new ServerCommand().register(dispatcher)); + new QuiltServerCommand().register(dispatcher)); ServerLifecycleEvents.STARTING.register(server -> PluginConfig.reload()); ServerLifecycleEvents.STOPPED.register(server -> onServerStopped()); diff --git a/src/main/java/mcp/mobius/waila/command/ServerCommand.java b/src/main/java/mcp/mobius/waila/command/ServerCommand.java index f29544c9b..ff10bbc56 100644 --- a/src/main/java/mcp/mobius/waila/command/ServerCommand.java +++ b/src/main/java/mcp/mobius/waila/command/ServerCommand.java @@ -19,6 +19,7 @@ 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.registries.BuiltInRegistries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.ClickEvent;