Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;

public class DiscoveryHandlers {
private static final List<BiFunction<Player, String, ItemStack>> DEBUG_DISCOVERER = new ArrayList<>();
private static final List<Function<Player, List<ItemStack>>> EXTRA_EQUIPMENT_DISCOVERY = new ArrayList<>();

public static ItemStack findDebugItem(Player player, String type) {
for (var discoverer : DEBUG_DISCOVERER) {
Expand All @@ -20,7 +22,19 @@ public static ItemStack findDebugItem(Player player, String type) {
return ItemStack.EMPTY;
}

public static List<ItemStack> collectExtraEquipments(Player player) {
List<ItemStack> stacks = new ArrayList<>();
for (var discoverer : EXTRA_EQUIPMENT_DISCOVERY) {
stacks.addAll(discoverer.apply(player));
}
return stacks;
}

public static void addDebugItemDiscoverer(BiFunction<Player, String, ItemStack> discoverer) {
DEBUG_DISCOVERER.add(discoverer);
}

public static void addExtraEquipmentDiscoverer(Function<Player, List<ItemStack>> discoverer) {
EXTRA_EQUIPMENT_DISCOVERY.add(discoverer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package at.petrak.hexcasting.api.utils

import at.petrak.hexcasting.api.HexAPI
import at.petrak.hexcasting.api.addldata.ADMediaHolder
import at.petrak.hexcasting.api.misc.DiscoveryHandlers
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.server.level.ServerPlayer
import net.minecraft.util.Mth
Expand Down Expand Up @@ -64,7 +65,7 @@ fun extractMedia(
fun scanPlayerForMediaStuff(player: ServerPlayer): List<ADMediaHolder> {
val sources = mutableListOf<ADMediaHolder>()

(player.inventory.items + player.inventory.armor + player.inventory.offhand).forEach {
(player.inventory.items + player.inventory.armor + player.inventory.offhand + DiscoveryHandlers.collectExtraEquipments(player)).forEach {
val holder = HexAPI.instance().findMediaHolder(it)
if (holder?.canProvide() == true) {
sources.add(holder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.util.Tuple;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.item.ItemStack;

import java.util.Optional;
import java.util.UUID;
import java.util.*;

public class TrinketsApiInterop {
public static void init() {
Expand All @@ -37,6 +37,16 @@ public Multimap<Attribute, AttributeModifier> getModifiers(ItemStack stack, Slot
}
});

DiscoveryHandlers.addExtraEquipmentDiscoverer(player -> {
Optional<TrinketComponent> optional = TrinketsApi.getTrinketComponent(player);
if (optional.isPresent()) {
TrinketComponent component = optional.get();
return component.getEquipped(i -> !i.isEmpty()).stream()
.map(Tuple::getB)
.toList();
}
return List.of();
});

DiscoveryHandlers.addDebugItemDiscoverer((player, type) -> {
Optional<TrinketComponent> optional = TrinketsApi.getTrinketComponent(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import top.theillusivec4.curios.api.SlotTypePreset;
import top.theillusivec4.curios.api.type.capability.ICurio;

import java.util.UUID;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

public class CuriosApiInterop {
Expand Down Expand Up @@ -55,6 +55,21 @@ public static ICapabilityProvider curioCap(ItemStack stack) {


public static void init() {
DiscoveryHandlers.addExtraEquipmentDiscoverer(player -> {
List<ItemStack> result = new ArrayList<>();
player.getCapability(CuriosCapability.INVENTORY).ifPresent(handler -> {
for (var stacksHandler : handler.getCurios().values()) {
var stacks = stacksHandler.getStacks();
for (int i = 0; i < stacks.getSlots(); i++) {
var stack = stacks.getStackInSlot(i);
if (stack.isEmpty()) continue;
result.add(stack);
}
}
});
return result;
});

DiscoveryHandlers.addDebugItemDiscoverer((player, type) -> {
AtomicReference<ItemStack> result = new AtomicReference<>(ItemStack.EMPTY);
player.getCapability(CuriosCapability.INVENTORY).ifPresent(handler -> {
Expand Down
Loading