Skip to content

Commit 70457ad

Browse files
authored
Merge pull request #1986 from VT-14/More-Curios
More Curios, Related InventoryHelper Updates, & Demon Will Aura Gauge Tweak
2 parents d629b00 + 2c4291d commit 70457ad

File tree

8 files changed

+89
-43
lines changed

8 files changed

+89
-43
lines changed

src/main/java/wayoftime/bloodmagic/core/util/PlayerUtil.java

+33-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
package wayoftime.bloodmagic.core.util;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
35
import java.util.function.Predicate;
46

57
import com.google.common.collect.Multimap;
68

9+
import net.minecraft.core.NonNullList;
710
import net.minecraft.world.entity.EquipmentSlot;
811
import net.minecraft.world.entity.ai.attributes.Attribute;
912
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
1013
import net.minecraft.world.entity.player.Player;
1114
import net.minecraft.world.item.ItemStack;
15+
import wayoftime.bloodmagic.BloodMagic;
1216
import wayoftime.bloodmagic.common.item.ExpandedArmor;
1317
import wayoftime.bloodmagic.core.living.LivingUtil;
18+
import wayoftime.bloodmagic.util.helper.InventoryHelper;
1419

1520
public class PlayerUtil
1621
{
@@ -22,13 +27,36 @@ public static ItemStack findItem(Player player, Predicate<ItemStack> requirement
2227
ItemStack offHand = player.getOffhandItem();
2328
if (requirements.test(offHand))
2429
return offHand;
30+
List<String> checkedInventories = new ArrayList<>();
31+
checkedInventories.add("offHandInventory");
2532

26-
// Check inventory next
27-
for (int slot = 0; slot < player.getInventory().getContainerSize(); slot++)
33+
// Check Curios next, if available.
34+
if (BloodMagic.curiosLoaded)
2835
{
29-
ItemStack foundStack = player.getInventory().getItem(slot);
30-
if (!foundStack.isEmpty() && requirements.test(foundStack))
31-
return foundStack;
36+
NonNullList<ItemStack> curiosInventory = InventoryHelper.getInventory(player, "curiosInventory");
37+
for (ItemStack item : curiosInventory)
38+
{
39+
if (requirements.test(item))
40+
return item;
41+
}
42+
checkedInventories.add("curiosInventory");
43+
}
44+
45+
// Check Main Inventory next.
46+
NonNullList<ItemStack> mainInventory = InventoryHelper.getInventory(player, "mainInventory");
47+
for (ItemStack item : mainInventory)
48+
{
49+
if (requirements.test(item))
50+
return item;
51+
}
52+
checkedInventories.add("mainInventory");
53+
54+
// Check all remaining registered inventories. Armor and Add-ons.
55+
NonNullList<ItemStack> remainingInventories = InventoryHelper.getAllInventoriesExcluding(player, checkedInventories);
56+
for (ItemStack item : remainingInventories)
57+
{
58+
if (requirements.test(item))
59+
return item;
3260
}
3361

3462
return ItemStack.EMPTY;

src/main/java/wayoftime/bloodmagic/util/Utils.java

+6-32
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import net.minecraft.core.BlockPos;
1010
import net.minecraft.core.Direction;
11+
import net.minecraft.core.NonNullList;
1112
import net.minecraft.nbt.CompoundTag;
1213
import net.minecraft.sounds.SoundEvents;
1314
import net.minecraft.sounds.SoundSource;
@@ -43,6 +44,7 @@
4344
import net.minecraftforge.items.wrapper.SidedInvWrapper;
4445
import wayoftime.bloodmagic.api.compat.IDemonWillViewer;
4546
import wayoftime.bloodmagic.common.tile.TileInventory;
47+
import wayoftime.bloodmagic.util.helper.InventoryHelper;
4648
import wayoftime.bloodmagic.util.helper.NBTHelper;
4749

4850
public class Utils
@@ -571,55 +573,27 @@ public static ItemStack[] combineStacks(ItemStack stack1, ItemStack stack2)
571573

572574
public static boolean canPlayerSeeDemonWill(Player player)
573575
{
574-
IItemHandler inventory = new PlayerMainInvWrapper(player.getInventory());
575-
576-
for (int i = 0; i < inventory.getSlots(); i++)
576+
NonNullList<ItemStack> inventory = InventoryHelper.getActiveInventories(player);
577+
for (ItemStack stack : inventory)
577578
{
578-
ItemStack stack = inventory.getStackInSlot(i);
579-
if (stack.isEmpty())
580-
{
581-
continue;
582-
}
583-
584579
if (stack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) stack.getItem()).canSeeDemonWillAura(player.getCommandSenderWorld(), stack, player))
585580
{
586581
return true;
587582
}
588583
}
589-
590-
ItemStack offhandStack = player.getOffhandItem();
591-
if (!offhandStack.isEmpty() && offhandStack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) offhandStack.getItem()).canSeeDemonWillAura(player.getCommandSenderWorld(), offhandStack, player))
592-
{
593-
return true;
594-
}
595-
596584
return false;
597585
}
598586

