Skip to content

Commit

Permalink
Improved functionality when mod compat mods are removed
Browse files Browse the repository at this point in the history
  • Loading branch information
B1n-ry committed Feb 28, 2024
1 parent c8b94e9 commit fd6a4ce
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/main/java/com/b1n_ry/yigd/components/InventoryComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,17 @@ public DefaultedList<ItemStack> merge(InventoryComponent mergingComponent, Serve

for (InvModCompat<?> modCompat : InvModCompat.invCompatMods) {
String modName = modCompat.getModName();
CompatComponent<?> compatComponent = this.modInventoryItems.get(modName);
if (!mergingComponent.modInventoryItems.containsKey(modName)) continue;

CompatComponent<?> mergingCompatComponent = mergingComponent.modInventoryItems.get(modName);
if (!this.modInventoryItems.containsKey(modName)) {
for (Pair<ItemStack, DropRule> pair : mergingCompatComponent.getAsStackDropList()) {
ItemStack item = pair.getLeft();
if (!item.isEmpty())
extraItems.add(item);
}
}
CompatComponent<?> compatComponent = this.modInventoryItems.get(modName);

DefaultedList<ItemStack> extraModItems = compatComponent.merge(mergingCompatComponent, merger);
extraItems.addAll(extraModItems);
Expand Down Expand Up @@ -531,7 +540,9 @@ public DefaultedList<ItemStack> applyToPlayer(ServerPlayerEntity player) {

// Set mod inventories
for (InvModCompat<?> modCompat : InvModCompat.invCompatMods) {
DefaultedList<ItemStack> extraModItems = this.modInventoryItems.get(modCompat.getModName()).storeToPlayer(player);
String modName = modCompat.getModName();
if (!this.modInventoryItems.containsKey(modName)) continue;
DefaultedList<ItemStack> extraModItems = this.modInventoryItems.get(modName).storeToPlayer(player);
extraItems.addAll(extraModItems);
}

Expand All @@ -551,6 +562,7 @@ public InventoryComponent filteredInv(Predicate<DropRule> filter) {
Map<String, CompatComponent<?>> filteredModInventories = new HashMap<>();
for (InvModCompat<?> compatMod : InvModCompat.invCompatMods) {
String modName = compatMod.getModName();
if (!this.modInventoryItems.containsKey(modName)) continue;
CompatComponent<?> compatInv = this.modInventoryItems.get(modName);
CompatComponent<?> filteredCompatInv = compatInv.filterInv(filter);
filteredModInventories.put(modName, filteredCompatInv);
Expand Down Expand Up @@ -584,6 +596,8 @@ public NbtCompound toNbt() {
NbtCompound modInventoriesNbt = new NbtCompound();
for (InvModCompat<?> compatMod : InvModCompat.invCompatMods) {
String modName = compatMod.getModName();
if (!this.modInventoryItems.containsKey(modName)) continue;

CompatComponent<?> compatInv = this.modInventoryItems.get(modName);
modInventoriesNbt.put(modName, compatInv.writeNbt());
}
Expand Down Expand Up @@ -613,6 +627,7 @@ public static InventoryComponent fromNbt(NbtCompound nbt) {
Map<String, CompatComponent<?>> compatComponents = new HashMap<>();
for (InvModCompat<?> compatMod : InvModCompat.invCompatMods) {
String modName = compatMod.getModName();
if (!modInventoriesNbt.contains(modName)) continue;
NbtCompound modNbt = modInventoriesNbt.getCompound(modName);
compatComponents.put(modName, compatMod.readNbt(modNbt));
}
Expand Down

0 comments on commit fd6a4ce

Please sign in to comment.