Another debug cube feature
This commit is contained in:
parent
cf1d65cae0
commit
5193a20a0a
7 changed files with 88 additions and 36 deletions
|
@ -10,6 +10,7 @@ import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ public class DiscoveryHandlers {
|
||||||
private static final List<ToFloatFunction<Player>> GRID_SCALE_MODIFIERS = new ArrayList<>();
|
private static final List<ToFloatFunction<Player>> GRID_SCALE_MODIFIERS = new ArrayList<>();
|
||||||
private static final List<Function<CastingContext, List<ItemStack>>> ITEM_SLOT_DISCOVERER = new ArrayList<>();
|
private static final List<Function<CastingContext, List<ItemStack>>> ITEM_SLOT_DISCOVERER = new ArrayList<>();
|
||||||
private static final List<Function<CastingContext, List<ItemStack>>> OPERATIVE_SLOT_DISCOVERER = new ArrayList<>();
|
private static final List<Function<CastingContext, List<ItemStack>>> OPERATIVE_SLOT_DISCOVERER = new ArrayList<>();
|
||||||
|
private static final List<BiFunction<Player, String, ItemStack>> DEBUG_DISCOVERER = new ArrayList<>();
|
||||||
|
|
||||||
public static boolean hasLens(Player player) {
|
public static boolean hasLens(Player player) {
|
||||||
for (var predicate : HAS_LENS_PREDICATE) {
|
for (var predicate : HAS_LENS_PREDICATE) {
|
||||||
|
@ -61,6 +63,16 @@ public class DiscoveryHandlers {
|
||||||
return stacks;
|
return stacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ItemStack findDebugItem(Player player, String type) {
|
||||||
|
for (var discoverer : DEBUG_DISCOVERER) {
|
||||||
|
var stack = discoverer.apply(player, type);
|
||||||
|
if (!stack.isEmpty()) {
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
public static void addLensPredicate(Predicate<Player> predicate) {
|
public static void addLensPredicate(Predicate<Player> predicate) {
|
||||||
HAS_LENS_PREDICATE.add(predicate);
|
HAS_LENS_PREDICATE.add(predicate);
|
||||||
}
|
}
|
||||||
|
@ -80,4 +92,8 @@ public class DiscoveryHandlers {
|
||||||
public static void addOperativeSlotDiscoverer(Function<CastingContext, List<ItemStack>> discoverer) {
|
public static void addOperativeSlotDiscoverer(Function<CastingContext, List<ItemStack>> discoverer) {
|
||||||
OPERATIVE_SLOT_DISCOVERER.add(discoverer);
|
OPERATIVE_SLOT_DISCOVERER.add(discoverer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addDebugItemDiscoverer(BiFunction<Player, String, ItemStack> discoverer) {
|
||||||
|
DEBUG_DISCOVERER.add(discoverer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import at.petrak.hexcasting.api.spell.mishaps.MishapEntityTooFarAway
|
||||||
import at.petrak.hexcasting.api.spell.mishaps.MishapEvalTooDeep
|
import at.petrak.hexcasting.api.spell.mishaps.MishapEvalTooDeep
|
||||||
import at.petrak.hexcasting.api.spell.mishaps.MishapLocationTooFarAway
|
import at.petrak.hexcasting.api.spell.mishaps.MishapLocationTooFarAway
|
||||||
import at.petrak.hexcasting.api.utils.otherHand
|
import at.petrak.hexcasting.api.utils.otherHand
|
||||||
|
import at.petrak.hexcasting.common.items.magic.ItemCreativeUnlocker
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
|
@ -200,6 +201,10 @@ data class CastingContext(
|
||||||
return advs.getOrStartProgress(adv!!).isDone
|
return advs.getOrStartProgress(adv!!).isDone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val debugPatterns: Boolean by lazy {
|
||||||
|
!DiscoveryHandlers.findDebugItem(this.caster, ItemCreativeUnlocker.DISPLAY_PATTERNS).isEmpty
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
init {
|
init {
|
||||||
DiscoveryHandlers.addItemSlotDiscoverer {
|
DiscoveryHandlers.addItemSlotDiscoverer {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import at.petrak.hexcasting.api.spell.math.HexPattern
|
||||||
import at.petrak.hexcasting.api.spell.mishaps.*
|
import at.petrak.hexcasting.api.spell.mishaps.*
|
||||||
import at.petrak.hexcasting.api.utils.*
|
import at.petrak.hexcasting.api.utils.*
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||||
|
import net.minecraft.Util
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.nbt.Tag
|
import net.minecraft.nbt.Tag
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
@ -47,6 +48,12 @@ class CastingHarness private constructor(
|
||||||
*/
|
*/
|
||||||
fun executeIota(iota: SpellDatum<*>, world: ServerLevel): ControllerInfo = executeIotas(listOf(iota), world)
|
fun executeIota(iota: SpellDatum<*>, world: ServerLevel): ControllerInfo = executeIotas(listOf(iota), world)
|
||||||
|
|
||||||
|
private fun displayPattern(pattern: Operator?, iota: SpellDatum<*>) {
|
||||||
|
if (this.ctx.debugPatterns) {
|
||||||
|
this.ctx.caster.sendMessage(pattern?.displayName ?: iota.display(), Util.NIL_UUID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getOperatorForPattern(iota: SpellDatum<*>, world: ServerLevel): Operator? {
|
private fun getOperatorForPattern(iota: SpellDatum<*>, world: ServerLevel): Operator? {
|
||||||
if (iota.getType() == DatumType.PATTERN)
|
if (iota.getType() == DatumType.PATTERN)
|
||||||
return PatternRegistry.matchPattern(iota.payload as HexPattern, world)
|
return PatternRegistry.matchPattern(iota.payload as HexPattern, world)
|
||||||
|
@ -192,6 +199,7 @@ class CastingHarness private constructor(
|
||||||
var cont2 = continuation
|
var cont2 = continuation
|
||||||
|
|
||||||
if (!unenlightened || pattern.alwaysProcessGreatSpell) {
|
if (!unenlightened || pattern.alwaysProcessGreatSpell) {
|
||||||
|
displayPattern(pattern, SpellDatum.make(newPat))
|
||||||
val result = pattern.operate(
|
val result = pattern.operate(
|
||||||
continuation,
|
continuation,
|
||||||
this.stack.toMutableList(),
|
this.stack.toMutableList(),
|
||||||
|
@ -311,7 +319,7 @@ class CastingHarness private constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (this.parenCount > 0) {
|
val out = if (this.parenCount > 0) {
|
||||||
if (this.escapeNext) {
|
if (this.escapeNext) {
|
||||||
val newParens = this.parenthesized.toMutableList()
|
val newParens = this.parenthesized.toMutableList()
|
||||||
newParens.add(iota)
|
newParens.add(iota)
|
||||||
|
@ -380,6 +388,11 @@ class CastingHarness private constructor(
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (out != null) {
|
||||||
|
displayPattern(operator, iota)
|
||||||
|
}
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,40 +36,58 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
|
|
||||||
public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
|
public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
|
||||||
|
|
||||||
static {
|
public static final String DISPLAY_MEDIA = "media";
|
||||||
DiscoveryHandlers.addManaHolderDiscoverer(harness -> {
|
public static final String DISPLAY_PATTERNS = "patterns";
|
||||||
var player = harness.getCtx().getCaster();
|
|
||||||
if (!player.isCreative())
|
|
||||||
return List.of();
|
|
||||||
|
|
||||||
|
static {
|
||||||
|
DiscoveryHandlers.addDebugItemDiscoverer((player, type) -> {
|
||||||
for (ItemStack item : player.getInventory().items) {
|
for (ItemStack item : player.getInventory().items) {
|
||||||
if (isDebug(item)) {
|
if (isDebug(item, type)) {
|
||||||
return List.of(new DebugUnlockerHolder(item));
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Technically possible with commands!
|
// Technically possible with commands!
|
||||||
for (ItemStack item : player.getInventory().armor) {
|
for (ItemStack item : player.getInventory().armor) {
|
||||||
if (isDebug(item)) {
|
if (isDebug(item, type)) {
|
||||||
return List.of(new DebugUnlockerHolder(item));
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ItemStack item : player.getInventory().offhand) {
|
for (ItemStack item : player.getInventory().offhand) {
|
||||||
if (isDebug(item)) {
|
if (isDebug(item, type)) {
|
||||||
return List.of(new DebugUnlockerHolder(item));
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
});
|
||||||
|
|
||||||
|
DiscoveryHandlers.addManaHolderDiscoverer(harness -> {
|
||||||
|
var player = harness.getCtx().getCaster();
|
||||||
|
if (!player.isCreative())
|
||||||
|
return List.of();
|
||||||
|
|
||||||
|
ItemStack stack = DiscoveryHandlers.findDebugItem(player, DISPLAY_MEDIA);
|
||||||
|
if (!stack.isEmpty())
|
||||||
|
return List.of(new DebugUnlockerHolder(stack));
|
||||||
|
|
||||||
return List.of();
|
return List.of();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDebug(ItemStack stack) {
|
public static boolean isDebug(ItemStack stack) {
|
||||||
return stack.is(HexItems.CREATIVE_UNLOCKER)
|
return isDebug(stack, null);
|
||||||
&& stack.hasCustomHoverName()
|
}
|
||||||
&& stack.getHoverName().getString().toLowerCase(Locale.ROOT).contains("debug");
|
|
||||||
|
public static boolean isDebug(ItemStack stack, String flag) {
|
||||||
|
if (!stack.is(HexItems.CREATIVE_UNLOCKER) || !stack.hasCustomHoverName()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var keywords = Arrays.asList(stack.getHoverName().getString().toLowerCase(Locale.ROOT).split(" "));
|
||||||
|
if (!keywords.contains("debug")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return flag == null || keywords.contains(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component infiniteMedia(Level level) {
|
public static Component infiniteMedia(Level level) {
|
||||||
|
@ -129,7 +147,7 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
|
||||||
@Override
|
@Override
|
||||||
public int withdrawMana(ItemStack stack, int cost, boolean simulate) {
|
public int withdrawMana(ItemStack stack, int cost, boolean simulate) {
|
||||||
// In case it's withdrawn through other means
|
// In case it's withdrawn through other means
|
||||||
if (!simulate && isDebug(stack)) {
|
if (!simulate && isDebug(stack, DISPLAY_MEDIA)) {
|
||||||
addToIntArray(stack, TAG_EXTRACTIONS, cost);
|
addToIntArray(stack, TAG_EXTRACTIONS, cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +157,7 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
|
||||||
@Override
|
@Override
|
||||||
public int insertMana(ItemStack stack, int amount, boolean simulate) {
|
public int insertMana(ItemStack stack, int amount, boolean simulate) {
|
||||||
// In case it's inserted through other means
|
// In case it's inserted through other means
|
||||||
if (!simulate && isDebug(stack)) {
|
if (!simulate && isDebug(stack, DISPLAY_MEDIA)) {
|
||||||
addToIntArray(stack, TAG_INSERTIONS, amount);
|
addToIntArray(stack, TAG_INSERTIONS, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +171,7 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) {
|
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) {
|
||||||
if (isDebug(stack) && !level.isClientSide) {
|
if (isDebug(stack, DISPLAY_MEDIA) && !level.isClientSide) {
|
||||||
debugDisplay(stack, TAG_EXTRACTIONS, "withdrawn", "all_mana", entity);
|
debugDisplay(stack, TAG_EXTRACTIONS, "withdrawn", "all_mana", entity);
|
||||||
debugDisplay(stack, TAG_INSERTIONS, "inserted", "infinite_mana", entity);
|
debugDisplay(stack, TAG_INSERTIONS, "inserted", "infinite_mana", entity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,10 +182,10 @@
|
||||||
"command.hexcasting.brainsweep.fail.badtype": "%s is not a villager",
|
"command.hexcasting.brainsweep.fail.badtype": "%s is not a villager",
|
||||||
"command.hexcasting.brainsweep.fail.already": "%s is already empty",
|
"command.hexcasting.brainsweep.fail.already": "%s is already empty",
|
||||||
"hexcasting.pattern.unknown": "Unknown pattern resource location %s",
|
"hexcasting.pattern.unknown": "Unknown pattern resource location %s",
|
||||||
"hexcasting.debug.mana_withdrawn": "%s - Mana withdrawn: %s",
|
"hexcasting.debug.mana_withdrawn": "%s - Media withdrawn: %s",
|
||||||
"hexcasting.debug.mana_withdrawn.with_dust": "%s - Mana withdrawn: %s (%s in dust)",
|
"hexcasting.debug.mana_withdrawn.with_dust": "%s - Media withdrawn: %s (%s in dust)",
|
||||||
"hexcasting.debug.mana_inserted": "%s - Mana inserted: %s",
|
"hexcasting.debug.mana_inserted": "%s - Media inserted: %s",
|
||||||
"hexcasting.debug.mana_inserted.with_dust": "%s - Mana inserted: %s (%s in dust)",
|
"hexcasting.debug.mana_inserted.with_dust": "%s - Media inserted: %s (%s in dust)",
|
||||||
"hexcasting.debug.all_mana": "Entire contents",
|
"hexcasting.debug.all_mana": "Entire contents",
|
||||||
"hexcasting.debug.infinite_mana": "Infinite",
|
"hexcasting.debug.infinite_mana": "Infinite",
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package at.petrak.hexcasting.fabric.interop.trinkets;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.misc.DiscoveryHandlers;
|
import at.petrak.hexcasting.api.misc.DiscoveryHandlers;
|
||||||
import at.petrak.hexcasting.api.utils.ManaHelper;
|
import at.petrak.hexcasting.api.utils.ManaHelper;
|
||||||
import at.petrak.hexcasting.common.items.magic.DebugUnlockerHolder;
|
|
||||||
import at.petrak.hexcasting.common.items.magic.ItemCreativeUnlocker;
|
import at.petrak.hexcasting.common.items.magic.ItemCreativeUnlocker;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||||
|
@ -12,6 +11,7 @@ import dev.emi.trinkets.api.client.TrinketRendererRegistry;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.util.Tuple;
|
import net.minecraft.util.Tuple;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -41,16 +41,16 @@ public class TrinketsApiInterop {
|
||||||
return List.of();
|
return List.of();
|
||||||
});
|
});
|
||||||
|
|
||||||
DiscoveryHandlers.addManaHolderDiscoverer(harness -> {
|
DiscoveryHandlers.addDebugItemDiscoverer((player, type) -> {
|
||||||
Optional<TrinketComponent> optional = TrinketsApi.getTrinketComponent(harness.getCtx().getCaster());
|
Optional<TrinketComponent> optional = TrinketsApi.getTrinketComponent(player);
|
||||||
if (optional.isPresent()) {
|
if (optional.isPresent()) {
|
||||||
TrinketComponent component = optional.get();
|
TrinketComponent component = optional.get();
|
||||||
var equipped = component.getEquipped(ItemCreativeUnlocker::isDebug);
|
var equipped = component.getEquipped(stack -> ItemCreativeUnlocker.isDebug(stack, type));
|
||||||
if (!equipped.isEmpty()) {
|
if (!equipped.isEmpty()) {
|
||||||
return List.of(new DebugUnlockerHolder(equipped.get(0).getB()));
|
return equipped.get(0).getB();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return List.of();
|
return ItemStack.EMPTY;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@ package at.petrak.hexcasting.forge.interop.curios;
|
||||||
import at.petrak.hexcasting.api.addldata.ManaHolder;
|
import at.petrak.hexcasting.api.addldata.ManaHolder;
|
||||||
import at.petrak.hexcasting.api.misc.DiscoveryHandlers;
|
import at.petrak.hexcasting.api.misc.DiscoveryHandlers;
|
||||||
import at.petrak.hexcasting.api.utils.ManaHelper;
|
import at.petrak.hexcasting.api.utils.ManaHelper;
|
||||||
import at.petrak.hexcasting.common.items.magic.DebugUnlockerHolder;
|
|
||||||
import at.petrak.hexcasting.common.items.magic.ItemCreativeUnlocker;
|
import at.petrak.hexcasting.common.items.magic.ItemCreativeUnlocker;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
import at.petrak.hexcasting.interop.HexInterop;
|
import at.petrak.hexcasting.interop.HexInterop;
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.fml.InterModComms;
|
import net.minecraftforge.fml.InterModComms;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
|
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
|
||||||
|
@ -19,6 +19,7 @@ import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public class CuriosApiInterop {
|
public class CuriosApiInterop {
|
||||||
|
|
||||||
|
@ -61,22 +62,21 @@ public class CuriosApiInterop {
|
||||||
return holders;
|
return holders;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
DiscoveryHandlers.addDebugItemDiscoverer((player, type) -> {
|
||||||
DiscoveryHandlers.addManaHolderDiscoverer(harness -> {
|
AtomicReference<ItemStack> result = new AtomicReference<>(ItemStack.EMPTY);
|
||||||
List<ManaHolder> holders = Lists.newArrayList();
|
player.getCapability(CuriosCapability.INVENTORY).ifPresent(handler -> {
|
||||||
harness.getCtx().getCaster().getCapability(CuriosCapability.INVENTORY).ifPresent(handler -> {
|
|
||||||
for (var stacksHandler : handler.getCurios().values()) {
|
for (var stacksHandler : handler.getCurios().values()) {
|
||||||
var stacks = stacksHandler.getStacks();
|
var stacks = stacksHandler.getStacks();
|
||||||
for (int i = 0; i < stacks.getSlots(); i++) {
|
for (int i = 0; i < stacks.getSlots(); i++) {
|
||||||
var stack = stacks.getStackInSlot(i);
|
var stack = stacks.getStackInSlot(i);
|
||||||
if (ItemCreativeUnlocker.isDebug(stack)) {
|
if (ItemCreativeUnlocker.isDebug(stack, type)) {
|
||||||
holders.add(new DebugUnlockerHolder(stack));
|
result.set(stack);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return holders;
|
return result.get();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue