Skip to content

Commit

Permalink
Fixed trinkets issue
Browse files Browse the repository at this point in the history
  • Loading branch information
B1n-ry committed Aug 18, 2024
1 parent ce04c21 commit df81b03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# You're in Grave Danger 2.4.6

### Fixes
* Fixed issue with graves clearing inventories if the player had more trinkets equipped
in the grave than when claiming a grave

---

# You're in Grave Danger 2.4.5
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/b1n_ry/yigd/compat/AccessoriesCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,14 @@ public DefaultedList<ItemStack> merge(CompatComponent<?> mergingComponent, Serve

for (int i = 0; i < mergingSlot.normal.size(); i++) {
Pair<ItemStack, DropRule> mergingPair = mergingSlot.normal.get(i);
ItemStack mergingStack = mergingPair.getLeft();
ItemStack mergingStack = mergingPair.getLeft().copy();
if (mergingStack.isEmpty()) continue;

if (thisSlot.normal.size() <= i) {
extraItems.add(mergingStack);
continue;
}

Pair<ItemStack, DropRule> currentPair = thisSlot.normal.get(i);
ItemStack thisStack = currentPair.getLeft();
if (YigdConfig.getConfig().graveConfig.treatBindingCurse && !AccessoriesAPI.getOrDefaultAccessory(mergingStack).canUnequip(mergingStack, SlotReference.of(merger, key, i))) {
Expand All @@ -171,9 +176,14 @@ public DefaultedList<ItemStack> merge(CompatComponent<?> mergingComponent, Serve
}
for (int i = 0; i < mergingSlot.cosmetic.size(); i++) {
Pair<ItemStack, DropRule> mergingPair = mergingSlot.cosmetic.get(i);
ItemStack mergingStack = mergingPair.getLeft();
ItemStack mergingStack = mergingPair.getLeft().copy();
if (mergingStack.isEmpty()) continue;

if (thisSlot.cosmetic.size() <= i) {
extraItems.add(mergingStack);
continue;
}

Pair<ItemStack, DropRule> currentPair = thisSlot.cosmetic.get(i);
ItemStack thisStack = currentPair.getLeft();
if (YigdConfig.getConfig().graveConfig.treatBindingCurse && !AccessoriesAPI.getOrDefaultAccessory(mergingStack).canUnequip(mergingStack, SlotReference.of(merger, key, i))) {
Expand Down Expand Up @@ -245,16 +255,18 @@ public DefaultedList<ItemStack> storeToPlayer(ServerPlayerEntity player) {
ExpandedSimpleContainer cosmeticAccessories = container.getCosmeticAccessories();
for (int i = 0; i < inventorySlot.normal.size(); i++) {
Pair<ItemStack, DropRule> pair = inventorySlot.normal.get(i);
if (i > normalAccessories.size()) {
if (i >= normalAccessories.size()) {
extraItems.add(pair.getLeft());
continue;
}

normalAccessories.setStack(i, pair.getLeft());
}
for (int i = 0; i < inventorySlot.cosmetic.size(); i++) {
Pair<ItemStack, DropRule> pair = inventorySlot.cosmetic.get(i);
if (i > cosmeticAccessories.size()) {
if (i >= cosmeticAccessories.size()) {
extraItems.add(pair.getLeft());
continue;
}

cosmeticAccessories.setStack(i, pair.getLeft());
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/b1n_ry/yigd/compat/TrinketsCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,19 @@ public DefaultedList<ItemStack> merge(CompatComponent<?> mergingComponent, Serve
Pair<ItemStack, DropRule> pair = mergingItems.get(i);
ItemStack mergingStack = pair.getLeft().copy(); // Solves the issue where the itemstacks are the same instance

if (stacks.size() <= i) {
extraItems.add(mergingStack);
continue;
}

Pair<ItemStack, DropRule> currentPair = stacks.get(i);
if (YigdConfig.getConfig().graveConfig.treatBindingCurse && !this.canUnequip(trinketComponent.orElse(null), slotName, groupName, i, mergingStack, merger)) {
extraItems.add(currentPair.getLeft()); // Add the current item to extraItems (as it's being replaced)
stacks.set(i, new Pair<>(mergingStack, pair.getRight())); // Can't be unequipped, so it's prioritized
continue; // Already set the item, so we can skip the rest
}

if (stacks.size() <= i || !currentPair.getLeft().isEmpty()) {
if (!currentPair.getLeft().isEmpty()) {
extraItems.add(mergingStack);
continue;
}
Expand Down

0 comments on commit df81b03

Please sign in to comment.