diff --git a/CHANGELOG.md b/CHANGELOG.md index c1f76e1..dc7670c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # You're in Grave Danger 2.0.11 +### Changes +* Item loss can now optionally be applied to modded inventories + +### Fixes +* Item loss will now not try and remove the same item twice, and count it as 2 + items (more reliable how much is lost) +* Running the /clear command after retrieving items from a grave no longer clears + the grave backup +* Graves being moved (like with carry-on mod) will now be detected when they reappear + --- # You're in Grave Danger 2.0.10 diff --git a/src/main/java/com/b1n_ry/yigd/block/entity/GraveBlockEntity.java b/src/main/java/com/b1n_ry/yigd/block/entity/GraveBlockEntity.java index 2a66d75..7098c20 100644 --- a/src/main/java/com/b1n_ry/yigd/block/entity/GraveBlockEntity.java +++ b/src/main/java/com/b1n_ry/yigd/block/entity/GraveBlockEntity.java @@ -160,7 +160,11 @@ public void readNbt(NbtCompound nbt) { public static void tick(World world, BlockPos pos, BlockState ignoredState, GraveBlockEntity be) { if (world.isClient) return; - if (be.component == null) return; + if (be.component == null) { + if (be.graveId == null) return; + DeathInfoManager.INSTANCE.getGrave(be.graveId).ifPresent(be::setComponent); + if (be.component == null) return; + } if (world.getTime() % 2400 == 0) cachedConfig = YigdConfig.getConfig(); // Reloads the config every 60 seconds YigdConfig.GraveConfig.GraveTimeout timeoutConfig = cachedConfig.graveConfig.graveTimeout; diff --git a/src/main/java/com/b1n_ry/yigd/compat/AccessoriesCompat.java b/src/main/java/com/b1n_ry/yigd/compat/AccessoriesCompat.java index af14284..c3faa7e 100644 --- a/src/main/java/com/b1n_ry/yigd/compat/AccessoriesCompat.java +++ b/src/main/java/com/b1n_ry/yigd/compat/AccessoriesCompat.java @@ -248,20 +248,20 @@ public DefaultedList storeToPlayer(ServerPlayerEntity player) { for (int i = 0; i < inventorySlot.normal.size(); i++) { Pair pair = inventorySlot.normal.get(i); if (i >= normalAccessories.size()) { - extraItems.add(pair.getLeft()); + extraItems.add(pair.getLeft().copy()); continue; } - normalAccessories.setStack(i, pair.getLeft()); + normalAccessories.setStack(i, pair.getLeft().copy()); } for (int i = 0; i < inventorySlot.cosmetic.size(); i++) { Pair pair = inventorySlot.cosmetic.get(i); if (i >= cosmeticAccessories.size()) { - extraItems.add(pair.getLeft()); + extraItems.add(pair.getLeft().copy()); continue; } - cosmeticAccessories.setStack(i, pair.getLeft()); + cosmeticAccessories.setStack(i, pair.getLeft().copy()); } } diff --git a/src/main/java/com/b1n_ry/yigd/compat/BeansBackpacksCompat.java b/src/main/java/com/b1n_ry/yigd/compat/BeansBackpacksCompat.java index b0c21c5..cb9569f 100644 --- a/src/main/java/com/b1n_ry/yigd/compat/BeansBackpacksCompat.java +++ b/src/main/java/com/b1n_ry/yigd/compat/BeansBackpacksCompat.java @@ -125,12 +125,12 @@ public BeansBackpackInv getInventory(ServerPlayerEntity player) { public DefaultedList storeToPlayer(ServerPlayerEntity player) { DefaultedList extraItems = DefaultedList.of(); - ItemStack backpack = this.inventory.getBackpack(); + ItemStack backpack = this.inventory.getBackpack().copy(); DefaultedList backpackContents = this.inventory.getBackpackContents(); if (backpack.isEmpty()) { for (ItemStack extra : backpackContents) { if (!extra.isEmpty()) - extraItems.add(extra); + extraItems.add(extra.copy()); } return extraItems; } @@ -141,7 +141,7 @@ public DefaultedList storeToPlayer(ServerPlayerEntity player) { backpackInventory.clear(); for (ItemStack stack : backpackContents) { if (!stack.isEmpty()) { - backpackInventory.add(stack); + backpackInventory.add(stack.copy()); } } diff --git a/src/main/java/com/b1n_ry/yigd/compat/InventorioCompat.java b/src/main/java/com/b1n_ry/yigd/compat/InventorioCompat.java index 1cc316c..ada8802 100644 --- a/src/main/java/com/b1n_ry/yigd/compat/InventorioCompat.java +++ b/src/main/java/com/b1n_ry/yigd/compat/InventorioCompat.java @@ -108,7 +108,7 @@ public DefaultedList storeToPlayer(ServerPlayerEntity player) { if (addon == null) return extraItems; for (int i = 0; i < this.inventory.size(); i++) { - ItemStack item = this.inventory.get(i).getLeft(); + ItemStack item = this.inventory.get(i).getLeft().copy(); if (i >= addon.size()) { extraItems.add(item); } else { diff --git a/src/main/java/com/b1n_ry/yigd/compat/OriginsCompat.java b/src/main/java/com/b1n_ry/yigd/compat/OriginsCompat.java index ab834a2..55d8730 100644 --- a/src/main/java/com/b1n_ry/yigd/compat/OriginsCompat.java +++ b/src/main/java/com/b1n_ry/yigd/compat/OriginsCompat.java @@ -138,7 +138,7 @@ public DefaultedList storeToPlayer(ServerPlayerEntity player) { continue; for (int i = 0; i < inventoryItems.size(); i++) { - ItemStack currentStack = inventoryItems.get(i).getLeft(); + ItemStack currentStack = inventoryItems.get(i).getLeft().copy(); if (i >= power.size()) { extraItems.add(currentStack); @@ -150,7 +150,7 @@ public DefaultedList storeToPlayer(ServerPlayerEntity player) { for (String key : unhandledPowers) { for (Pair pair : this.inventory.get(key)) { - extraItems.add(pair.getLeft()); + extraItems.add(pair.getLeft().copy()); } } diff --git a/src/main/java/com/b1n_ry/yigd/compat/TravelersBackpackCompat.java b/src/main/java/com/b1n_ry/yigd/compat/TravelersBackpackCompat.java index 2ff4bc0..8b13a60 100644 --- a/src/main/java/com/b1n_ry/yigd/compat/TravelersBackpackCompat.java +++ b/src/main/java/com/b1n_ry/yigd/compat/TravelersBackpackCompat.java @@ -94,7 +94,7 @@ public DefaultedList merge(CompatComponent mergingComponent, Serve public DefaultedList storeToPlayer(ServerPlayerEntity player) { if (this.inventory.getLeft().isEmpty()) return DefaultedList.of(); - ComponentUtils.equipBackpack(player, this.inventory.getLeft()); + ComponentUtils.equipBackpack(player, this.inventory.getLeft().copy()); return DefaultedList.of(); } diff --git a/src/main/java/com/b1n_ry/yigd/compat/TrinketsCompat.java b/src/main/java/com/b1n_ry/yigd/compat/TrinketsCompat.java index ac6faca..8409b32 100644 --- a/src/main/java/com/b1n_ry/yigd/compat/TrinketsCompat.java +++ b/src/main/java/com/b1n_ry/yigd/compat/TrinketsCompat.java @@ -247,7 +247,7 @@ public DefaultedList storeToPlayer(ServerPlayerEntity player) { if (componentSlots == null) { // The trinket group is missing, and all those items need to be added to extraItems for (DefaultedList> itemList : group.getValue().values()) { for (Pair stack : itemList) { - extraItems.add(stack.getLeft()); + extraItems.add(stack.getLeft().copy()); } } continue; @@ -261,7 +261,7 @@ public DefaultedList storeToPlayer(ServerPlayerEntity player) { if (trinketInventory == null) { // The trinket slot is missing, and all those items need to be added to extraItems for (Pair stack : slotItems) { - extraItems.add(stack.getLeft()); + extraItems.add(stack.getLeft().copy()); } continue; } @@ -269,7 +269,7 @@ public DefaultedList storeToPlayer(ServerPlayerEntity player) { // Traverse through item stacks for (int i = 0; i < slotItems.size(); i++) { Pair pair = slotItems.get(i); - ItemStack item = pair.getLeft(); + ItemStack item = pair.getLeft().copy(); if (i >= trinketInventory.size()) { extraItems.add(item); continue; diff --git a/src/main/java/com/b1n_ry/yigd/components/GraveComponent.java b/src/main/java/com/b1n_ry/yigd/components/GraveComponent.java index 7d25bee..6a029be 100644 --- a/src/main/java/com/b1n_ry/yigd/components/GraveComponent.java +++ b/src/main/java/com/b1n_ry/yigd/components/GraveComponent.java @@ -657,6 +657,7 @@ public void onDestroyed() { YigdConfig config = YigdConfig.getConfig(); + Yigd.LOGGER.info("Grave belonging to {} was detected destroyed at X: {}, Y: {}, Z: {} / {}", owner.getGameProfile().getName(), this.pos.getX(), this.pos.getY(), this.pos.getZ(), this.worldRegistryKey.getValue()); if (config.graveConfig.notifyOwnerIfDestroyed) { owner.sendMessage(Text.translatable("text.yigd.message.grave_destroyed")); } diff --git a/src/main/java/com/b1n_ry/yigd/components/InventoryComponent.java b/src/main/java/com/b1n_ry/yigd/components/InventoryComponent.java index 3fc60b1..1df801a 100644 --- a/src/main/java/com/b1n_ry/yigd/components/InventoryComponent.java +++ b/src/main/java/com/b1n_ry/yigd/components/InventoryComponent.java @@ -208,7 +208,8 @@ private void loseRandomItem() { YigdConfig.InventoryConfig.ItemLossConfig itemLoss = config.inventoryConfig.itemLoss; List itemSlots = new ArrayList<>(); - for (int i = 0; i < this.items.size(); i++) { + int vanillaLimit = this.items.size(); + for (int i = 0; i < vanillaLimit; i++) { Pair pair = this.items.get(i); ItemStack stack = pair.getLeft(); if (stack.isEmpty()) continue; @@ -217,6 +218,18 @@ private void loseRandomItem() { itemSlots.add(i); } + DefaultedList extraItems = DefaultedList.of(); + if (itemLoss.includeModdedInventories) { + for (CompatComponent compatComponent : this.modInventoryItems.values()) { + for (Pair tuple : compatComponent.getAsStackDropList()) { + if (tuple.getLeft().isEmpty()) continue; + extraItems.add(tuple.getLeft()); + } + } + for (int i = 0; i < extraItems.size(); i++) { + itemSlots.add(vanillaLimit + i); + } + } if (itemSlots.isEmpty()) return; @@ -224,11 +237,21 @@ private void loseRandomItem() { int slot = itemSlots.get(random); if (itemLoss.affectStacks) { - this.items.get(slot).setRight(DropRule.DESTROY); + if (slot >= vanillaLimit) { + ItemStack toBeRemoved = extraItems.get(slot - vanillaLimit); + this.handleItemPairs(s -> !s.equals("vanilla"), (stack, s, pair) -> { + if (stack.equals(toBeRemoved)) pair.setRight(DropRule.DESTROY); + }); + } else { + this.items.get(slot).setRight(DropRule.DESTROY); + } } else { - ItemStack stack = this.items.get(slot).getLeft(); + ItemStack stack = slot >= vanillaLimit ? extraItems.get(slot - vanillaLimit) : this.items.get(slot).getLeft(); stack.decrement(1); + if (stack.isEmpty() || stack.getCount() == 0) { + itemSlots.remove(Integer.valueOf(slot)); // Make sure we can't lose this item again + } } } @@ -537,7 +560,7 @@ public DefaultedList applyToPlayer(ServerPlayerEntity player) { playerInvIndex = groupIndex + invMainSize + invArmorSize + invOffHandSize; } - ItemStack stack = this.items.get(i).getLeft(); + ItemStack stack = this.items.get(i).getLeft().copy(); if (playerInvIndex >= inventory.size() || playerInvIndex == -1) { extraItems.add(stack); diff --git a/src/main/java/com/b1n_ry/yigd/config/YigdConfig.java b/src/main/java/com/b1n_ry/yigd/config/YigdConfig.java index 3084352..69db968 100644 --- a/src/main/java/com/b1n_ry/yigd/config/YigdConfig.java +++ b/src/main/java/com/b1n_ry/yigd/config/YigdConfig.java @@ -71,6 +71,7 @@ public static class ItemLossConfig { public int percentChanceOfLoss = 50; @Comment("If true, you can lose soulbound items from the item loss feature") public boolean canLoseSoulbound = false; + public boolean includeModdedInventories = true; } } @@ -138,9 +139,10 @@ public static class GraveConfig { public boolean storeXp = true; @Comment("Inform player where the grave generated when respawning") public boolean informGraveLocation = true; - @Comment("If true, you HAVE to have one of `requiredItem` for a grave to generate. One of that item will then be consumed") + @Comment("If true, you HAVE to have `requiredItemCount` number of `requiredItem` for a grave to generate. That many of that item will then be consumed") public boolean requireItem = false; public String requiredItem = "yigd:grave"; + public int requiredItemCount = 1; // require shovel to open public boolean requireShovelToLoot = false; // retrieve method (list with enums) diff --git a/src/main/java/com/b1n_ry/yigd/events/YigdServerEventHandler.java b/src/main/java/com/b1n_ry/yigd/events/YigdServerEventHandler.java index 68435f3..3cecdec 100644 --- a/src/main/java/com/b1n_ry/yigd/events/YigdServerEventHandler.java +++ b/src/main/java/com/b1n_ry/yigd/events/YigdServerEventHandler.java @@ -193,7 +193,7 @@ public static void registerEventCallbacks() { if (graveConfig.requireItem) { Item item = Registries.ITEM.get(new Identifier(graveConfig.requiredItem)); - if (!grave.getInventoryComponent().removeItem(stack -> stack.isOf(item), 1)) { + if (!grave.getInventoryComponent().removeItem(stack -> stack.isOf(item), graveConfig.requiredItemCount)) { return false; } } diff --git a/src/main/resources/assets/yigd/lang/en_us.json b/src/main/resources/assets/yigd/lang/en_us.json index 1e76265..6af7763 100644 --- a/src/main/resources/assets/yigd/lang/en_us.json +++ b/src/main/resources/assets/yigd/lang/en_us.json @@ -92,6 +92,7 @@ "text.autoconfig.yigd.option.inventoryConfig.itemLoss.lossRangeTo": "Range To", "text.autoconfig.yigd.option.inventoryConfig.itemLoss.percentChanceOfLoss": "% Chance of Loss Per Item", "text.autoconfig.yigd.option.inventoryConfig.itemLoss.canLoseSoulbound": "Can Affect Soulbound", + "text.autoconfig.yigd.option.inventoryConfig.itemLoss.includeModdedInventories": "Enable Loss from Modded Inventories", "text.autoconfig.yigd.option.inventoryConfig.vanishingEnchantments": "Vanishing Enchantments", "text.autoconfig.yigd.option.inventoryConfig.soulboundEnchantments": "Soulbound Enchantments", "text.autoconfig.yigd.option.inventoryConfig.loseSoulboundLevelOnDeath": "Lose Soulbound Level on Death", @@ -109,6 +110,7 @@ "text.autoconfig.yigd.option.graveConfig.informGraveLocation": "Inform Grave Location", "text.autoconfig.yigd.option.graveConfig.requireItem": "Require Item", "text.autoconfig.yigd.option.graveConfig.requiredItem": "Required Item", + "text.autoconfig.yigd.option.graveConfig.requiredItemCount": "Required Item Count", "text.autoconfig.yigd.option.graveConfig.requireShovelToLoot": "Require Shovel to Loot", "text.autoconfig.yigd.option.graveConfig.retrieveMethods": "Retrieve-Methods", "text.autoconfig.yigd.option.graveConfig.retrieveMethods.onClick": "On Click",