blood magic mod, living armor and curios incompatibility fix
martinez1267 opened this issue · 3 comments
Hey I think I fixed the issue with the living armor and the curios mod for 1.20.1. I really wanted to play the mod with my brother and it was annoying me that the bug would absolutely crash and brick the game with no hope of saving. I hope this fixes it. let me know if it doesnt. make it easy on me and upload it to curse forge so that I can get to playing.
`package wayoftime.bloodmagic.compat;
import net.minecraft.core.NonNullList;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
import top.theillusivec4.curios.api.CuriosApi;
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
import wayoftime.bloodmagic.core.LivingArmorRegistrar;
import wayoftime.bloodmagic.core.living.LivingStats;
import wayoftime.bloodmagic.core.living.LivingUtil;
import wayoftime.bloodmagic.impl.BloodMagicAPI;
import java.util.Map;
public class CuriosCompat
{
public void registerInventory()
{
BloodMagicAPI.INSTANCE.registerInventoryProvider("curiosInventory", player -> getCuriosInventory(player));
BloodMagicAPI.INSTANCE.registerActiveInventoryProvider("curiosInventory");
}
public NonNullList<ItemStack> getCuriosInventory(Player player)
{
var curiosOpt = CuriosApi.getCuriosInventory(player).resolve();
if (curiosOpt.isEmpty()) return NonNullList.create(); // ← SAFE RETURN if Curios data is missing
IItemHandlerModifiable itemHandler = curiosOpt.get().getEquippedCurios();
NonNullList<ItemStack> inventory = NonNullList.create();
for (int i = 0; i < itemHandler.getSlots(); i++)
{
inventory.add(itemHandler.getStackInSlot(i));
}
return inventory;
}
public int recalculateCuriosSlots(Player player)
{
//ICurioStacksHandler livingArmourSockets = CuriosApi.getCuriosInventory(player).resolve().get().getCurios().get("living_armour_socket");
var curiosOpt = CuriosApi.getCuriosInventory(player).resolve();
if (curiosOpt.isEmpty()) return 0;
var curios = curiosOpt.get().getCurios();
if(!curios.containsKey("living_armour_socket")) return 0;
ICurioStacksHandler livingArmourSockets = curios.get("living_armour_socket");
if (LivingUtil.hasFullSet(player))
{
LivingStats stats = LivingStats.fromPlayer(player);
int curiosLevel = (stats != null) ? stats.getLevel(LivingArmorRegistrar.UPGRADE_CURIOS_SOCKET.get().getKey()) : 0;
livingArmourSockets.removeModifier(player.getUUID());
if (curiosLevel != 0)
{
livingArmourSockets.addTransientModifier(new AttributeModifier(player.getUUID(), "legacy", Double.valueOf(LivingArmorRegistrar.UPGRADE_CURIOS_SOCKET.get().getBonusValue("slots", curiosLevel).intValue()), AttributeModifier.Operation.ADDITION));
}
return curiosLevel;
} else
{
livingArmourSockets.removeModifier(player.getUUID());
return 0;
}
}
}`
Should be solved by PR #2045 - if you encounter this issue again after the next BM release, please reopen this issue
so essentially pr #2045
No need to thank me # @stellanera98