discovery of grid scale modifiers and item slots
This commit is contained in:
parent
bde6f9ad59
commit
36321c3cd0
6 changed files with 57 additions and 11 deletions
|
@ -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<Predicate<Player>> HAS_LENS_PREDICATE = new ArrayList<>();
|
||||
private static final List<Function<CastingHarness, List<ManaHolder>>> MANA_HOLDER_DISCOVERY = 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<>();
|
||||
|
||||
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<ItemStack> collectItemSlots(CastingContext ctx) {
|
||||
List<ItemStack> stacks = Lists.newArrayList();
|
||||
for (var discoverer : ITEM_SLOT_DISCOVERER) {
|
||||
stacks.addAll(discoverer.apply(ctx));
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public static void addLensPredicate(Predicate<Player> predicate) {
|
||||
HAS_LENS_PREDICATE.add(predicate);
|
||||
|
@ -39,4 +59,12 @@ public class DiscoveryHandlers {
|
|||
public static void addManaHolderDiscoverer(Function<CastingHarness, List<ManaHolder>> discoverer) {
|
||||
MANA_HOLDER_DISCOVERY.add(discoverer);
|
||||
}
|
||||
|
||||
public static void addGridScaleModifier(ToFloatFunction<Player> modifier) {
|
||||
GRID_SCALE_MODIFIERS.add(modifier);
|
||||
}
|
||||
|
||||
public static void addItemSlotDiscoverer(Function<CastingContext, List<ItemStack>> discoverer) {
|
||||
ITEM_SLOT_DISCOVERER.add(discoverer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ItemStack>): 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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -36,22 +36,25 @@ 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();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue