Skip to content

Commit

Permalink
Merge pull request #1986 from VT-14/More-Curios
Browse files Browse the repository at this point in the history
More Curios, Related InventoryHelper Updates, & Demon Will Aura Gauge Tweak
  • Loading branch information
WayofTime committed Jan 22, 2024
2 parents d629b00 + 2c4291d commit 70457ad
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 43 deletions.
38 changes: 33 additions & 5 deletions 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
{
Expand All @@ -22,13 +27,36 @@ public static ItemStack findItem(Player player, Predicate<ItemStack> requirement
ItemStack offHand = player.getOffhandItem();
if (requirements.test(offHand))
return offHand;
List<String> 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<ItemStack> curiosInventory = InventoryHelper.getInventory(player, "curiosInventory");
for (ItemStack item : curiosInventory)
{
if (requirements.test(item))
return item;
}
checkedInventories.add("curiosInventory");
}

// Check Main Inventory next.
NonNullList<ItemStack> 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<ItemStack> remainingInventories = InventoryHelper.getAllInventoriesExcluding(player, checkedInventories);
for (ItemStack item : remainingInventories)
{
if (requirements.test(item))
return item;
}

return ItemStack.EMPTY;
Expand Down
38 changes: 6 additions & 32 deletions src/main/java/wayoftime/bloodmagic/util/Utils.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<ItemStack> 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<ItemStack> 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;
}

Expand Down
@@ -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;

Expand All @@ -11,6 +13,21 @@

public class InventoryHelper
{
private static Map<String, Function<Player, NonNullList<ItemStack>>> 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<ItemStack> of all items in those inventories.
*/
public static NonNullList<ItemStack> getInventory(Player player, String inventoryKey)
{
NonNullList<ItemStack> inventory = NonNullList.create();
inventory.addAll(inventoryProvider.get(inventoryKey).apply(player));
return inventory;
}

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

inventoryProvider.forEach((identifier, provider) -> inventory.addAll(provider.apply(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<ItemStack> of all items in those inventories.
*/
public static NonNullList<ItemStack> getAllInventoriesExcluding(Player player, List<String> excludedInventoryKeys)
{
NonNullList<ItemStack> 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
Expand All @@ -37,10 +69,10 @@ public static NonNullList<ItemStack> getAllInventories(Player player)
*/
public static NonNullList<ItemStack> getActiveInventories(Player player)
{
Map<String, Function<Player, NonNullList<ItemStack>>> inventoryProviders = BloodMagicAPI.INSTANCE.getActiveInventoryProvider();
Map<String, Function<Player, NonNullList<ItemStack>>> activeInventoryProvider = BloodMagicAPI.INSTANCE.getActiveInventoryProvider();
NonNullList<ItemStack> 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));
Expand Down
Expand Up @@ -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",
Expand Down
Expand Up @@ -3,6 +3,7 @@
"slots": [
"charm",
"necklace",
"bracelet",
"living_armour_socket"
]
}
6 changes: 6 additions & 0 deletions src/main/resources/data/curios/tags/items/bracelet.json
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"bloodmagic:upgradetrainer"
]
}
4 changes: 3 additions & 1 deletion src/main/resources/data/curios/tags/items/charm.json
Expand Up @@ -8,6 +8,8 @@
"bloodmagic:sigilofholding",
"bloodmagic:divinationsigil",
"bloodmagic:seersigil",
"bloodmagic:experiencebook"
"bloodmagic:sigilofsuppression",
"bloodmagic:experiencebook",
"bloodmagic:demonwillgauge"
]
}
Expand Up @@ -8,10 +8,13 @@
"bloodmagic:sigilofholding",
"bloodmagic:divinationsigil",
"bloodmagic:seersigil",
"bloodmagic:sigilofsuppression",
"bloodmagic:experiencebook",
"bloodmagic:soulgempetty",
"bloodmagic:soulgemlesser",
"bloodmagic:soulgemcommon",
"bloodmagic:soulgemgreater"
"bloodmagic:soulgemgreater",
"bloodmagic:upgradetrainer",
"bloodmagic:demonwillgauge"
]
}

0 comments on commit 70457ad

Please sign in to comment.