599587
public static double getDemonWillResolution(Player player)
600588
{
601-
IItemHandler inventory = new PlayerMainInvWrapper(player.getInventory());
602-
603-
for (int i = 0; i < inventory.getSlots(); i++)
589+
NonNullList<ItemStack> inventory = InventoryHelper.getActiveInventories(player);
590+
for (ItemStack stack : inventory)
604591
{
605-
ItemStack stack = inventory.getStackInSlot(i);
606-
if (stack.isEmpty())
607-
{
608-
continue;
609-
}
610-
611592
if (stack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) stack.getItem()).canSeeDemonWillAura(player.getCommandSenderWorld(), stack, player))
612593
{
613594
return ((IDemonWillViewer) stack.getItem()).getDemonWillAuraResolution(player.getCommandSenderWorld(), stack, player);
614595
}
615596
}
616-
617-
ItemStack offhandStack = player.getOffhandItem();
618-
if (!offhandStack.isEmpty() && offhandStack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) offhandStack.getItem()).canSeeDemonWillAura(player.getCommandSenderWorld(), offhandStack, player))
619-
{
620-
return ((IDemonWillViewer) offhandStack.getItem()).getDemonWillAuraResolution(player.getCommandSenderWorld(), offhandStack, player);
621-
}
622-
623597
return 100;
624598
}
625599

src/main/java/wayoftime/bloodmagic/util/helper/InventoryHelper.java

+35-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package wayoftime.bloodmagic.util.helper;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
35
import java.util.Map;
46
import java.util.function.Function;
57

@@ -11,6 +13,21 @@
1113

