Skip to content

Commit

Permalink
cherry-pick fixes
Browse files Browse the repository at this point in the history
(cherry picked from commit 1087b56)
  • Loading branch information
deirn committed Dec 8, 2024
1 parent 35a4821 commit e9d74dc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions platform/quilt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
modCompileRuntime("org.quiltmc.quilted-fabric-api:fabric-rendering-v1:${rootProp["qfapi"]}")
modCompileRuntime("org.quiltmc.quilted-fabric-api:fabric-lifecycle-events-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 @@ -20,7 +20,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 @@ -18,6 +18,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.component.DataComponents;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
Expand Down

0 comments on commit e9d74dc

Please sign in to comment.