diff --git a/CHANGELOG.md b/CHANGELOG.md index 3669a7b..5f628cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # You're in Grave Danger 2.0.7 +### Changes +* Added compat with [Cosmetic Armor Reworked](https://www.curseforge.com/minecraft/mc-mods/cosmetic-armor-reworked) + --- # You're in Grave Danger 2.0.6 diff --git a/build.gradle b/build.gradle index 4a185b2..3717aef 100644 --- a/build.gradle +++ b/build.gradle @@ -90,6 +90,16 @@ repositories { includeGroup "maven.modrinth" } } + exclusiveContent { + forRepository { + maven { + url "https://cursemaven.com" + } + } + filter { + includeGroup "curse.maven" + } + } } dependencies { @@ -98,6 +108,7 @@ dependencies { compileOnly "io.wispforest:accessories-neoforge:${project.accessories_version}" compileOnly "top.theillusivec4.curios:curios-neoforge:${project.curios_version}" compileOnly "maven.modrinth:travelersbackpack:${project.travelers_backpack_version}" + compileOnly "curse.maven:cosmeticarmor-${project.cosmetic_armor_version}" } base { diff --git a/gradle.properties b/gradle.properties index 1da57bb..50d9f8e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -54,3 +54,4 @@ config_version=15.0.128 accessories_version=1.0.0-beta.30+1.21 curios_version=9.0.5+1.21 travelers_backpack_version=e2aP2Euz +cosmetic_armor_version=237307:5610814 diff --git a/src/main/java/com/b1n_ry/yigd/compat/CosmeticArmorCompat.java b/src/main/java/com/b1n_ry/yigd/compat/CosmeticArmorCompat.java new file mode 100644 index 0000000..855b5ba --- /dev/null +++ b/src/main/java/com/b1n_ry/yigd/compat/CosmeticArmorCompat.java @@ -0,0 +1,165 @@ +package com.b1n_ry.yigd.compat; + +import com.b1n_ry.yigd.components.InventoryComponent; +import com.b1n_ry.yigd.config.YigdConfig; +import com.b1n_ry.yigd.data.DeathContext; +import com.b1n_ry.yigd.events.YigdEvents; +import com.b1n_ry.yigd.util.DropRule; +import lain.mods.cos.impl.ModObjects; +import lain.mods.cos.impl.inventory.InventoryCosArmor; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Tuple; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.common.NeoForge; + +import java.util.function.Predicate; + +public class CosmeticArmorCompat implements InvModCompat>> { + @Override + public String getModName() { + return "cosmeticarmor"; + } + + @Override + public void clear(ServerPlayer player) { + InventoryCosArmor inv = ModObjects.invMan.getCosArmorInventory(player.getUUID()); + inv.clearContent(); + } + + @Override + public CompatComponent>> readNbt(CompoundTag nbt, HolderLookup.Provider registries) { + NonNullList> items = InventoryComponent.listFromNbt(nbt, itemTag -> { + DropRule dropRule = DropRule.valueOf(itemTag.getString("dropRule")); + ItemStack stack = ItemStack.parse(registries, itemTag).orElse(ItemStack.EMPTY); + return new Tuple<>(stack, dropRule); + }, InventoryComponent.EMPTY_ITEM_PAIR); + return new CosmeticArmorCompatComponent(items); + } + + @Override + public CompatComponent>> getNewComponent(ServerPlayer player) { + return new CosmeticArmorCompatComponent(player); + } + + static class CosmeticArmorCompatComponent extends CompatComponent>> { + public CosmeticArmorCompatComponent(ServerPlayer player) { + super(player); + } + public CosmeticArmorCompatComponent(NonNullList> inventory) { + super(inventory); + } + + @Override + public NonNullList> getInventory(ServerPlayer player) { + InventoryCosArmor inventory = ModObjects.invMan.getCosArmorInventory(player.getUUID()); + NonNullList> list = NonNullList.create(); + for (int i = 0; i < inventory.getContainerSize(); i++) { + ItemStack stack = inventory.getItem(i); + list.add(new Tuple<>(stack, DropRule.PUT_IN_GRAVE)); + } + return list; + } + + @Override + public NonNullList storeToPlayer(ServerPlayer player) { + NonNullList extraItems = NonNullList.create(); + InventoryCosArmor cosArmor = ModObjects.invMan.getCosArmorInventory(player.getUUID()); + + for (int i = 0; i < cosArmor.getContainerSize(); i++) { + if (i >= this.inventory.size()) break; + ItemStack stack = this.inventory.get(i).getA(); + if (cosArmor.getItem(i).isEmpty()) { + cosArmor.setItem(i, stack); + } else { + extraItems.add(stack); + } + } + return extraItems; + } + + @Override + public void handleDropRules(DeathContext context) { + YigdConfig.CompatConfig compatConfig = YigdConfig.getConfig().compatConfig; + + for (Tuple tuple : this.inventory) { + if (tuple.getA().isEmpty()) continue; + DropRule dropRule = compatConfig.defaultCosmeticArmorDropRule; + + if (dropRule != DropRule.PUT_IN_GRAVE) continue; + dropRule = NeoForge.EVENT_BUS.post(new YigdEvents.DropRuleEvent(tuple.getA(), -1, context, true)).getDropRule(); + + tuple.setB(dropRule); + } + } + + @Override + public NonNullList> getAsStackDropList() { + return NonNullList.copyOf(this.inventory); + } + + @Override + public void clear() { + this.inventory.clear(); + } + + @Override + public CompoundTag writeNbt(HolderLookup.Provider registries) { + return InventoryComponent.listToNbt(this.inventory, tuple -> { + CompoundTag itemTag = (CompoundTag) tuple.getA().save(registries); + itemTag.putString("dropRule", tuple.getB().toString()); + return itemTag; + }, tuple -> tuple.getA().isEmpty()); + } + + @Override + public boolean removeItem(Predicate predicate, int itemCount) { + for (Tuple tuple : this.inventory) { + ItemStack stack = tuple.getA(); + if (predicate.test(stack)) { + stack.shrink(itemCount); + return true; + } + } + return false; + } + + @Override + public CompatComponent>> filterInv(Predicate predicate) { + NonNullList> list = NonNullList.create(); + for (Tuple tuple : this.inventory) { + if (predicate.test(tuple.getB())) { + list.add(tuple); + } else { + list.add(InventoryComponent.EMPTY_ITEM_PAIR); + } + } + return new CosmeticArmorCompatComponent(list); + } + + @Override + public NonNullList merge(CompatComponent mergingComponent, ServerPlayer merger) { + NonNullList extraItems = NonNullList.create(); + + @SuppressWarnings("unchecked") + NonNullList> mergingItems = (NonNullList>) mergingComponent.inventory; + for (int i = 0; i < mergingItems.size(); i++) { + Tuple tuple = mergingItems.get(i); + ItemStack mergingStack = tuple.getA(); + if (i >= this.inventory.size()) { + extraItems.add(mergingStack); + continue; + } + ItemStack thisStack = this.inventory.get(i).getA(); + if (thisStack.isEmpty()) { + this.inventory.set(i, new Tuple<>(mergingStack, tuple.getB())); + } else { + extraItems.add(mergingStack); + } + } + return extraItems; + } + } +} diff --git a/src/main/java/com/b1n_ry/yigd/compat/InvModCompat.java b/src/main/java/com/b1n_ry/yigd/compat/InvModCompat.java index 4564027..85e814c 100644 --- a/src/main/java/com/b1n_ry/yigd/compat/InvModCompat.java +++ b/src/main/java/com/b1n_ry/yigd/compat/InvModCompat.java @@ -27,6 +27,8 @@ static void reloadModCompat() { if (compatConfig.enableTravelersBackpackCompat && !(accessoriesPresent && TravelersBackpackCompat.isAccessoriesIntegrationEnabled())) invCompatMods.add(new TravelersBackpackCompat()); } + if (modList.isLoaded("cosmeticarmorreworked") && compatConfig.enableCosmeticArmorCompat) + invCompatMods.add(new CosmeticArmorCompat()); } String getModName(); 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 58ece4c..b1983f2 100644 --- a/src/main/java/com/b1n_ry/yigd/config/YigdConfig.java +++ b/src/main/java/com/b1n_ry/yigd/config/YigdConfig.java @@ -298,10 +298,10 @@ public static class CompatConfig { @Comment("While PUT_IN_GRAVE, other drop rules will be prioritized") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public DropRule defaultCuriosDropRule = DropRule.PUT_IN_GRAVE; -// public boolean enableBeansBackpacksCompat = true; -// @Comment("While PUT_IN_GRAVE, other drop rules will be prioritized") -// @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) -// public DropRule defaultBeansBackpacksDropRule = DropRule.PUT_IN_GRAVE; + public boolean enableCosmeticArmorCompat = true; + @Comment("While PUT_IN_GRAVE, other drop rules will be prioritized") + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public DropRule defaultCosmeticArmorDropRule = DropRule.PUT_IN_GRAVE; // public boolean enableRespawnObelisksCompat = true; } diff --git a/src/main/resources/assets/yigd/lang/en_us.json b/src/main/resources/assets/yigd/lang/en_us.json index 7049e50..c5511d8 100644 --- a/src/main/resources/assets/yigd/lang/en_us.json +++ b/src/main/resources/assets/yigd/lang/en_us.json @@ -199,22 +199,14 @@ "text.autoconfig.yigd.option.ExtraItemDrop.count": "Amount", "text.autoconfig.yigd.option.ExtraItemDrop.itemNbt": "Item NBT", "text.autoconfig.yigd.option.compatConfig": "Mod Compatibility Config", - "text.autoconfig.yigd.option.compatConfig.standardDropRuleInClaim": "Default Drop Rule While on Claimed Land", - "text.autoconfig.yigd.option.compatConfig.enableInventorioCompat": "Load Inventorio Compat?", - "text.autoconfig.yigd.option.compatConfig.defaultInventorioDropRule": "Default Drop Rule for Items in Inventorio Inventory", - "text.autoconfig.yigd.option.compatConfig.enableLevelzCompat": "Load LevelZ Compat?", - "text.autoconfig.yigd.option.compatConfig.defaultLevelzDropRule": "Default Drop Rule for LevelZ EXP", - "text.autoconfig.yigd.option.compatConfig.enableNumismaticOverhaulCompat": "Load Numismatic Overhaul Compat?", - "text.autoconfig.yigd.option.compatConfig.defaultNumismaticDropRule": "Default Drop Rule for Numismatic Overhaul Coins", - "text.autoconfig.yigd.option.compatConfig.enableOriginsInventoryCompat": "Load Origins Inventory Compat?", - "text.autoconfig.yigd.option.compatConfig.defaultOriginsDropRule": "Default Drop Rule for Items in Origins Inventory", + "text.autoconfig.yigd.option.compatConfig.enableAccessoriesCompat": "Load Accessories Compat?", + "text.autoconfig.yigd.option.compatConfig.defaultAccessoriesDropRule": "Default Drop Rule for Accessories Items", "text.autoconfig.yigd.option.compatConfig.enableTravelersBackpackCompat": "Load Travelers Backpack Compat?", "text.autoconfig.yigd.option.compatConfig.defaultTravelersBackpackDropRule": "Default Drop Rule for Travelers Backpack's Backpack", - "text.autoconfig.yigd.option.compatConfig.enableTrinketsCompat": "Load Trinkets Compat?", - "text.autoconfig.yigd.option.compatConfig.defaultTrinketsDropRule": "Default Drop Rule for All Trinkets", - "text.autoconfig.yigd.option.compatConfig.enableBeansBackpacksCompat": "Load Beans Backpacks Compat?", - "text.autoconfig.yigd.option.compatConfig.defaultBeansBackpacksDropRule": "Default Drop Rule for All Beans Backpacks Items", - "text.autoconfig.yigd.option.compatConfig.enableRespawnObelisksCompat": "Load Respawn Obelisks Compat?", + "text.autoconfig.yigd.option.compatConfig.enableCuriosCompat": "Load Curios Compat?", + "text.autoconfig.yigd.option.compatConfig.defaultCuriosDropRule": "Default Drop Rule for Curios Items", + "text.autoconfig.yigd.option.compatConfig.enableCosmeticArmorCompat": "Load Cosmetic Armor (Reworked) Compat?", + "text.autoconfig.yigd.option.compatConfig.defaultCosmeticArmorDropRule": "Default Drop Rule for Cosmetic Armor (Reworked) Items", "text.autoconfig.yigd.option.commandConfig": "Command Config", "text.autoconfig.yigd.option.commandConfig.mainCommand": "Mod Core Command", "text.autoconfig.yigd.option.commandConfig.basePermissionLevel": "Base Permission Level",