diff --git a/Common/src/main/java/at/petrak/hexcasting/api/misc/DiscoveryHandlers.java b/Common/src/main/java/at/petrak/hexcasting/api/misc/DiscoveryHandlers.java index e9f04fb6..e9f3a98d 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/misc/DiscoveryHandlers.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/misc/DiscoveryHandlers.java @@ -1,9 +1,12 @@ package at.petrak.hexcasting.api.misc; import at.petrak.hexcasting.api.addldata.ManaHolder; +import at.petrak.hexcasting.api.spell.casting.CastingContext; import at.petrak.hexcasting.api.spell.casting.CastingHarness; import com.google.common.collect.Lists; +import net.minecraft.util.ToFloatFunction; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import java.util.ArrayList; import java.util.List; @@ -13,6 +16,8 @@ import java.util.function.Predicate; public class DiscoveryHandlers { private static final List> HAS_LENS_PREDICATE = new ArrayList<>(); private static final List>> MANA_HOLDER_DISCOVERY = new ArrayList<>(); + private static final List> GRID_SCALE_MODIFIERS = new ArrayList<>(); + private static final List>> ITEM_SLOT_DISCOVERER = new ArrayList<>(); public static boolean hasLens(Player player) { for (var predicate : HAS_LENS_PREDICATE) { @@ -31,6 +36,21 @@ public class DiscoveryHandlers { return holders; } + public static float gridScaleModifier(Player player) { + float mod = 1; + for (var modifier : GRID_SCALE_MODIFIERS) { + mod *= modifier.apply(player); + } + return mod; + } + + public static List collectItemSlots(CastingContext ctx) { + List stacks = Lists.newArrayList(); + for (var discoverer : ITEM_SLOT_DISCOVERER) { + stacks.addAll(discoverer.apply(ctx)); + } + return stacks; + } public static void addLensPredicate(Predicate predicate) { HAS_LENS_PREDICATE.add(predicate); @@ -39,4 +59,12 @@ public class DiscoveryHandlers { public static void addManaHolderDiscoverer(Function> discoverer) { MANA_HOLDER_DISCOVERY.add(discoverer); } + + public static void addGridScaleModifier(ToFloatFunction modifier) { + GRID_SCALE_MODIFIERS.add(modifier); + } + + public static void addItemSlotDiscoverer(Function> discoverer) { + ITEM_SLOT_DISCOVERER.add(discoverer); + } } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingContext.kt b/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingContext.kt index 53540a8d..dbf8c267 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingContext.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingContext.kt @@ -1,6 +1,7 @@ package at.petrak.hexcasting.api.spell.casting import at.petrak.hexcasting.api.HexAPI.modLoc +import at.petrak.hexcasting.api.misc.DiscoveryHandlers import at.petrak.hexcasting.api.mod.HexConfig import at.petrak.hexcasting.api.spell.Operator import at.petrak.hexcasting.api.spell.mishaps.MishapEntityTooFarAway @@ -133,6 +134,7 @@ data class CastingContext( // for what purpose i cannot imagine // http://redditpublic.com/images/b/b2/Items_slot_number.png looks right // and offhand is 150 Inventory.java:464 + // todo discovery? fun getOperativeSlot(stackOK: Predicate): Int? { val otherHandStack = this.caster.getItemInHand(this.otherHand) if (stackOK.test(otherHandStack)) { @@ -214,4 +216,16 @@ data class CastingContext( val advs = this.caster.advancements return advs.getOrStartProgress(adv!!).isDone } + + companion object { + init { + DiscoveryHandlers.addItemSlotDiscoverer { + val inv = it.caster.inventory + inv.items.toMutableList().apply { removeAt(inv.selected) }.asReversed().toMutableList().apply { + addAll(inv.offhand) + add(inv.getSelected()) + } + } + } + } } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingHarness.kt b/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingHarness.kt index 1e88d402..100f5409 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingHarness.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/spell/casting/CastingHarness.kt @@ -486,12 +486,12 @@ class CastingHarness private constructor( .mapNotNull(IXplatAbstractions.INSTANCE::findManaHolder) } DiscoveryHandlers.addManaHolderDiscoverer { - it.ctx.caster.armorSlots + it.ctx.caster.inventory.armor .filter(::isManaItem) .mapNotNull(IXplatAbstractions.INSTANCE::findManaHolder) } DiscoveryHandlers.addManaHolderDiscoverer { - listOf(it.ctx.caster.offhandItem) + it.ctx.caster.inventory.offhand .filter(::isManaItem) .mapNotNull(IXplatAbstractions.INSTANCE::findManaHolder) } diff --git a/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt b/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt index 4bb0a9f0..8d01bbb6 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt +++ b/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt @@ -1,5 +1,6 @@ package at.petrak.hexcasting.client.gui +import at.petrak.hexcasting.api.misc.DiscoveryHandlers import at.petrak.hexcasting.api.mod.HexConfig import at.petrak.hexcasting.api.mod.HexItemTags import at.petrak.hexcasting.api.spell.casting.ControllerInfo @@ -10,13 +11,11 @@ import at.petrak.hexcasting.api.spell.math.HexCoord import at.petrak.hexcasting.api.spell.math.HexDir import at.petrak.hexcasting.api.spell.math.HexPattern import at.petrak.hexcasting.api.utils.asTranslatedComponent -import at.petrak.hexcasting.api.utils.otherHand import at.petrak.hexcasting.client.ShiftScrollListener import at.petrak.hexcasting.client.drawPatternFromPoints import at.petrak.hexcasting.client.drawSpot import at.petrak.hexcasting.client.ktxt.accumulatedScroll import at.petrak.hexcasting.client.sound.GridSoundInstance -import at.petrak.hexcasting.common.lib.HexItems import at.petrak.hexcasting.common.lib.HexSounds import at.petrak.hexcasting.common.network.MsgNewSpellPatternSyn import at.petrak.hexcasting.xplat.IClientXplatAbstractions @@ -352,13 +351,12 @@ class GuiSpellcasting( /** Distance between adjacent hex centers */ fun hexSize(): Float { - val hasLens = Minecraft.getInstance().player!! - .getItemInHand(otherHand(this.handOpenedWith)).`is`(HexItems.SCRYING_LENS) + val scaleModifier = DiscoveryHandlers.gridScaleModifier(Minecraft.getInstance().player) // Originally, we allowed 32 dots across. Assuming a 1920x1080 screen this allowed like 500-odd area. // Let's be generous and give them 512. val baseScale = sqrt(this.width.toDouble() * this.height / 512.0) - return baseScale.toFloat() * if (hasLens) 0.75f else 1f + return baseScale.toFloat() * scaleModifier } fun coordsOffset(): Vec2 = Vec2(this.width.toFloat() * 0.5f, this.height.toFloat() * 0.5f) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/ItemLens.java b/Common/src/main/java/at/petrak/hexcasting/common/items/ItemLens.java index e370cb48..82864339 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/ItemLens.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/ItemLens.java @@ -38,6 +38,9 @@ public class ItemLens extends Item implements Wearable { DiscoveryHandlers.addLensPredicate(player -> player.getItemBySlot(EquipmentSlot.MAINHAND).is(HexItems.SCRYING_LENS)); DiscoveryHandlers.addLensPredicate(player -> player.getItemBySlot(EquipmentSlot.OFFHAND).is(HexItems.SCRYING_LENS)); DiscoveryHandlers.addLensPredicate(player -> player.getItemBySlot(EquipmentSlot.HEAD).is(HexItems.SCRYING_LENS)); + + DiscoveryHandlers.addGridScaleModifier(player -> player.getItemBySlot(EquipmentSlot.MAINHAND).is(HexItems.SCRYING_LENS) ? 0.75f : 1); + DiscoveryHandlers.addGridScaleModifier(player -> player.getItemBySlot(EquipmentSlot.OFFHAND).is(HexItems.SCRYING_LENS) ? 0.75f : 1); } public ItemLens(Properties pProperties) { diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java index 8c92a21d..8865081c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java @@ -36,23 +36,26 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem { if (!player.isCreative()) return List.of(); - for (ItemStack item : player.inventoryMenu.getItems()) { + for (ItemStack item : player.getInventory().items) { if (isDebug(item)) { return List.of(new DebugUnlockerHolder(item)); } } // Technically possible with commands! - for (ItemStack item : player.getArmorSlots()) { + for (ItemStack item : player.getInventory().armor) { if (isDebug(item)) { return List.of(new DebugUnlockerHolder(item)); } } - if (isDebug(player.getOffhandItem())) { - return List.of(new DebugUnlockerHolder(player.getOffhandItem())); + for (ItemStack item : player.getInventory().offhand) { + if (isDebug(item)) { + return List.of(new DebugUnlockerHolder(item)); + } } + return List.of(); }); }