Skip to content

Commit

Permalink
Stuff
Browse files Browse the repository at this point in the history
Item loss can now optionally be applied to modded inventories
Item loss will now not try and remove the same item twice, and count it as 2 items (more reliavle 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
  • Loading branch information
B1n-ry committed Nov 3, 2024
1 parent 7dcff06 commit 78a8d86
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 21 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 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 @@ -248,20 +248,20 @@ public DefaultedList<ItemStack> storeToPlayer(ServerPlayerEntity player) {
for (int i = 0; i < inventorySlot.normal.size(); i++) {
Pair<ItemStack, DropRule> 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<ItemStack, DropRule> 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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public BeansBackpackInv getInventory(ServerPlayerEntity player) {
public DefaultedList<ItemStack> storeToPlayer(ServerPlayerEntity player) {
DefaultedList<ItemStack> extraItems = DefaultedList.of();

ItemStack backpack = this.inventory.getBackpack();
ItemStack backpack = this.inventory.getBackpack().copy();
DefaultedList<ItemStack> backpackContents = this.inventory.getBackpackContents();
if (backpack.isEmpty()) {
for (ItemStack extra : backpackContents) {
if (!extra.isEmpty())
extraItems.add(extra);
extraItems.add(extra.copy());
}
return extraItems;
}
Expand All @@ -141,7 +141,7 @@ public DefaultedList<ItemStack> storeToPlayer(ServerPlayerEntity player) {
backpackInventory.clear();
for (ItemStack stack : backpackContents) {
if (!stack.isEmpty()) {
backpackInventory.add(stack);
backpackInventory.add(stack.copy());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/b1n_ry/yigd/compat/InventorioCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public DefaultedList<ItemStack> 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 {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/b1n_ry/yigd/compat/OriginsCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public DefaultedList<ItemStack> 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);
Expand All @@ -150,7 +150,7 @@ public DefaultedList<ItemStack> storeToPlayer(ServerPlayerEntity player) {

for (String key : unhandledPowers) {
for (Pair<ItemStack, DropRule> pair : this.inventory.get(key)) {
extraItems.add(pair.getLeft());
extraItems.add(pair.getLeft().copy());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public DefaultedList<ItemStack> merge(CompatComponent<?> mergingComponent, Serve
public DefaultedList<ItemStack> 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();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/b1n_ry/yigd/compat/TrinketsCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public DefaultedList<ItemStack> storeToPlayer(ServerPlayerEntity player) {
if (componentSlots == null) { // The trinket group is missing, and all those items need to be added to extraItems
for (DefaultedList<Pair<ItemStack, DropRule>> itemList : group.getValue().values()) {
for (Pair<ItemStack, DropRule> stack : itemList) {
extraItems.add(stack.getLeft());
extraItems.add(stack.getLeft().copy());
}
}
continue;
Expand All @@ -261,15 +261,15 @@ public DefaultedList<ItemStack> storeToPlayer(ServerPlayerEntity player) {

if (trinketInventory == null) { // The trinket slot is missing, and all those items need to be added to extraItems
for (Pair<ItemStack, DropRule> stack : slotItems) {
extraItems.add(stack.getLeft());
extraItems.add(stack.getLeft().copy());
}
continue;
}

// Traverse through item stacks
for (int i = 0; i < slotItems.size(); i++) {
Pair<ItemStack, DropRule> pair = slotItems.get(i);
ItemStack item = pair.getLeft();
ItemStack item = pair.getLeft().copy();
if (i >= trinketInventory.size()) {
extraItems.add(item);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
31 changes: 27 additions & 4 deletions src/main/java/com/b1n_ry/yigd/components/InventoryComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ private void loseRandomItem() {
YigdConfig.InventoryConfig.ItemLossConfig itemLoss = config.inventoryConfig.itemLoss;

List<Integer> 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<ItemStack, DropRule> pair = this.items.get(i);
ItemStack stack = pair.getLeft();
if (stack.isEmpty()) continue;
Expand All @@ -217,18 +218,40 @@ private void loseRandomItem() {

itemSlots.add(i);
}
DefaultedList<ItemStack> extraItems = DefaultedList.of();
if (itemLoss.includeModdedInventories) {
for (CompatComponent<?> compatComponent : this.modInventoryItems.values()) {
for (Pair<ItemStack, DropRule> 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;

int random = RANDOM.nextInt(itemSlots.size());

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
}
}
}

Expand Down Expand Up @@ -537,7 +560,7 @@ public DefaultedList<ItemStack> 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);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/b1n_ry/yigd/config/YigdConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/yigd/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 78a8d86

Please sign in to comment.