-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry picked from commit 1087b56)
- Loading branch information
Showing
4 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
platform/quilt/src/main/java/mcp/mobius/waila/quilt/QuiltServerCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters