Skip to content

Commit

Permalink
cherry-pick fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Dec 8, 2024
1 parent 2db27fd commit 1087b56
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("UnstableApiUsage")
public class FabricServerCommand extends ServerCommand {

@Override
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions platform/quilt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}")

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mcp/mobius/waila/command/ServerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1087b56

Please sign in to comment.