diff --git a/gradle.properties b/gradle.properties index 7d739a3f..eb9546bb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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.20.25 +mod_version=3.20.26 mod_group_id=sophisticatedbackpacks mod_authors=P3pp3rF1y, Ridanisaurus mod_description=Fancy and functional backpacks. @@ -34,7 +34,7 @@ chipped_cf_file_id=5506938 resourcefullib_cf_file_id=5483169 athena_cf_file_id=5431579 curios_cf_file_id=5546342 -sc_version=[1.21-0.6.41,1.22) +sc_version=[1.21-0.7.10,1.22) #publish curseforge_id=422301 diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/backpack/wrapper/BackpackWrapper.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/backpack/wrapper/BackpackWrapper.java index 8bf8e811..a02eb6a1 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/backpack/wrapper/BackpackWrapper.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/backpack/wrapper/BackpackWrapper.java @@ -1,5 +1,6 @@ package net.p3pp3rf1y.sophisticatedbackpacks.backpack.wrapper; +import net.minecraft.core.BlockPos; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -8,10 +9,13 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +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; @@ -167,6 +171,9 @@ 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(); } @@ -428,14 +435,20 @@ public void setLoot(ResourceLocation lootTableName, float lootFactor) { @Override public void fillWithLoot(Player playerEntity) { - if (playerEntity.level().isClientSide) { + Level level = playerEntity.level(); + if (level.isClientSide) { return; } + BlockPos pos = playerEntity.blockPosition(); + fillWithLoot(level, pos); + } + + private void fillWithLoot(Level level, BlockPos pos) { ResourceLocation lootTable = getBackpackStack().get(ModDataComponents.LOOT_TABLE); if (lootTable == null) { return; } - fillWithLootFromTable(playerEntity, lootTable); + fillWithLootFromTable(level, pos, lootTable); } @Override @@ -496,9 +509,9 @@ public int getColumnsTaken() { return getBackpackStack().getOrDefault(ModDataComponents.COLUMNS_TAKEN, 0); } - private void fillWithLootFromTable(Player playerEntity, ResourceLocation lootTable) { - MinecraftServer server = playerEntity.level().getServer(); - if (server == null || !(playerEntity.level() instanceof ServerLevel serverLevel)) { + private void fillWithLootFromTable(Level level, BlockPos pos, ResourceLocation lootTable) { + MinecraftServer server = level.getServer(); + if (server == null || !(level instanceof ServerLevel serverLevel)) { return; } @@ -507,7 +520,7 @@ private void fillWithLootFromTable(Player playerEntity, ResourceLocation lootTab getBackpackStack().remove(ModDataComponents.LOOT_TABLE); getBackpackStack().remove(ModDataComponents.LOOT_FACTOR); - List loot = LootHelper.getLoot(lootTable, server, serverLevel, playerEntity); + List loot = LootHelper.getLoot(lootTable, server, serverLevel, pos); loot.removeIf(stack -> stack.getItem() instanceof BackpackItem); loot = RandHelper.getNRandomElements(loot, (int) (loot.size() * lootFactor)); LootHelper.fillWithLoot(serverLevel.random, loot, getInventoryHandler());