Skip to content

Commit

Permalink
fix: šŸ› Fixed backpack to return empty item handler when something triā€¦
Browse files Browse the repository at this point in the history
ā€¦es to get item handler capability from it and the backpack doesn't have a storage uuid assigned yet. This prevents creation of unnecessary storage ids and records in cases where the backpack stack may be a copy and thus newly created storage id won't be retained on it.
  • Loading branch information
P3pp3rF1y committed Jan 14, 2025
1 parent 5e63fdf commit 39c254c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ loader_version_range=[4,)
mod_id=sophisticatedbackpacks
mod_name=Sophisticated Backpacks
mod_license=GNU General Public License v3.0
mod_version=3.22.2
mod_version=3.22.3
mod_group_id=sophisticatedbackpacks
mod_authors=P3pp3rF1y, Ridanisaurus
mod_description=Fancy and functional backpacks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ItemContainerContents;
import net.minecraft.world.level.Level;
import net.neoforged.fml.util.thread.SidedThreadGroups;
import net.neoforged.neoforge.energy.IEnergyStorage;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
import net.neoforged.neoforge.fluids.capability.IFluidHandlerItem;
import net.neoforged.neoforge.server.ServerLifecycleHooks;
import net.p3pp3rf1y.sophisticatedbackpacks.SophisticatedBackpacks;
import net.p3pp3rf1y.sophisticatedbackpacks.api.IEnergyStorageUpgradeWrapper;
import net.p3pp3rf1y.sophisticatedbackpacks.api.IFluidHandlerWrapperUpgrade;
Expand Down Expand Up @@ -174,9 +172,6 @@ private void markBackpackContentsDirty() {
public ITrackedContentsItemHandler getInventoryForInputOutput() {
if (inventoryIOHandler == null) {
inventoryIOHandler = new InventoryIOHandler(this);
if (Thread.currentThread().getThreadGroup() == SidedThreadGroups.SERVER && ServerLifecycleHooks.getCurrentServer() != null) {
fillWithLoot(ServerLifecycleHooks.getCurrentServer().overworld(), BlockPos.ZERO);
}
}
return inventoryIOHandler.getFilteredItemHandler();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.common.extensions.IMenuTypeExtension;
import net.neoforged.neoforge.common.loot.IGlobalLootModifier;
import net.neoforged.neoforge.items.wrapper.EmptyItemHandler;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
Expand Down Expand Up @@ -378,7 +379,10 @@ public static void registerCauldronInteractions() {
}

private static void registerCapabilities(RegisterCapabilitiesEvent event) {
event.registerItem(Capabilities.ItemHandler.ITEM, (stack, v) -> BackpackWrapper.fromStack(stack).getInventoryForInputOutput(),
event.registerItem(Capabilities.ItemHandler.ITEM, (stack, v) -> {
IBackpackWrapper backpackWrapper = BackpackWrapper.fromStack(stack);
return backpackWrapper.getContentsUuid().isEmpty() ? EmptyItemHandler.INSTANCE : backpackWrapper.getInventoryForInputOutput();
},
BACKPACK.get(), COPPER_BACKPACK.get(), IRON_BACKPACK.get(), GOLD_BACKPACK.get(), DIAMOND_BACKPACK.get(), NETHERITE_BACKPACK.get());
event.registerItem(Capabilities.FluidHandler.ITEM, (stack, v) -> {
if (Boolean.FALSE.equals(Config.SERVER.itemFluidHandlerEnabled.get())) {
Expand Down

0 comments on commit 39c254c

Please sign in to comment.