Skip to content

Commit

Permalink
restore curio compat
Browse files Browse the repository at this point in the history
Fixes #606
  • Loading branch information
Caltinor committed Nov 29, 2024
1 parent 9cffbbb commit 7eff02e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/harmonised/pmmo/compat/curios/CuriosCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package harmonised.pmmo.compat.curios;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import top.theillusivec4.curios.api.CuriosApi;

import java.util.ArrayList;
import java.util.List;

public class CuriosCompat {
public static boolean hasCurio = false;
//provide curio data to various methods
public static List<ItemStack> getItems(Player player) {
List<ItemStack> curioItems = new ArrayList<>();
CuriosApi.getCuriosHelper().getEquippedCurios(player).ifPresent((handler) -> {
for (int i = 0; i < handler.getSlots(); i++) {
curioItems.add(handler.getStackInSlot(i));
}
});
return curioItems;
}
}
3 changes: 3 additions & 0 deletions src/main/java/harmonised/pmmo/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import harmonised.pmmo.api.enums.ObjectType;
import harmonised.pmmo.api.enums.ReqType;
import harmonised.pmmo.client.utils.DataMirror;
import harmonised.pmmo.compat.curios.CuriosCompat;
import harmonised.pmmo.config.Config;
import harmonised.pmmo.config.codecs.CodecTypes.SalvageData;
import harmonised.pmmo.config.codecs.DataSource;
Expand Down Expand Up @@ -270,6 +271,8 @@ public Map<String, Double> getConsolidatedModifierMap(Player player) {
//WORN Modification
List<ItemStack> wornItems = new ArrayList<>();
player.getArmorSlots().forEach(wornItems::add);
if (CuriosCompat.hasCurio)
wornItems.addAll(CuriosCompat.getItems(player));
wornItems.forEach((stack) -> {
ResourceLocation itemID = RegistryUtil.getId(player.level().registryAccess(), stack);
Map<String, Double> modifers = tooltips.bonusTooltipExists(itemID, ModifierDataType.WORN) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import harmonised.pmmo.api.enums.ObjectType;
import harmonised.pmmo.api.enums.ReqType;
import harmonised.pmmo.compat.curios.CuriosCompat;
import harmonised.pmmo.core.Core;
import harmonised.pmmo.core.CoreUtils;
import harmonised.pmmo.util.RegistryUtil;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;

import java.util.ArrayList;
import java.util.List;

public class EffectManager {
Expand All @@ -36,6 +38,11 @@ public static void applyEffects(Core core, Player player) {
Inventory inv = player.getInventory();

List<ItemStack> items = List.of(inv.getItem(36), inv.getItem(37), inv.getItem(38), inv.getItem(39), player.getMainHandItem(), player.getOffhandItem());
//========== CURIOS ==============
if (CuriosCompat.hasCurio) {
items = new ArrayList<>(items);
items.addAll(CuriosCompat.getItems(player));
}
//================================
for (ItemStack stack : items) {
if (!stack.isEmpty() && !core.isActionPermitted(ReqType.WEAR, stack, player)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package harmonised.pmmo.features.veinmining;

import harmonised.pmmo.api.enums.ReqType;
import harmonised.pmmo.compat.curios.CuriosCompat;
import harmonised.pmmo.config.Config;
import harmonised.pmmo.config.codecs.VeinData;
import harmonised.pmmo.core.Core;
Expand All @@ -17,6 +18,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -62,6 +64,11 @@ public static void regenerateVein(ServerPlayer player) {
inv.getItem(39),
player.getMainHandItem(),
player.getOffhandItem());
//========== CURIOS ==============
if (CuriosCompat.hasCurio) {
items = new ArrayList<>(items);
items.addAll(CuriosCompat.getItems(player));
}
//================================
Core core = Core.get(player.level());
double currentCharge = veinAmount(player);
Expand Down Expand Up @@ -98,6 +105,11 @@ public static int getMaxChargeFromAllItems(Player player) {
inv.getItem(39),
player.getMainHandItem(),
player.getOffhandItem());
//========== CURIOS ==============
if (CuriosCompat.hasCurio) {
items = new ArrayList<>(items);
items.addAll(CuriosCompat.getItems(player));
}
//================================
int totalCapacity = getCap(player) + items.stream()
.filter(stack -> Core.get(player.level()).isActionPermitted(ReqType.WEAR, stack, player))
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/harmonised/pmmo/setup/CommonSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.serialization.Codec;
import harmonised.pmmo.commands.CmdPmmoRoot;
import harmonised.pmmo.compat.curios.CuriosCompat;
import harmonised.pmmo.compat.ftb_quests.FTBQHandler;
import harmonised.pmmo.config.Config;
import harmonised.pmmo.config.readers.CoreLoader;
Expand Down Expand Up @@ -78,6 +79,7 @@ public class CommonSetup {
public static void init(final FMLCommonSetupEvent event) {
PerkRegistration.init();
//=========COMPAT=============
CuriosCompat.hasCurio = ModList.get().isLoaded("curios");
if (ModList.get().isLoaded("ftbquests")) FTBQHandler.init();
}

Expand Down

0 comments on commit 7eff02e

Please sign in to comment.