From 4cb22c059e27f31abbf52bde148d5aaf04d879fd Mon Sep 17 00:00:00 2001 From: VT-14 Date: Mon, 2 Oct 2023 23:23:09 -0400 Subject: [PATCH 1/4] Expand InventoryHelper & Update PlayerUtil.findItem(). Expand InventoryHelper with methods to find a specific inventory, and all registered inventories excluding certain ones. Together these allow a method to check inventories in a specific order, but still be able to check all registered inventories. Update PlayerUtil.findItem() to use the update InventoryHelper. This is needed to allow it to check Curios and any add-on mod inventories. Decided to check Curios before the Main Inventory, but after the Off-Hand slot. --- .../bloodmagic/core/util/PlayerUtil.java | 38 ++++++++++++++++--- .../util/helper/InventoryHelper.java | 38 +++++++++++++++++-- 2 files changed, 68 insertions(+), 8 deletions(-) diff --git a/src/main/java/wayoftime/bloodmagic/core/util/PlayerUtil.java b/src/main/java/wayoftime/bloodmagic/core/util/PlayerUtil.java index ccd364f98..0b43952e4 100644 --- a/src/main/java/wayoftime/bloodmagic/core/util/PlayerUtil.java +++ b/src/main/java/wayoftime/bloodmagic/core/util/PlayerUtil.java @@ -1,16 +1,21 @@ package wayoftime.bloodmagic.core.util; +import java.util.ArrayList; +import java.util.List; import java.util.function.Predicate; import com.google.common.collect.Multimap; +import net.minecraft.core.NonNullList; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import wayoftime.bloodmagic.BloodMagic; import wayoftime.bloodmagic.common.item.ExpandedArmor; import wayoftime.bloodmagic.core.living.LivingUtil; +import wayoftime.bloodmagic.util.helper.InventoryHelper; public class PlayerUtil { @@ -22,13 +27,36 @@ public static ItemStack findItem(Player player, Predicate requirement ItemStack offHand = player.getOffhandItem(); if (requirements.test(offHand)) return offHand; + List checkedInventories = new ArrayList<>(); + checkedInventories.add("offHandInventory"); - // Check inventory next - for (int slot = 0; slot < player.getInventory().getContainerSize(); slot++) + // Check Curios next, if available. + if (BloodMagic.curiosLoaded) { - ItemStack foundStack = player.getInventory().getItem(slot); - if (!foundStack.isEmpty() && requirements.test(foundStack)) - return foundStack; + NonNullList curiosInventory = InventoryHelper.getInventory(player, "curiosInventory"); + for (ItemStack item : curiosInventory) + { + if (requirements.test(item)) + return item; + } + checkedInventories.add("curiosInventory"); + } + + // Check Main Inventory next. + NonNullList mainInventory = InventoryHelper.getInventory(player, "mainInventory"); + for (ItemStack item : mainInventory) + { + if (requirements.test(item)) + return item; + } + checkedInventories.add("mainInventory"); + + // Check all remaining registered inventories. Armor and Add-ons. + NonNullList remainingInventories = InventoryHelper.getAllInventoriesExcluding(player, checkedInventories); + for (ItemStack item : remainingInventories) + { + if (requirements.test(item)) + return item; } return ItemStack.EMPTY; diff --git a/src/main/java/wayoftime/bloodmagic/util/helper/InventoryHelper.java b/src/main/java/wayoftime/bloodmagic/util/helper/InventoryHelper.java index 57128ba06..b2259feed 100644 --- a/src/main/java/wayoftime/bloodmagic/util/helper/InventoryHelper.java +++ b/src/main/java/wayoftime/bloodmagic/util/helper/InventoryHelper.java @@ -1,5 +1,7 @@ package wayoftime.bloodmagic.util.helper; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.function.Function; @@ -11,6 +13,21 @@ public class InventoryHelper { + private static Map>> inventoryProvider = BloodMagicAPI.INSTANCE.getInventoryProvider(); + + /** + * Gets all items from the specified inventory. + * + * @param player - The player who's inventories to check. + * @param inventoryKey - inventory's name. See BloodMagicCorePlugin for the vanilla ones. + * @return - NonNullList of all items in those inventories. + */ + public static NonNullList getInventory(Player player, String inventoryKey) + { + NonNullList inventory = NonNullList.create(); + inventory.addAll(inventoryProvider.get(inventoryKey).apply(player)); + return inventory; + } /** * Gets all items from all registered inventories. @@ -20,7 +37,6 @@ public class InventoryHelper */ public static NonNullList getAllInventories(Player player) { - Map>> inventoryProvider = BloodMagicAPI.INSTANCE.getInventoryProvider(); NonNullList inventory = NonNullList.create(); inventoryProvider.forEach((identifier, provider) -> inventory.addAll(provider.apply(player))); @@ -28,6 +44,22 @@ public static NonNullList getAllInventories(Player player) return inventory; } + /** + * Gets all items from all inventories, excluding the listed inventories + * + * @param player - The player who's inventories to check. + * @param excludedInventoryKeys - inventory keys to exclude. See BloodMagicCorePlugin for the vanilla ones. + * @return - NonNullList of all items in those inventories. + */ + public static NonNullList getAllInventoriesExcluding(Player player, List excludedInventoryKeys) + { + NonNullList inventory = NonNullList.create(); + + inventoryProvider.forEach((identifier, provider) -> {if (!identifier.equals(excludedInventoryKeys)) {inventory.addAll(provider.apply(player));}}); + + return inventory; + } + /** * Gets all items from all registered inventories marked as active as well as * main and off hand @@ -37,10 +69,10 @@ public static NonNullList getAllInventories(Player player) */ public static NonNullList getActiveInventories(Player player) { - Map>> inventoryProviders = BloodMagicAPI.INSTANCE.getActiveInventoryProvider(); + Map>> activeInventoryProvider = BloodMagicAPI.INSTANCE.getActiveInventoryProvider(); NonNullList inventories = NonNullList.create(); - inventoryProviders.forEach((identifier, provider) -> inventories.addAll(provider.apply(player))); + activeInventoryProvider.forEach((identifier, provider) -> inventories.addAll(provider.apply(player))); inventories.add(player.getItemInHand(InteractionHand.MAIN_HAND)); inventories.add(player.getItemInHand(InteractionHand.OFF_HAND)); From 884a6cbbeb1392876dc3706d23ce233bc8046a53 Mon Sep 17 00:00:00 2001 From: VT-14 Date: Mon, 2 Oct 2023 23:38:10 -0400 Subject: [PATCH 2/4] Make the Living Armour Training Bracelet a Curio Gives the player a Bracelet slot by default. Allows the player to put the Training Bracelet in either the Bracelet or LA Socket slots. Add a note to the Sanguine Scientiem about how only one will work at a time; Off-hand > Curios > Main Inventory (including Main Hand) > Add-on inventories. --- .../alchemy_array/living_equipment/training_bracelet.json | 2 +- .../data/bloodmagic/curios/entities/bmplayerslots.json | 1 + src/main/resources/data/curios/tags/items/bracelet.json | 6 ++++++ .../data/curios/tags/items/living_armour_socket.json | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/data/curios/tags/items/bracelet.json diff --git a/src/main/resources/assets/bloodmagic/patchouli_books/guide/en_us/entries/alchemy_array/living_equipment/training_bracelet.json b/src/main/resources/assets/bloodmagic/patchouli_books/guide/en_us/entries/alchemy_array/living_equipment/training_bracelet.json index 24b1c09bc..f2dcc160d 100644 --- a/src/main/resources/assets/bloodmagic/patchouli_books/guide/en_us/entries/alchemy_array/living_equipment/training_bracelet.json +++ b/src/main/resources/assets/bloodmagic/patchouli_books/guide/en_us/entries/alchemy_array/living_equipment/training_bracelet.json @@ -11,7 +11,7 @@ "type": "bloodmagic:crafting_array", "heading": "Training Bracelet", "recipe": "bloodmagic:array/living_trainer", - "text": "$(italic)*Insert Rocky Training Montage here*$()" + "text": "$(italic)*Insert Rocky Training Montage here*$()$(br2)Only one of these bracelets will work at a time. Off-hand > Curios (if available) > Main Inventory (including main hand) > add-on inventories." }, { "type": "patchouli:image", diff --git a/src/main/resources/data/bloodmagic/curios/entities/bmplayerslots.json b/src/main/resources/data/bloodmagic/curios/entities/bmplayerslots.json index 57f4addc7..f0ec4e24c 100644 --- a/src/main/resources/data/bloodmagic/curios/entities/bmplayerslots.json +++ b/src/main/resources/data/bloodmagic/curios/entities/bmplayerslots.json @@ -3,6 +3,7 @@ "slots": [ "charm", "necklace", + "bracelet", "living_armour_socket" ] } \ No newline at end of file diff --git a/src/main/resources/data/curios/tags/items/bracelet.json b/src/main/resources/data/curios/tags/items/bracelet.json new file mode 100644 index 000000000..8fc77363c --- /dev/null +++ b/src/main/resources/data/curios/tags/items/bracelet.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "bloodmagic:upgradetrainer" + ] +} \ No newline at end of file diff --git a/src/main/resources/data/curios/tags/items/living_armour_socket.json b/src/main/resources/data/curios/tags/items/living_armour_socket.json index 7ca41a545..c177aeb10 100644 --- a/src/main/resources/data/curios/tags/items/living_armour_socket.json +++ b/src/main/resources/data/curios/tags/items/living_armour_socket.json @@ -12,6 +12,7 @@ "bloodmagic:soulgempetty", "bloodmagic:soulgemlesser", "bloodmagic:soulgemcommon", - "bloodmagic:soulgemgreater" + "bloodmagic:soulgemgreater", + "bloodmagic:upgradetrainer" ] } \ No newline at end of file From 85772ced8d44fb10db09d226f902e6777c585873 Mon Sep 17 00:00:00 2001 From: VT-14 Date: Tue, 3 Oct 2023 00:00:47 -0400 Subject: [PATCH 3/4] Demon Will Aura Gauge +Curio, -Active Slots Only Adjusted `Utils.canPlayerSeeDemonWill()` and `Utils.getDemonWillResolution()` to use the `InventoryHelper`. Functionality Change: The new implementation checks only "active" slots (Main and Off-hands, Curios, and any slots add-ons mark as active). With base Blood Magic that means the gauge will only show up when held or in a Curios slot. Added tags needed to put the Demon Will Aura Gauge in the Curios Charm and LA Socket slots. --- .../java/wayoftime/bloodmagic/util/Utils.java | 38 +++---------------- .../data/curios/tags/items/charm.json | 3 +- .../tags/items/living_armour_socket.json | 3 +- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/src/main/java/wayoftime/bloodmagic/util/Utils.java b/src/main/java/wayoftime/bloodmagic/util/Utils.java index a7093ffc7..15a8c9d21 100644 --- a/src/main/java/wayoftime/bloodmagic/util/Utils.java +++ b/src/main/java/wayoftime/bloodmagic/util/Utils.java @@ -8,6 +8,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; @@ -43,6 +44,7 @@ import net.minecraftforge.items.wrapper.SidedInvWrapper; import wayoftime.bloodmagic.api.compat.IDemonWillViewer; import wayoftime.bloodmagic.common.tile.TileInventory; +import wayoftime.bloodmagic.util.helper.InventoryHelper; import wayoftime.bloodmagic.util.helper.NBTHelper; public class Utils @@ -571,55 +573,27 @@ public static ItemStack[] combineStacks(ItemStack stack1, ItemStack stack2) public static boolean canPlayerSeeDemonWill(Player player) { - IItemHandler inventory = new PlayerMainInvWrapper(player.getInventory()); - - for (int i = 0; i < inventory.getSlots(); i++) + NonNullList inventory = InventoryHelper.getActiveInventories(player); + for (ItemStack stack : inventory) { - ItemStack stack = inventory.getStackInSlot(i); - if (stack.isEmpty()) - { - continue; - } - if (stack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) stack.getItem()).canSeeDemonWillAura(player.getCommandSenderWorld(), stack, player)) { return true; } } - - ItemStack offhandStack = player.getOffhandItem(); - if (!offhandStack.isEmpty() && offhandStack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) offhandStack.getItem()).canSeeDemonWillAura(player.getCommandSenderWorld(), offhandStack, player)) - { - return true; - } - return false; } public static double getDemonWillResolution(Player player) { - IItemHandler inventory = new PlayerMainInvWrapper(player.getInventory()); - - for (int i = 0; i < inventory.getSlots(); i++) + NonNullList inventory = InventoryHelper.getActiveInventories(player); + for (ItemStack stack : inventory) { - ItemStack stack = inventory.getStackInSlot(i); - if (stack.isEmpty()) - { - continue; - } - if (stack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) stack.getItem()).canSeeDemonWillAura(player.getCommandSenderWorld(), stack, player)) { return ((IDemonWillViewer) stack.getItem()).getDemonWillAuraResolution(player.getCommandSenderWorld(), stack, player); } } - - ItemStack offhandStack = player.getOffhandItem(); - if (!offhandStack.isEmpty() && offhandStack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) offhandStack.getItem()).canSeeDemonWillAura(player.getCommandSenderWorld(), offhandStack, player)) - { - return ((IDemonWillViewer) offhandStack.getItem()).getDemonWillAuraResolution(player.getCommandSenderWorld(), offhandStack, player); - } - return 100; } diff --git a/src/main/resources/data/curios/tags/items/charm.json b/src/main/resources/data/curios/tags/items/charm.json index e2c10b162..74d4fbc50 100644 --- a/src/main/resources/data/curios/tags/items/charm.json +++ b/src/main/resources/data/curios/tags/items/charm.json @@ -8,6 +8,7 @@ "bloodmagic:sigilofholding", "bloodmagic:divinationsigil", "bloodmagic:seersigil", - "bloodmagic:experiencebook" + "bloodmagic:experiencebook", + "bloodmagic:demonwillgauge" ] } \ No newline at end of file diff --git a/src/main/resources/data/curios/tags/items/living_armour_socket.json b/src/main/resources/data/curios/tags/items/living_armour_socket.json index c177aeb10..7287eb9f9 100644 --- a/src/main/resources/data/curios/tags/items/living_armour_socket.json +++ b/src/main/resources/data/curios/tags/items/living_armour_socket.json @@ -13,6 +13,7 @@ "bloodmagic:soulgemlesser", "bloodmagic:soulgemcommon", "bloodmagic:soulgemgreater", - "bloodmagic:upgradetrainer" + "bloodmagic:upgradetrainer", + "bloodmagic:demonwillgauge" ] } \ No newline at end of file From 2c4291d314974d515c439c5cb153ad42cdf629db Mon Sep 17 00:00:00 2001 From: VT-14 Date: Tue, 3 Oct 2023 00:26:20 -0400 Subject: [PATCH 4/4] Sigil of Suppression Curio Add the Tags needed to put the Sigil of Suppression in the Charm and LA Socket slots. --- src/main/resources/data/curios/tags/items/charm.json | 1 + .../resources/data/curios/tags/items/living_armour_socket.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/resources/data/curios/tags/items/charm.json b/src/main/resources/data/curios/tags/items/charm.json index 74d4fbc50..1aa8010aa 100644 --- a/src/main/resources/data/curios/tags/items/charm.json +++ b/src/main/resources/data/curios/tags/items/charm.json @@ -8,6 +8,7 @@ "bloodmagic:sigilofholding", "bloodmagic:divinationsigil", "bloodmagic:seersigil", + "bloodmagic:sigilofsuppression", "bloodmagic:experiencebook", "bloodmagic:demonwillgauge" ] diff --git a/src/main/resources/data/curios/tags/items/living_armour_socket.json b/src/main/resources/data/curios/tags/items/living_armour_socket.json index 7287eb9f9..fe2b98de6 100644 --- a/src/main/resources/data/curios/tags/items/living_armour_socket.json +++ b/src/main/resources/data/curios/tags/items/living_armour_socket.json @@ -8,6 +8,7 @@ "bloodmagic:sigilofholding", "bloodmagic:divinationsigil", "bloodmagic:seersigil", + "bloodmagic:sigilofsuppression", "bloodmagic:experiencebook", "bloodmagic:soulgempetty", "bloodmagic:soulgemlesser",