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 09ec620 commit 26f3260
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
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.core.Registry;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.Nullable;

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

@Override
Expand All @@ -23,9 +24,9 @@ public class FabricServerCommand extends ServerCommand {
var offHandStack = player.getOffhandItem();
var item = !offHandStack.isEmpty()
? offHandStack.getItem()
: BuiltInRegistries.ITEM.getRandom(world.random).orElseThrow().value();
: Registry.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 @@ -2,11 +2,11 @@

import mcp.mobius.waila.command.ServerCommand;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.Registry;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.items.CapabilityItemHandler;
import org.jetbrains.annotations.Nullable;

public class ForgeServerCommand extends ServerCommand {
Expand All @@ -15,17 +15,17 @@ public class ForgeServerCommand extends ServerCommand {
protected @Nullable String fillContainer(ServerLevel world, BlockPos pos, ServerPlayer player) {
var be = world.getBlockEntity(pos);
if (be == null) return "No BlockEntity at " + pos.toShortString();
var handler = be.getCapability(ForgeCapabilities.ITEM_HANDLER, null).resolve().orElse(null);
var handler = be.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).resolve().orElse(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();
: Registry.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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import mcp.mobius.waila.gui.screen.HomeScreen;
import mcp.mobius.waila.network.Packets;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.ConfigScreenHandler;
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
import net.minecraftforge.client.event.RegisterClientCommandsEvent;
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
Expand All @@ -17,6 +18,7 @@
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
Expand Down
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.Registry;
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()
: Registry.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
@@ -1,7 +1,6 @@
package mcp.mobius.waila.quilt;

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;
Expand All @@ -19,7 +18,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

0 comments on commit 26f3260

Please sign in to comment.