1214
public class InventoryHelper
1315
{
16+
private static Map<String, Function<Player, NonNullList<ItemStack>>> inventoryProvider = BloodMagicAPI.INSTANCE.getInventoryProvider();
17+
18+
/**
19+
* Gets all items from the specified inventory.
20+
*
21+
* @param player - The player who's inventories to check.
22+
* @param inventoryKey - inventory's name. See BloodMagicCorePlugin for the vanilla ones.
23+
* @return - NonNullList<ItemStack> of all items in those inventories.
24+
*/
25+
public static NonNullList<ItemStack> getInventory(Player player, String inventoryKey)
26+
{
27+
NonNullList<ItemStack> inventory = NonNullList.create();
28+
inventory.addAll(inventoryProvider.get(inventoryKey).apply(player));
29+
return inventory;
30+
}
1431

1532
/**
1633
* Gets all items from all registered inventories.
@@ -20,14 +37,29 @@ public class InventoryHelper
2037
*/
2138
public static NonNullList<ItemStack> getAllInventories(Player player)
2239
{
23-
Map<String, Function<Player, NonNullList<ItemStack>>> inventoryProvider = BloodMagicAPI.INSTANCE.getInventoryProvider();
2440
NonNullList<ItemStack> inventory = NonNullList.create();
2541

2642
inventoryProvider.forEach((identifier, provider) -> inventory.addAll(provider.apply(player)));
2743

2844
return inventory;
2945
}
3046

47+
/**
48+
* Gets all items from all inventories, excluding the listed inventories
49+
*
50+
* @param player - The player who's inventories to check.
51+
* @param excludedInventoryKeys - inventory keys to exclude. See BloodMagicCorePlugin for the vanilla ones.
52+
* @return - NonNullList<ItemStack> of all items in those inventories.
53+
*/
54+
public static NonNullList<ItemStack> getAllInventoriesExcluding(Player player, List<String> excludedInventoryKeys)
55+
{
56+
NonNullList<ItemStack> inventory = NonNullList.create();
57+
58+
inventoryProvider.forEach((identifier, provider) -> {if (!identifier.equals(excludedInventoryKeys)) {inventory.addAll(provider.apply(player));}});
59+
60+
return inventory;
61+
}
62+
3163
/**
3264
* Gets all items from all registered inventories marked as active as well as
3365
* main and off hand
@@ -37,10 +69,10 @@ public static NonNullList<ItemStack> getAllInventories(Player player)
3769
*/
3870
public static NonNullList<ItemStack> getActiveInventories(Player player)
3971
{
40-
Map<String, Function<Player, NonNullList<ItemStack>>> inventoryProviders = BloodMagicAPI.INSTANCE.getActiveInventoryProvider();
72+
Map<String, Function<Player, NonNullList<ItemStack>>> activeInventoryProvider = BloodMagicAPI.INSTANCE.getActiveInventoryProvider();
4173
NonNullList<ItemStack> inventories = NonNullList.create();
4274

43-
inventoryProviders.forEach((identifier, provider) -> inventories.addAll(provider.apply(player)));
75+
activeInventoryProvider.forEach((identifier, provider) -> inventories.addAll(provider.apply(player)));
4476

4577
inventories.add(player.getItemInHand(InteractionHand.MAIN_HAND));
4678
inventories.add(player.getItemInHand(InteractionHand.OFF_HAND));

src/main/resources/assets/bloodmagic/patchouli_books/guide/en_us/entries/alchemy_array/living_equipment/training_bracelet.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"type": "bloodmagic:crafting_array",
1212
"heading": "Training Bracelet",
1313
"recipe": "bloodmagic:array/living_trainer",
14-
"text": "$(italic)*Insert Rocky Training Montage here*$()"
14+
"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."
1515
},
1616
{
1717
"type": "patchouli:image",

src/main/resources/data/bloodmagic/curios/entities/bmplayerslots.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"slots": [
44
"charm",
55
"necklace",
6+
"bracelet",
67
"living_armour_socket"
78
]
89
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"replace": false,
3+
"values": [
4+
"bloodmagic:upgradetrainer"
5+
]
6+
}

src/main/resources/data/curios/tags/items/charm.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"bloodmagic:sigilofholding",
99
"bloodmagic:divinationsigil",
1010
"bloodmagic:seersigil",
11-
"bloodmagic:experiencebook"
11+
"bloodmagic:sigilofsuppression",
12+
"bloodmagic:experiencebook",
13+
"bloodmagic:demonwillgauge"
1214
]
1315
}

src/main/resources/data/curios/tags/items/living_armour_socket.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
"bloodmagic:sigilofholding",
99
"bloodmagic:divinationsigil",
1010
"bloodmagic:seersigil",
11+
"bloodmagic:sigilofsuppression",
1112
"bloodmagic:experiencebook",
1213
"bloodmagic:soulgempetty",
1314
"bloodmagic:soulgemlesser",
1415
"bloodmagic:soulgemcommon",
15-
"bloodmagic:soulgemgreater"
16+
"bloodmagic:soulgemgreater",
17+
"bloodmagic:upgradetrainer",
18+
"bloodmagic:demonwillgauge"
1619
]
1720
}

0 commit comments

Comments
 (0)