diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ac9cd46..44bb5b5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# You're in Grave Danger 2.0.0-beta.4 + +### Fixes +* Graves generating inside the world when dying outside the world (like falling +out of the end) will now store the grave data +* Origins inventories will now properly handle its own drop rules + +--- + # You're in Grave Danger 2.0.0-beta.3 ### Changes 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 9a89b362..14e8bcf8 100644 --- a/src/main/java/com/b1n_ry/yigd/compat/OriginsCompat.java +++ b/src/main/java/com/b1n_ry/yigd/compat/OriginsCompat.java @@ -1,16 +1,21 @@ package com.b1n_ry.yigd.compat; import com.b1n_ry.yigd.components.InventoryComponent; +import com.b1n_ry.yigd.config.DropType; import com.b1n_ry.yigd.config.YigdConfig; import com.b1n_ry.yigd.data.DeathContext; import com.b1n_ry.yigd.events.DropRuleEvent; import com.b1n_ry.yigd.util.DropRule; import io.github.apace100.apoli.component.PowerHolderComponent; +import io.github.apace100.apoli.component.PowerHolderComponentImpl; import io.github.apace100.apoli.power.Active; import io.github.apace100.apoli.power.InventoryPower; import net.minecraft.inventory.Inventories; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtHelper; +import net.minecraft.nbt.NbtList; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.math.Vec3d; @@ -32,6 +37,7 @@ public void clear(ServerPlayerEntity player) { @Override public CompatComponent>> readNbt(NbtCompound nbt) { Map> inventory = new HashMap<>(); + Map> inventoryDropRules = new HashMap<>(); for (String key : nbt.getKeys()) { NbtCompound inventoryNbt = nbt.getCompound(key); @@ -42,8 +48,22 @@ public CompatComponent>> readNbt(NbtCompoun Inventories.readNbt(inventoryNbt, items); inventory.put(key, items); + + NbtList dropRulesNbt = nbt.getList(key + "_dropRules", NbtElement.COMPOUND_TYPE); + DefaultedList dropRules = DefaultedList.ofSize(size, DropRule.PUT_IN_GRAVE); + for (NbtElement element : dropRulesNbt) { + NbtCompound c = (NbtCompound) element; + int i = c.getInt("Id"); + DropRule dropRule = DropRule.valueOf(c.getString("dropRule")); + dropRules.set(i, dropRule); + } + inventoryDropRules.put(key, dropRules); } - return new OriginsCompatComponent(inventory); + + OriginsCompatComponent returnValue = new OriginsCompatComponent(inventory); + returnValue.inventoryDropRules = inventoryDropRules; + + return returnValue; } @Override @@ -52,6 +72,7 @@ public CompatComponent>> getNewComponent(Se } private static class OriginsCompatComponent extends CompatComponent>> { + private Map> inventoryDropRules = new HashMap<>(); public OriginsCompatComponent(ServerPlayerEntity player) { super(player); @@ -63,18 +84,25 @@ public OriginsCompatComponent(Map> inventory) { @Override public Map> getInventory(ServerPlayerEntity player) { + YigdConfig.CompatConfig compatConfig = YigdConfig.getConfig().compatConfig; + Map> inventory = new HashMap<>(); + this.inventoryDropRules.clear(); List powers = PowerHolderComponent.getPowers(player, InventoryPower.class); for (InventoryPower inventoryPower : powers) { Active.Key key = inventoryPower.getKey(); DefaultedList stacks = DefaultedList.of(); + DefaultedList dropRules = DefaultedList.of(); for (int i = 0; i < inventoryPower.size(); i++) { - stacks.add(inventoryPower.getStack(i)); + ItemStack stack = inventoryPower.getStack(i); + stacks.add(stack); + dropRules.add(inventoryPower.shouldDropOnDeath(stack) ? compatConfig.defaultOriginsDropRule : DropRule.KEEP); } inventory.put(key.key, stacks); + this.inventoryDropRules.put(key.key, dropRules); } return inventory; @@ -146,20 +174,22 @@ public DefaultedList storeToPlayer(ServerPlayerEntity player) { @Override public CompatComponent>> handleDropRules(DeathContext context) { - YigdConfig.CompatConfig compatConfig = YigdConfig.getConfig().compatConfig; Map> soulbound = new HashMap<>(); + Vec3d deathPos = context.getDeathPos(); for (Map.Entry> entry : this.inventory.entrySet()) { String key = entry.getKey(); DefaultedList items = entry.getValue(); + DefaultedList dropRules = this.inventoryDropRules.get(key); DefaultedList soulboundStacks = DefaultedList.ofSize(items.size(), ItemStack.EMPTY); for (int i = 0; i < items.size(); i++) { ItemStack item = items.get(i); - DropRule dropRule = compatConfig.defaultOriginsDropRule; + DropRule dropRule = dropRules.get(i); + if (dropRule == DropRule.PUT_IN_GRAVE) dropRule = DropRuleEvent.EVENT.invoker().getDropRule(item, -1, context, true); @@ -223,7 +253,21 @@ public NbtCompound writeNbt() { itemsNbt.putInt("size", items.size()); + NbtList dropRulesNbt = new NbtList(); + DefaultedList dropRules = this.inventoryDropRules.get(entry.getKey()); + for (int j = 0; j < dropRules.size(); j++) { + if (items.get(j).isEmpty()) + continue; + + NbtCompound element = new NbtCompound(); + element.putInt("Id", j); + element.putString("dropRule", dropRules.get(j).toString()); + + dropRulesNbt.add(element); + } + nbt.put(entry.getKey(), itemsNbt); + nbt.put(entry.getKey() + "_dropRules", dropRulesNbt); } return nbt; }