Merge branch 'main' of git+ssh://github.com/gamma-delta/HexMod into main
This commit is contained in:
commit
d7df7cd412
33 changed files with 639 additions and 129 deletions
|
@ -38,6 +38,9 @@ dependencies {
|
||||||
compileOnly "at.petra-k.paucal:paucal-common-$minecraftVersion:$paucalVersion"
|
compileOnly "at.petra-k.paucal:paucal-common-$minecraftVersion:$paucalVersion"
|
||||||
compileOnly "vazkii.patchouli:Patchouli-xplat:$minecraftVersion-$patchouliVersion"
|
compileOnly "vazkii.patchouli:Patchouli-xplat:$minecraftVersion-$patchouliVersion"
|
||||||
|
|
||||||
|
compileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
|
||||||
|
testCompileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
|
||||||
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.1'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.1'
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.1'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.1'
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,69 @@
|
||||||
package at.petrak.hexcasting.api.addldata;
|
package at.petrak.hexcasting.api.addldata;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
public interface ManaHolder {
|
public interface ManaHolder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use {@code withdrawMana(-1, true)}
|
||||||
|
*
|
||||||
|
* @see ManaHolder#withdrawMana(int, boolean)
|
||||||
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
int getMana();
|
int getMana();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use {@code withdrawMana(-1, true) + insertMana(-1, true)} where possible
|
||||||
|
*
|
||||||
|
* @see ManaHolder#insertMana(int, boolean)
|
||||||
|
* @see ManaHolder#withdrawMana(int, boolean)
|
||||||
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
int getMaxMana();
|
int getMaxMana();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use {@code insertMana(mana - withdrawMana(-1, true), false)} where possible
|
||||||
|
*
|
||||||
|
* @see ManaHolder#insertMana(int, boolean)
|
||||||
|
* @see ManaHolder#withdrawMana(int, boolean)
|
||||||
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
void setMana(int mana);
|
void setMana(int mana);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this mana holder can have mana inserted into it.
|
||||||
|
*/
|
||||||
boolean canRecharge();
|
boolean canRecharge();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this mana holder can be extracted from.
|
||||||
|
*/
|
||||||
boolean canProvide();
|
boolean canProvide();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The priority for this mana holder to be selected when casting a hex. Higher priorities are taken first.
|
||||||
|
*
|
||||||
|
* By default,
|
||||||
|
* * Charged Amethyst has priority 1
|
||||||
|
* * Amethyst Shards have priority 2
|
||||||
|
* * Amethyst Dust has priority 3
|
||||||
|
* * Items which hold mana have priority 40
|
||||||
|
*/
|
||||||
int getConsumptionPriority();
|
int getConsumptionPriority();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the mana inside this mana holder may be used to construct a battery.
|
||||||
|
*/
|
||||||
boolean canConstructBattery();
|
boolean canConstructBattery();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Withdraws mana from the holder. Returns the amount of mana extracted, which may be less or more than the cost.
|
||||||
|
*
|
||||||
|
* Even if {@link ManaHolder#canProvide} is false, you can still withdraw mana this way.
|
||||||
|
*
|
||||||
|
* Withdrawing a negative amount will act as though you attempted to withdraw as much mana as the holder contains.
|
||||||
|
*/
|
||||||
default int withdrawMana(int cost, boolean simulate) {
|
default int withdrawMana(int cost, boolean simulate) {
|
||||||
if (!canProvide()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
var manaHere = getMana();
|
var manaHere = getMana();
|
||||||
if (cost < 0) {
|
if (cost < 0) {
|
||||||
cost = manaHere;
|
cost = manaHere;
|
||||||
|
@ -30,4 +74,30 @@ public interface ManaHolder {
|
||||||
}
|
}
|
||||||
return Math.min(cost, manaHere);
|
return Math.min(cost, manaHere);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts mana into the holder. Returns the amount of mana inserted, which may be less than the requested amount.
|
||||||
|
*
|
||||||
|
* Even if {@link ManaHolder#canRecharge} is false, you can still insert mana this way.
|
||||||
|
*
|
||||||
|
* Inserting a negative amount will act as though you attempted to insert exactly as much mana as the holder was missing.
|
||||||
|
*/
|
||||||
|
default int insertMana(int amount, boolean simulate) {
|
||||||
|
var manaHere = getMana();
|
||||||
|
int emptySpace = getMaxMana() - manaHere;
|
||||||
|
if (emptySpace <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (amount < 0) {
|
||||||
|
amount = emptySpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
int inserting = Math.min(amount, emptySpace);
|
||||||
|
|
||||||
|
if (!simulate) {
|
||||||
|
var newMana = manaHere + inserting;
|
||||||
|
setMana(newMana);
|
||||||
|
}
|
||||||
|
return inserting;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,11 @@ package at.petrak.hexcasting.api.item;
|
||||||
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
public interface ColorizerItem {
|
public interface ColorizerItem {
|
||||||
int color(ItemStack stack, UUID owner, float time, Vec3 position);
|
int color(ItemStack stack, UUID owner, float time, Vec3 position);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,12 @@ import net.minecraft.network.chat.TranslatableComponent;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.TooltipFlag;
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
public interface DataHolderItem {
|
public interface DataHolderItem {
|
||||||
String TAG_OVERRIDE_VISUALLY = "VisualOverride";
|
String TAG_OVERRIDE_VISUALLY = "VisualOverride";
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,12 @@ package at.petrak.hexcasting.api.item;
|
||||||
import at.petrak.hexcasting.api.spell.SpellDatum;
|
import at.petrak.hexcasting.api.spell.SpellDatum;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
public interface HexHolderItem extends ManaHolderItem {
|
public interface HexHolderItem extends ManaHolderItem {
|
||||||
|
|
||||||
boolean canDrawManaFromInventory(ItemStack stack);
|
boolean canDrawManaFromInventory(ItemStack stack);
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
package at.petrak.hexcasting.api.item;
|
package at.petrak.hexcasting.api.item;
|
||||||
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface should not be accessed direc
|
||||||
|
*/
|
||||||
|
@ApiStatus.OverrideOnly
|
||||||
public interface ManaHolderItem {
|
public interface ManaHolderItem {
|
||||||
int getMana(ItemStack stack);
|
int getMana(ItemStack stack);
|
||||||
|
|
||||||
|
@ -32,4 +37,23 @@ public interface ManaHolderItem {
|
||||||
}
|
}
|
||||||
return Math.min(cost, manaHere);
|
return Math.min(cost, manaHere);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default int insertMana(ItemStack stack, int amount, boolean simulate) {
|
||||||
|
var manaHere = getMana(stack);
|
||||||
|
int emptySpace = getMaxMana(stack) - manaHere;
|
||||||
|
if (emptySpace <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (amount < 0) {
|
||||||
|
amount = emptySpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
int inserting = Math.min(amount, emptySpace);
|
||||||
|
|
||||||
|
if (!simulate) {
|
||||||
|
var newMana = manaHere + inserting;
|
||||||
|
setMana(stack, newMana);
|
||||||
|
}
|
||||||
|
return inserting;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
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;
|
||||||
|
import java.util.function.Function;
|
||||||
|
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<>();
|
||||||
|
private static final List<Function<CastingContext, List<ItemStack>>> OPERATIVE_SLOT_DISCOVERER = new ArrayList<>();
|
||||||
|
|
||||||
|
public static boolean hasLens(Player player) {
|
||||||
|
for (var predicate : HAS_LENS_PREDICATE) {
|
||||||
|
if (predicate.test(player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ManaHolder> collectManaHolders(CastingHarness harness) {
|
||||||
|
List<ManaHolder> holders = Lists.newArrayList();
|
||||||
|
for (var discoverer : MANA_HOLDER_DISCOVERY) {
|
||||||
|
holders.addAll(discoverer.apply(harness));
|
||||||
|
}
|
||||||
|
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 List<ItemStack> collectOperableSlots(CastingContext ctx) {
|
||||||
|
List<ItemStack> stacks = Lists.newArrayList();
|
||||||
|
for (var discoverer : OPERATIVE_SLOT_DISCOVERER) {
|
||||||
|
stacks.addAll(discoverer.apply(ctx));
|
||||||
|
}
|
||||||
|
return stacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addLensPredicate(Predicate<Player> predicate) {
|
||||||
|
HAS_LENS_PREDICATE.add(predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addOperativeSlotDiscoverer(Function<CastingContext, List<ItemStack>> discoverer) {
|
||||||
|
OPERATIVE_SLOT_DISCOVERER.add(discoverer);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package at.petrak.hexcasting.api.spell.casting
|
package at.petrak.hexcasting.api.spell.casting
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.HexAPI.modLoc
|
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.mod.HexConfig
|
||||||
import at.petrak.hexcasting.api.spell.Operator
|
import at.petrak.hexcasting.api.spell.Operator
|
||||||
import at.petrak.hexcasting.api.spell.mishaps.MishapEntityTooFarAway
|
import at.petrak.hexcasting.api.spell.mishaps.MishapEntityTooFarAway
|
||||||
|
@ -40,10 +41,10 @@ data class CastingContext(
|
||||||
private val entitiesGivenMotion = mutableSetOf<Entity>()
|
private val entitiesGivenMotion = mutableSetOf<Entity>()
|
||||||
|
|
||||||
inline fun getHeldItemToOperateOn(acceptItemIf: (ItemStack) -> Boolean): Pair<ItemStack, InteractionHand> {
|
inline fun getHeldItemToOperateOn(acceptItemIf: (ItemStack) -> Boolean): Pair<ItemStack, InteractionHand> {
|
||||||
val handItem = caster.getItemInHand(castingHand)
|
val handItem = caster.getItemInHand(otherHand)
|
||||||
if (!acceptItemIf(handItem))
|
if (!acceptItemIf(handItem))
|
||||||
return caster.getItemInHand(otherHand) to otherHand
|
return caster.getItemInHand(castingHand) to castingHand
|
||||||
return handItem to castingHand
|
return handItem to otherHand
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,25 +134,12 @@ data class CastingContext(
|
||||||
// for what purpose i cannot imagine
|
// for what purpose i cannot imagine
|
||||||
// http://redditpublic.com/images/b/b2/Items_slot_number.png looks right
|
// http://redditpublic.com/images/b/b2/Items_slot_number.png looks right
|
||||||
// and offhand is 150 Inventory.java:464
|
// and offhand is 150 Inventory.java:464
|
||||||
fun getOperativeSlot(stackOK: Predicate<ItemStack>): Int? {
|
fun getOperativeSlot(stackOK: Predicate<ItemStack>): ItemStack? {
|
||||||
val otherHandStack = this.caster.getItemInHand(this.otherHand)
|
val operable = DiscoveryHandlers.collectOperableSlots(this)
|
||||||
if (stackOK.test(otherHandStack)) {
|
|
||||||
return when (this.otherHand) {
|
for (stack in operable) {
|
||||||
InteractionHand.MAIN_HAND -> this.caster.inventory.selected
|
|
||||||
InteractionHand.OFF_HAND -> 150
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val anchorSlot = when (this.castingHand) {
|
|
||||||
// slot to the right of the wand
|
|
||||||
InteractionHand.MAIN_HAND -> (this.caster.inventory.selected + 1) % 9
|
|
||||||
// first hotbar slot
|
|
||||||
InteractionHand.OFF_HAND -> 0
|
|
||||||
}
|
|
||||||
for (delta in 0 until 9) {
|
|
||||||
val slot = (anchorSlot + delta) % 9
|
|
||||||
val stack = this.caster.inventory.getItem(slot)
|
|
||||||
if (stackOK.test(stack)) {
|
if (stackOK.test(stack)) {
|
||||||
return slot
|
return stack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
@ -165,11 +153,8 @@ data class CastingContext(
|
||||||
fun withdrawItem(item: Item, count: Int, actuallyRemove: Boolean): Boolean {
|
fun withdrawItem(item: Item, count: Int, actuallyRemove: Boolean): Boolean {
|
||||||
if (this.caster.isCreative) return true
|
if (this.caster.isCreative) return true
|
||||||
|
|
||||||
val inv = this.caster.inventory
|
|
||||||
// TODO: withdraw from ender chest given a specific ender charm?
|
// TODO: withdraw from ender chest given a specific ender charm?
|
||||||
val stacksToExamine = inv.items.toMutableList().apply { removeAt(inv.selected) }.asReversed().toMutableList()
|
val stacksToExamine = DiscoveryHandlers.collectItemSlots(this)
|
||||||
stacksToExamine.addAll(inv.offhand)
|
|
||||||
stacksToExamine.add(inv.getSelected())
|
|
||||||
|
|
||||||
fun matches(stack: ItemStack): Boolean =
|
fun matches(stack: ItemStack): Boolean =
|
||||||
!stack.isEmpty && stack.`is`(item)
|
!stack.isEmpty && stack.`is`(item)
|
||||||
|
@ -214,4 +199,28 @@ data class CastingContext(
|
||||||
val advs = this.caster.advancements
|
val advs = this.caster.advancements
|
||||||
return advs.getOrStartProgress(adv!!).isDone
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscoveryHandlers.addOperativeSlotDiscoverer {
|
||||||
|
val slots = mutableListOf<ItemStack>()
|
||||||
|
val anchorSlot = if (it.castingHand == InteractionHand.MAIN_HAND) (it.caster.inventory.selected + 1) % 9 else 0
|
||||||
|
|
||||||
|
slots.add(it.caster.getItemInHand(it.otherHand))
|
||||||
|
for (delta in 0 until 9) {
|
||||||
|
val slot = (anchorSlot + delta) % 9
|
||||||
|
slots.add(it.caster.inventory.getItem(slot))
|
||||||
|
}
|
||||||
|
slots
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package at.petrak.hexcasting.api.spell.casting
|
||||||
import at.petrak.hexcasting.api.PatternRegistry
|
import at.petrak.hexcasting.api.PatternRegistry
|
||||||
import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers
|
import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers
|
||||||
import at.petrak.hexcasting.api.block.circle.BlockEntityAbstractImpetus
|
import at.petrak.hexcasting.api.block.circle.BlockEntityAbstractImpetus
|
||||||
|
import at.petrak.hexcasting.api.misc.DiscoveryHandlers
|
||||||
import at.petrak.hexcasting.api.misc.FrozenColorizer
|
import at.petrak.hexcasting.api.misc.FrozenColorizer
|
||||||
import at.petrak.hexcasting.api.misc.HexDamageSources
|
import at.petrak.hexcasting.api.misc.HexDamageSources
|
||||||
import at.petrak.hexcasting.api.mod.HexConfig
|
import at.petrak.hexcasting.api.mod.HexConfig
|
||||||
|
@ -13,7 +14,6 @@ import at.petrak.hexcasting.api.spell.math.HexDir
|
||||||
import at.petrak.hexcasting.api.spell.math.HexPattern
|
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.common.items.magic.ItemCreativeUnlocker
|
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.nbt.Tag
|
import net.minecraft.nbt.Tag
|
||||||
|
@ -395,21 +395,21 @@ class CastingHarness private constructor(
|
||||||
val casterHexHolder = IXplatAbstractions.INSTANCE.findHexHolder(casterStack)
|
val casterHexHolder = IXplatAbstractions.INSTANCE.findHexHolder(casterStack)
|
||||||
val hexHolderDrawsFromInventory = if (casterHexHolder != null) {
|
val hexHolderDrawsFromInventory = if (casterHexHolder != null) {
|
||||||
if (casterManaHolder != null) {
|
if (casterManaHolder != null) {
|
||||||
val manaAvailable = casterManaHolder.mana
|
val manaAvailable = casterManaHolder.withdrawMana(-1, true)
|
||||||
val manaToTake = min(costLeft, manaAvailable)
|
val manaToTake = min(costLeft, manaAvailable)
|
||||||
if (!fake) casterManaHolder.mana = manaAvailable - manaToTake
|
if (!fake) casterManaHolder.withdrawMana(manaToTake, false)
|
||||||
costLeft -= manaToTake
|
costLeft -= manaToTake
|
||||||
}
|
}
|
||||||
casterHexHolder.canDrawManaFromInventory()
|
casterHexHolder.canDrawManaFromInventory()
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (casterStack.`is`(HexItemTags.WANDS) || hexHolderDrawsFromInventory) {
|
if (casterStack.`is`(HexItemTags.WANDS) || hexHolderDrawsFromInventory) {
|
||||||
val manableItems = this.ctx.caster.inventory.items
|
val manaSources = DiscoveryHandlers.collectManaHolders(this)
|
||||||
.filter(::isManaItem)
|
|
||||||
.sortedWith(Comparator(::compareManaItem).reversed())
|
.sortedWith(Comparator(::compareManaItem).reversed())
|
||||||
for (stack in manableItems) {
|
for (source in manaSources) {
|
||||||
costLeft -= extractMana(stack, costLeft, simulate = fake && !ItemCreativeUnlocker.isDebug(stack))
|
costLeft -= extractMana(source, costLeft, simulate = fake)
|
||||||
if (costLeft <= 0)
|
if (costLeft <= 0)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -421,13 +421,17 @@ class CastingHarness private constructor(
|
||||||
val manaAbleToCastFromHP = this.ctx.caster.health * manaToHealth
|
val manaAbleToCastFromHP = this.ctx.caster.health * manaToHealth
|
||||||
|
|
||||||
val manaToActuallyPayFor = min(manaAbleToCastFromHP.toInt(), costLeft)
|
val manaToActuallyPayFor = min(manaAbleToCastFromHP.toInt(), costLeft)
|
||||||
if (!fake) {
|
costLeft -= if (!fake) {
|
||||||
HexAdvancementTriggers.OVERCAST_TRIGGER.trigger(this.ctx.caster, manaToActuallyPayFor)
|
|
||||||
this.ctx.caster.awardStat(HexStatistics.MANA_OVERCASTED, manaCost - costLeft)
|
|
||||||
|
|
||||||
Mishap.trulyHurt(this.ctx.caster, HexDamageSources.OVERCAST, healthtoRemove.toFloat())
|
Mishap.trulyHurt(this.ctx.caster, HexDamageSources.OVERCAST, healthtoRemove.toFloat())
|
||||||
|
|
||||||
|
val actuallyTaken = (manaAbleToCastFromHP - (this.ctx.caster.health * manaToHealth)).toInt()
|
||||||
|
|
||||||
|
HexAdvancementTriggers.OVERCAST_TRIGGER.trigger(this.ctx.caster, actuallyTaken)
|
||||||
|
this.ctx.caster.awardStat(HexStatistics.MANA_OVERCASTED, manaCost - costLeft)
|
||||||
|
actuallyTaken
|
||||||
|
} else {
|
||||||
|
manaToActuallyPayFor
|
||||||
}
|
}
|
||||||
costLeft -= manaToActuallyPayFor
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -475,6 +479,24 @@ class CastingHarness private constructor(
|
||||||
const val TAG_ESCAPE_NEXT = "escape_next"
|
const val TAG_ESCAPE_NEXT = "escape_next"
|
||||||
const val TAG_PREPACKAGED_COLORIZER = "prepackaged_colorizer"
|
const val TAG_PREPACKAGED_COLORIZER = "prepackaged_colorizer"
|
||||||
|
|
||||||
|
init {
|
||||||
|
DiscoveryHandlers.addManaHolderDiscoverer {
|
||||||
|
it.ctx.caster.inventory.items
|
||||||
|
.filter(::isManaItem)
|
||||||
|
.mapNotNull(IXplatAbstractions.INSTANCE::findManaHolder)
|
||||||
|
}
|
||||||
|
DiscoveryHandlers.addManaHolderDiscoverer {
|
||||||
|
it.ctx.caster.inventory.armor
|
||||||
|
.filter(::isManaItem)
|
||||||
|
.mapNotNull(IXplatAbstractions.INSTANCE::findManaHolder)
|
||||||
|
}
|
||||||
|
DiscoveryHandlers.addManaHolderDiscoverer {
|
||||||
|
it.ctx.caster.inventory.offhand
|
||||||
|
.filter(::isManaItem)
|
||||||
|
.mapNotNull(IXplatAbstractions.INSTANCE::findManaHolder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun fromNBT(nbt: CompoundTag, ctx: CastingContext): CastingHarness {
|
fun fromNBT(nbt: CompoundTag, ctx: CastingContext): CastingHarness {
|
||||||
return try {
|
return try {
|
||||||
|
|
|
@ -10,7 +10,8 @@ import at.petrak.hexcasting.api.spell.math.HexPattern
|
||||||
import at.petrak.hexcasting.api.utils.asTranslatedComponent
|
import at.petrak.hexcasting.api.utils.asTranslatedComponent
|
||||||
import at.petrak.hexcasting.api.utils.lightPurple
|
import at.petrak.hexcasting.api.utils.lightPurple
|
||||||
import at.petrak.hexcasting.common.lib.HexItems
|
import at.petrak.hexcasting.common.lib.HexItems
|
||||||
import at.petrak.hexcasting.ktxt.lastHurt
|
import at.petrak.hexcasting.ktxt.*
|
||||||
|
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||||
import net.minecraft.Util
|
import net.minecraft.Util
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
|
@ -75,6 +76,8 @@ sealed class Mishap : Throwable() {
|
||||||
|
|
||||||
protected fun yeetHeldItem(ctx: CastingContext, hand: InteractionHand) {
|
protected fun yeetHeldItem(ctx: CastingContext, hand: InteractionHand) {
|
||||||
val item = ctx.caster.getItemInHand(hand).copy()
|
val item = ctx.caster.getItemInHand(hand).copy()
|
||||||
|
if (hand == ctx.castingHand && IXplatAbstractions.INSTANCE.findHexHolder(item) != null)
|
||||||
|
return
|
||||||
ctx.caster.setItemInHand(hand, ItemStack.EMPTY)
|
ctx.caster.setItemInHand(hand, ItemStack.EMPTY)
|
||||||
|
|
||||||
val delta = ctx.caster.lookAngle.scale(0.5)
|
val delta = ctx.caster.lookAngle.scale(0.5)
|
||||||
|
@ -109,7 +112,25 @@ sealed class Mishap : Throwable() {
|
||||||
else
|
else
|
||||||
entity.lastHurt -= amount
|
entity.lastHurt -= amount
|
||||||
}
|
}
|
||||||
entity.hurt(source, amount)
|
if (!entity.hurt(source, amount)) {
|
||||||
|
// Ok, if you REALLY don't want to play nice...
|
||||||
|
entity.health -= amount
|
||||||
|
entity.markHurt()
|
||||||
|
|
||||||
|
if (entity.isDeadOrDying) {
|
||||||
|
if (!entity.checkTotemDeathProtection(source)) {
|
||||||
|
val sound = entity.deathSoundAccessor
|
||||||
|
if (sound != null) {
|
||||||
|
entity.playSound(sound, entity.soundVolumeAccessor, entity.voicePitch)
|
||||||
|
}
|
||||||
|
entity.die(source)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
entity.playHurtSound(source)
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.setHurtWithStamp(source, entity.level.gameTime)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
@file:JvmName("ManaHelper")
|
@file:JvmName("ManaHelper")
|
||||||
package at.petrak.hexcasting.api.utils
|
package at.petrak.hexcasting.api.utils
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.addldata.ManaHolder
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||||
import net.minecraft.util.Mth
|
import net.minecraft.util.Mth
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
|
@ -30,26 +31,38 @@ fun extractMana(
|
||||||
): Int {
|
): Int {
|
||||||
val manaHolder = IXplatAbstractions.INSTANCE.findManaHolder(stack) ?: return 0
|
val manaHolder = IXplatAbstractions.INSTANCE.findManaHolder(stack) ?: return 0
|
||||||
|
|
||||||
if (drainForBatteries && !manaHolder.canConstructBattery())
|
return extractMana(manaHolder, cost, drainForBatteries, simulate)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract [cost] mana from [holder]. If [cost] is less than zero, extract all mana instead.
|
||||||
|
* This may mutate the stack underlying [holder] (and may consume it) unless [simulate] is set.
|
||||||
|
*
|
||||||
|
* If [drainForBatteries] is false, this will only consider forms of mana that can be used to make new batteries.
|
||||||
|
*
|
||||||
|
* Return the amount of mana extracted. This may be over [cost] if mana is wasted.
|
||||||
|
*/
|
||||||
|
fun extractMana(
|
||||||
|
holder: ManaHolder,
|
||||||
|
cost: Int = -1,
|
||||||
|
drainForBatteries: Boolean = false,
|
||||||
|
simulate: Boolean = false
|
||||||
|
): Int {
|
||||||
|
if (drainForBatteries && !holder.canConstructBattery())
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
return manaHolder.withdrawMana(cost, simulate)
|
return holder.withdrawMana(cost, simulate)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorted from least important to most important
|
* Sorted from least important to most important
|
||||||
*/
|
*/
|
||||||
fun compareManaItem(astack: ItemStack, bstack: ItemStack): Int {
|
fun compareManaItem(aMana: ManaHolder, bMana: ManaHolder): Int {
|
||||||
val aMana = IXplatAbstractions.INSTANCE.findManaHolder(astack)
|
val priority = aMana.consumptionPriority - bMana.consumptionPriority
|
||||||
val bMana = IXplatAbstractions.INSTANCE.findManaHolder(bstack)
|
if (priority != 0)
|
||||||
|
return priority
|
||||||
|
|
||||||
return if (astack.item != bstack.item) {
|
return aMana.withdrawMana(-1, true) - bMana.withdrawMana(-1, true)
|
||||||
(aMana?.consumptionPriority ?: 0) - (bMana?.consumptionPriority ?: 0)
|
|
||||||
} else if (aMana != null && bMana != null) {
|
|
||||||
aMana.mana - bMana.mana
|
|
||||||
} else {
|
|
||||||
astack.count - bstack.count
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun manaBarColor(mana: Int, maxMana: Int): Int {
|
fun manaBarColor(mana: Int, maxMana: Int): Int {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package at.petrak.hexcasting.client;
|
package at.petrak.hexcasting.client;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.client.ScryingLensOverlayRegistry;
|
import at.petrak.hexcasting.api.client.ScryingLensOverlayRegistry;
|
||||||
|
import at.petrak.hexcasting.api.misc.DiscoveryHandlers;
|
||||||
import at.petrak.hexcasting.api.player.Sentinel;
|
import at.petrak.hexcasting.api.player.Sentinel;
|
||||||
import at.petrak.hexcasting.common.items.ItemLens;
|
|
||||||
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 com.mojang.blaze3d.platform.GlStateManager;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
|
@ -155,7 +155,7 @@ public class HexAdditionalRenderers {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ItemLens.hasLensHUD(player))
|
if (!DiscoveryHandlers.hasLens(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var hitRes = mc.hitResult;
|
var hitRes = mc.hitResult;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package at.petrak.hexcasting.client.gui
|
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.HexConfig
|
||||||
import at.petrak.hexcasting.api.mod.HexItemTags
|
import at.petrak.hexcasting.api.mod.HexItemTags
|
||||||
import at.petrak.hexcasting.api.spell.casting.ControllerInfo
|
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.HexDir
|
||||||
import at.petrak.hexcasting.api.spell.math.HexPattern
|
import at.petrak.hexcasting.api.spell.math.HexPattern
|
||||||
import at.petrak.hexcasting.api.utils.asTranslatedComponent
|
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.ShiftScrollListener
|
||||||
import at.petrak.hexcasting.client.drawPatternFromPoints
|
import at.petrak.hexcasting.client.drawPatternFromPoints
|
||||||
import at.petrak.hexcasting.client.drawSpot
|
import at.petrak.hexcasting.client.drawSpot
|
||||||
import at.petrak.hexcasting.client.ktxt.accumulatedScroll
|
import at.petrak.hexcasting.client.ktxt.accumulatedScroll
|
||||||
import at.petrak.hexcasting.client.sound.GridSoundInstance
|
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.lib.HexSounds
|
||||||
import at.petrak.hexcasting.common.network.MsgNewSpellPatternSyn
|
import at.petrak.hexcasting.common.network.MsgNewSpellPatternSyn
|
||||||
import at.petrak.hexcasting.xplat.IClientXplatAbstractions
|
import at.petrak.hexcasting.xplat.IClientXplatAbstractions
|
||||||
|
@ -352,13 +351,12 @@ class GuiSpellcasting(
|
||||||
|
|
||||||
/** Distance between adjacent hex centers */
|
/** Distance between adjacent hex centers */
|
||||||
fun hexSize(): Float {
|
fun hexSize(): Float {
|
||||||
val hasLens = Minecraft.getInstance().player!!
|
val scaleModifier = DiscoveryHandlers.gridScaleModifier(Minecraft.getInstance().player)
|
||||||
.getItemInHand(otherHand(this.handOpenedWith)).`is`(HexItems.SCRYING_LENS)
|
|
||||||
|
|
||||||
// Originally, we allowed 32 dots across. Assuming a 1920x1080 screen this allowed like 500-odd area.
|
// Originally, we allowed 32 dots across. Assuming a 1920x1080 screen this allowed like 500-odd area.
|
||||||
// Let's be generous and give them 512.
|
// Let's be generous and give them 512.
|
||||||
val baseScale = sqrt(this.width.toDouble() * this.height / 512.0)
|
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)
|
fun coordsOffset(): Vec2 = Vec2(this.width.toFloat() * 0.5f, this.height.toFloat() * 0.5f)
|
||||||
|
|
|
@ -20,7 +20,7 @@ class OpExplode(val fire: Boolean) : SpellOperator {
|
||||||
val strength = args.getChecked<Double>(1, argc)
|
val strength = args.getChecked<Double>(1, argc)
|
||||||
ctx.assertVecInRange(pos)
|
ctx.assertVecInRange(pos)
|
||||||
val clampedStrength = Mth.clamp(strength, 0.0, 10.0)
|
val clampedStrength = Mth.clamp(strength, 0.0, 10.0)
|
||||||
val cost = ManaConstants.DUST_UNIT * (3 * clampedStrength + if (fire) 0.125 else 1.0)
|
val cost = ManaConstants.DUST_UNIT * (3 * clampedStrength + if (fire) 1.0 else 0.125)
|
||||||
return Triple(
|
return Triple(
|
||||||
Spell(pos, clampedStrength, this.fire),
|
Spell(pos, clampedStrength, this.fire),
|
||||||
cost.toInt(),
|
cost.toInt(),
|
||||||
|
|
|
@ -63,9 +63,8 @@ object OpPlaceBlock : SpellOperator {
|
||||||
)
|
)
|
||||||
|
|
||||||
val bstate = ctx.world.getBlockState(pos)
|
val bstate = ctx.world.getBlockState(pos)
|
||||||
val placeeSlot = ctx.getOperativeSlot { it.item is BlockItem }
|
val placeeStack = ctx.getOperativeSlot { it.item is BlockItem }?.copy()
|
||||||
if (placeeSlot != null) {
|
if (placeeStack != null) {
|
||||||
val placeeStack = ctx.caster.inventory.getItem(placeeSlot).copy()
|
|
||||||
if (!IXplatAbstractions.INSTANCE.isPlacingAllowed(ctx.world, pos, placeeStack, ctx.caster))
|
if (!IXplatAbstractions.INSTANCE.isPlacingAllowed(ctx.world, pos, placeeStack, ctx.caster))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ object OpRecharge : SpellOperator {
|
||||||
): Triple<RenderedSpell, Int, List<ParticleSpray>>? {
|
): Triple<RenderedSpell, Int, List<ParticleSpray>>? {
|
||||||
val (handStack, hand) = ctx.getHeldItemToOperateOn {
|
val (handStack, hand) = ctx.getHeldItemToOperateOn {
|
||||||
val mana = IXplatAbstractions.INSTANCE.findManaHolder(it)
|
val mana = IXplatAbstractions.INSTANCE.findManaHolder(it)
|
||||||
mana != null && mana.canRecharge() && mana.mana /* doo doo da do doo */ < mana.maxMana
|
mana != null && mana.canRecharge() && mana.insertMana(-1, true) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
val mana = IXplatAbstractions.INSTANCE.findManaHolder(handStack)
|
val mana = IXplatAbstractions.INSTANCE.findManaHolder(handStack)
|
||||||
|
@ -40,7 +40,7 @@ object OpRecharge : SpellOperator {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mana.mana >= mana.maxMana)
|
if (mana.insertMana(-1, true) == 0)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
return Triple(
|
return Triple(
|
||||||
|
@ -54,19 +54,18 @@ object OpRecharge : SpellOperator {
|
||||||
override fun cast(ctx: CastingContext) {
|
override fun cast(ctx: CastingContext) {
|
||||||
val (handStack) = ctx.getHeldItemToOperateOn {
|
val (handStack) = ctx.getHeldItemToOperateOn {
|
||||||
val mana = IXplatAbstractions.INSTANCE.findManaHolder(it)
|
val mana = IXplatAbstractions.INSTANCE.findManaHolder(it)
|
||||||
mana != null && mana.canRecharge() && mana.mana < mana.maxMana
|
mana != null && mana.canRecharge() && mana.insertMana(-1, true) != 0
|
||||||
}
|
}
|
||||||
val mana = IXplatAbstractions.INSTANCE.findManaHolder(handStack)
|
val mana = IXplatAbstractions.INSTANCE.findManaHolder(handStack)
|
||||||
|
|
||||||
if (mana != null && itemEntity.isAlive) {
|
if (mana != null && itemEntity.isAlive) {
|
||||||
val entityStack = itemEntity.item.copy()
|
val entityStack = itemEntity.item.copy()
|
||||||
|
|
||||||
val maxMana = mana.maxMana
|
val emptySpace = mana.insertMana(-1, true)
|
||||||
val existingMana = mana.mana
|
|
||||||
|
|
||||||
val manaAmt = extractMana(entityStack, maxMana - existingMana)
|
val manaAmt = extractMana(entityStack, emptySpace)
|
||||||
|
|
||||||
mana.mana = manaAmt + existingMana
|
mana.insertMana(manaAmt, false)
|
||||||
|
|
||||||
itemEntity.item = entityStack
|
itemEntity.item = entityStack
|
||||||
if (entityStack.isEmpty)
|
if (entityStack.isEmpty)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package at.petrak.hexcasting.common.items;
|
package at.petrak.hexcasting.common.items;
|
||||||
|
|
||||||
import at.petrak.hexcasting.annotations.SoftImplement;
|
import at.petrak.hexcasting.annotations.SoftImplement;
|
||||||
|
import at.petrak.hexcasting.api.misc.DiscoveryHandlers;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
import at.petrak.hexcasting.common.network.MsgUpdateComparatorVisualsAck;
|
import at.petrak.hexcasting.common.network.MsgUpdateComparatorVisualsAck;
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||||
|
@ -14,7 +15,6 @@ import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.ArmorItem;
|
import net.minecraft.world.item.ArmorItem;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
@ -29,32 +29,18 @@ import net.minecraft.world.phys.HitResult;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
public class ItemLens extends Item implements Wearable {
|
public class ItemLens extends Item implements Wearable {
|
||||||
|
|
||||||
private static final List<Predicate<Player>> HAS_HUD_PREDICATE = new ArrayList<>();
|
|
||||||
static {
|
static {
|
||||||
addLensHUDPredicate(player -> player.getItemBySlot(EquipmentSlot.MAINHAND).is(HexItems.SCRYING_LENS));
|
DiscoveryHandlers.addLensPredicate(player -> player.getItemBySlot(EquipmentSlot.MAINHAND).is(HexItems.SCRYING_LENS));
|
||||||
addLensHUDPredicate(player -> player.getItemBySlot(EquipmentSlot.OFFHAND).is(HexItems.SCRYING_LENS));
|
DiscoveryHandlers.addLensPredicate(player -> player.getItemBySlot(EquipmentSlot.OFFHAND).is(HexItems.SCRYING_LENS));
|
||||||
addLensHUDPredicate(player -> player.getItemBySlot(EquipmentSlot.HEAD).is(HexItems.SCRYING_LENS));
|
DiscoveryHandlers.addLensPredicate(player -> player.getItemBySlot(EquipmentSlot.HEAD).is(HexItems.SCRYING_LENS));
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasLensHUD(Player player) {
|
DiscoveryHandlers.addGridScaleModifier(player -> player.getItemBySlot(EquipmentSlot.MAINHAND).is(HexItems.SCRYING_LENS) ? 0.75f : 1);
|
||||||
for (Predicate<Player> predicate : HAS_HUD_PREDICATE) {
|
DiscoveryHandlers.addGridScaleModifier(player -> player.getItemBySlot(EquipmentSlot.OFFHAND).is(HexItems.SCRYING_LENS) ? 0.75f : 1);
|
||||||
if (predicate.test(player)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addLensHUDPredicate(Predicate<Player> predicate) {
|
|
||||||
HAS_HUD_PREDICATE.add(predicate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemLens(Properties pProperties) {
|
public ItemLens(Properties pProperties) {
|
||||||
|
@ -82,7 +68,7 @@ public class ItemLens extends Item implements Wearable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void tickLens(Entity pEntity) {
|
public static void tickLens(Entity pEntity) {
|
||||||
if (!pEntity.getLevel().isClientSide() && pEntity instanceof ServerPlayer player && hasLensHUD(player)) {
|
if (!pEntity.getLevel().isClientSide() && pEntity instanceof ServerPlayer player && DiscoveryHandlers.hasLens(player)) {
|
||||||
sendComparatorDataToClient(player);
|
sendComparatorDataToClient(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package at.petrak.hexcasting.common.items.magic;
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.addldata.ManaHolder;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
public record DebugUnlockerHolder(ItemStack creativeUnlocker) implements ManaHolder {
|
||||||
|
@Override
|
||||||
|
public int getMana() {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxMana() {
|
||||||
|
return Integer.MAX_VALUE - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMana(int mana) {
|
||||||
|
// NO-OP
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRecharge() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canProvide() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getConsumptionPriority() {
|
||||||
|
return 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canConstructBattery() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int withdrawMana(int cost, boolean simulate) {
|
||||||
|
ItemCreativeUnlocker.addToIntArray(creativeUnlocker, ItemCreativeUnlocker.TAG_EXTRACTIONS, cost);
|
||||||
|
|
||||||
|
return cost < 0 ? getMana() : cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insertMana(int amount, boolean simulate) {
|
||||||
|
ItemCreativeUnlocker.addToIntArray(creativeUnlocker, ItemCreativeUnlocker.TAG_INSERTIONS, amount);
|
||||||
|
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,12 @@
|
||||||
package at.petrak.hexcasting.common.items.magic;
|
package at.petrak.hexcasting.common.items.magic;
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.block.circle.BlockEntityAbstractImpetus;
|
||||||
import at.petrak.hexcasting.api.item.ManaHolderItem;
|
import at.petrak.hexcasting.api.item.ManaHolderItem;
|
||||||
|
import at.petrak.hexcasting.api.misc.DiscoveryHandlers;
|
||||||
import at.petrak.hexcasting.api.misc.ManaConstants;
|
import at.petrak.hexcasting.api.misc.ManaConstants;
|
||||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
|
import at.petrak.hexcasting.common.lib.HexSounds;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.Util;
|
import net.minecraft.Util;
|
||||||
import net.minecraft.advancements.Advancement;
|
import net.minecraft.advancements.Advancement;
|
||||||
|
@ -11,13 +14,17 @@ import net.minecraft.locale.Language;
|
||||||
import net.minecraft.network.chat.*;
|
import net.minecraft.network.chat.*;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.TooltipFlag;
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -29,6 +36,36 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
|
|
||||||
public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
|
public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
|
||||||
|
|
||||||
|
static {
|
||||||
|
DiscoveryHandlers.addManaHolderDiscoverer(harness -> {
|
||||||
|
var player = harness.getCtx().getCaster();
|
||||||
|
if (!player.isCreative())
|
||||||
|
return List.of();
|
||||||
|
|
||||||
|
for (ItemStack item : player.getInventory().items) {
|
||||||
|
if (isDebug(item)) {
|
||||||
|
return List.of(new DebugUnlockerHolder(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Technically possible with commands!
|
||||||
|
for (ItemStack item : player.getInventory().armor) {
|
||||||
|
if (isDebug(item)) {
|
||||||
|
return List.of(new DebugUnlockerHolder(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ItemStack item : player.getInventory().offhand) {
|
||||||
|
if (isDebug(item)) {
|
||||||
|
return List.of(new DebugUnlockerHolder(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return List.of();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isDebug(ItemStack stack) {
|
public static boolean isDebug(ItemStack stack) {
|
||||||
return stack.is(HexItems.CREATIVE_UNLOCKER)
|
return stack.is(HexItems.CREATIVE_UNLOCKER)
|
||||||
&& stack.hasCustomHoverName()
|
&& stack.hasCustomHoverName()
|
||||||
|
@ -47,7 +84,8 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
|
||||||
return emphasized;
|
return emphasized;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String TAG_EXTRACTIONS = "extractions";
|
public static final String TAG_EXTRACTIONS = "extractions";
|
||||||
|
public static final String TAG_INSERTIONS = "insertions";
|
||||||
|
|
||||||
public ItemCreativeUnlocker(Properties properties) {
|
public ItemCreativeUnlocker(Properties properties) {
|
||||||
super(properties);
|
super(properties);
|
||||||
|
@ -75,22 +113,37 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRecharge(ItemStack stack) {
|
public boolean canRecharge(ItemStack stack) {
|
||||||
return false;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addToIntArray(ItemStack stack, String tag, int n) {
|
||||||
|
int[] arr = NBTHelper.getIntArray(stack, tag);
|
||||||
|
if (arr == null) {
|
||||||
|
arr = new int[0];
|
||||||
|
}
|
||||||
|
int[] newArr = Arrays.copyOf(arr, arr.length + 1);
|
||||||
|
newArr[newArr.length - 1] = n;
|
||||||
|
NBTHelper.putIntArray(stack, tag, newArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
||||||
if (!simulate && isDebug(stack)) {
|
if (!simulate && isDebug(stack)) {
|
||||||
int[] arr = NBTHelper.getIntArray(stack, TAG_EXTRACTIONS);
|
addToIntArray(stack, TAG_EXTRACTIONS, cost);
|
||||||
if (arr == null) {
|
|
||||||
arr = new int[0];
|
|
||||||
}
|
|
||||||
int[] newArr = Arrays.copyOf(arr, arr.length + 1);
|
|
||||||
newArr[newArr.length - 1] = cost;
|
|
||||||
NBTHelper.putIntArray(stack, TAG_EXTRACTIONS, newArr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cost < 0 ? 1 : cost;
|
return cost < 0 ? getMana(stack) : cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insertMana(ItemStack stack, int amount, boolean simulate) {
|
||||||
|
// In case it's inserted through other means
|
||||||
|
if (!simulate && isDebug(stack)) {
|
||||||
|
addToIntArray(stack, TAG_INSERTIONS, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount < 0 ? getMaxMana(stack) : amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,28 +154,44 @@ 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) && !level.isClientSide) {
|
||||||
int[] arr = NBTHelper.getIntArray(stack, TAG_EXTRACTIONS);
|
debugDisplay(stack, TAG_EXTRACTIONS, "withdrawn", "all_mana", entity);
|
||||||
if (arr != null) {
|
debugDisplay(stack, TAG_INSERTIONS, "inserted", "infinite_mana", entity);
|
||||||
NBTHelper.remove(stack, TAG_EXTRACTIONS);
|
}
|
||||||
for (int i : arr) {
|
}
|
||||||
if (i < 0) {
|
|
||||||
entity.sendMessage(new TranslatableComponent("hexcasting.debug.mana_withdrawn",
|
private void debugDisplay(ItemStack stack, String tag, String langKey, String allKey, Entity entity) {
|
||||||
stack.getDisplayName(),
|
int[] arr = NBTHelper.getIntArray(stack, tag);
|
||||||
new TranslatableComponent("hexcasting.debug.all_mana").withStyle(ChatFormatting.GRAY))
|
if (arr != null) {
|
||||||
.withStyle(ChatFormatting.LIGHT_PURPLE), Util.NIL_UUID);
|
NBTHelper.remove(stack, tag);
|
||||||
} else {
|
for (int i : arr) {
|
||||||
entity.sendMessage(new TranslatableComponent("hexcasting.debug.mana_withdrawn.with_dust",
|
if (i < 0) {
|
||||||
stack.getDisplayName(),
|
entity.sendMessage(new TranslatableComponent("hexcasting.debug.mana_" + langKey,
|
||||||
new TextComponent("" + i).withStyle(ChatFormatting.WHITE),
|
stack.getDisplayName(),
|
||||||
new TextComponent(String.format("%.2f", i * 1.0 / ManaConstants.DUST_UNIT)).withStyle(
|
new TranslatableComponent("hexcasting.debug." + allKey).withStyle(ChatFormatting.GRAY))
|
||||||
ChatFormatting.WHITE))
|
.withStyle(ChatFormatting.LIGHT_PURPLE), Util.NIL_UUID);
|
||||||
.withStyle(ChatFormatting.LIGHT_PURPLE), Util.NIL_UUID);
|
} else {
|
||||||
}
|
entity.sendMessage(new TranslatableComponent("hexcasting.debug.mana_" + langKey + ".with_dust",
|
||||||
|
stack.getDisplayName(),
|
||||||
|
new TextComponent("" + i).withStyle(ChatFormatting.WHITE),
|
||||||
|
new TextComponent(String.format("%.2f", i * 1.0 / ManaConstants.DUST_UNIT)).withStyle(
|
||||||
|
ChatFormatting.WHITE))
|
||||||
|
.withStyle(ChatFormatting.LIGHT_PURPLE), Util.NIL_UUID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InteractionResult useOn(UseOnContext context) {
|
||||||
|
BlockEntity be = context.getLevel().getBlockEntity(context.getClickedPos());
|
||||||
|
if (be instanceof BlockEntityAbstractImpetus impetus) {
|
||||||
|
impetus.setInfiniteMana();
|
||||||
|
context.getLevel().playSound(null, context.getClickedPos(), HexSounds.SPELL_CIRCLE_FIND_BLOCK, SoundSource.PLAYERS, 1f, 1f);
|
||||||
|
return InteractionResult.sidedSuccess(context.getLevel().isClientSide());
|
||||||
|
}
|
||||||
|
return InteractionResult.PASS;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity consumer) {
|
public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity consumer) {
|
||||||
if (level instanceof ServerLevel slevel && consumer instanceof ServerPlayer player) {
|
if (level instanceof ServerLevel slevel && consumer instanceof ServerPlayer player) {
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
@file:JvmName("AccessorWrappers")
|
@file:JvmName("AccessorWrappers")
|
||||||
package at.petrak.hexcasting.ktxt
|
package at.petrak.hexcasting.ktxt
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.mixin.accessor.AccessorEntity
|
||||||
import at.petrak.hexcasting.mixin.accessor.AccessorLivingEntity
|
import at.petrak.hexcasting.mixin.accessor.AccessorLivingEntity
|
||||||
import at.petrak.hexcasting.mixin.accessor.AccessorUseOnContext
|
import at.petrak.hexcasting.mixin.accessor.AccessorUseOnContext
|
||||||
import at.petrak.hexcasting.mixin.accessor.AccessorVillager
|
import at.petrak.hexcasting.mixin.accessor.AccessorVillager
|
||||||
|
import net.minecraft.sounds.SoundEvent
|
||||||
import net.minecraft.world.InteractionHand
|
import net.minecraft.world.InteractionHand
|
||||||
|
import net.minecraft.world.damagesource.DamageSource
|
||||||
import net.minecraft.world.entity.Entity
|
import net.minecraft.world.entity.Entity
|
||||||
import net.minecraft.world.entity.LivingEntity
|
import net.minecraft.world.entity.LivingEntity
|
||||||
import net.minecraft.world.entity.npc.Villager
|
import net.minecraft.world.entity.npc.Villager
|
||||||
|
@ -18,6 +21,18 @@ var LivingEntity.lastHurt: Float
|
||||||
get() = (this as AccessorLivingEntity).`hex$getLastHurt`()
|
get() = (this as AccessorLivingEntity).`hex$getLastHurt`()
|
||||||
set(value) = (this as AccessorLivingEntity).`hex$setLastHurt`(value)
|
set(value) = (this as AccessorLivingEntity).`hex$setLastHurt`(value)
|
||||||
|
|
||||||
|
fun LivingEntity.playHurtSound(source: DamageSource) = (this as AccessorLivingEntity).`hex$playHurtSound`(source)
|
||||||
|
fun LivingEntity.checkTotemDeathProtection(source: DamageSource) = (this as AccessorLivingEntity).`hex$checkTotemDeathProtection`(source)
|
||||||
|
val LivingEntity.deathSoundAccessor: SoundEvent? get() = (this as AccessorLivingEntity).`hex$getDeathSound`()
|
||||||
|
val LivingEntity.soundVolumeAccessor get() = (this as AccessorLivingEntity).`hex$getSoundVolume`()
|
||||||
|
|
||||||
|
fun LivingEntity.setHurtWithStamp(source: DamageSource, stamp: Long) = (this as AccessorLivingEntity).apply {
|
||||||
|
`hex$setLastDamageSource`(source)
|
||||||
|
`hex$setLastDamageStamp`(stamp)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Entity.markHurt() = (this as AccessorEntity).`hex$markHurt`()
|
||||||
|
|
||||||
fun Villager.tellWitnessesThatIWasMurdered(murderer: Entity) = (this as AccessorVillager).`hex$tellWitnessesThatIWasMurdered`(murderer)
|
fun Villager.tellWitnessesThatIWasMurdered(murderer: Entity) = (this as AccessorVillager).`hex$tellWitnessesThatIWasMurdered`(murderer)
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package at.petrak.hexcasting.mixin.accessor;
|
||||||
|
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
|
@Mixin(Entity.class)
|
||||||
|
public interface AccessorEntity {
|
||||||
|
@Invoker("markHurt")
|
||||||
|
void hex$markHurt();
|
||||||
|
}
|
|
@ -1,8 +1,11 @@
|
||||||
package at.petrak.hexcasting.mixin.accessor;
|
package at.petrak.hexcasting.mixin.accessor;
|
||||||
|
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
@Mixin(LivingEntity.class)
|
@Mixin(LivingEntity.class)
|
||||||
public interface AccessorLivingEntity {
|
public interface AccessorLivingEntity {
|
||||||
|
@ -11,4 +14,22 @@ public interface AccessorLivingEntity {
|
||||||
|
|
||||||
@Accessor("lastHurt")
|
@Accessor("lastHurt")
|
||||||
void hex$setLastHurt(float lastHurt);
|
void hex$setLastHurt(float lastHurt);
|
||||||
|
|
||||||
|
@Invoker("playHurtSound")
|
||||||
|
void hex$playHurtSound(DamageSource source);
|
||||||
|
|
||||||
|
@Invoker("checkTotemDeathProtection")
|
||||||
|
boolean hex$checkTotemDeathProtection(DamageSource source);
|
||||||
|
|
||||||
|
@Invoker("getDeathSound")
|
||||||
|
SoundEvent hex$getDeathSound();
|
||||||
|
|
||||||
|
@Invoker("getSoundVolume")
|
||||||
|
float hex$getSoundVolume();
|
||||||
|
|
||||||
|
@Accessor("lastDamageSource")
|
||||||
|
void hex$setLastDamageSource(DamageSource source);
|
||||||
|
|
||||||
|
@Accessor("lastDamageStamp")
|
||||||
|
void hex$setLastDamageStamp(long stamp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,10 @@
|
||||||
"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 - Mana withdrawn: %s",
|
||||||
"hexcasting.debug.mana_withdrawn.with_dust": "%s - Mana withdrawn: %s (%s in dust)",
|
"hexcasting.debug.mana_withdrawn.with_dust": "%s - Mana withdrawn: %s (%s in dust)",
|
||||||
|
"hexcasting.debug.mana_inserted": "%s - Mana inserted: %s",
|
||||||
|
"hexcasting.debug.mana_inserted.with_dust": "%s - Mana inserted: %s (%s in dust)",
|
||||||
"hexcasting.debug.all_mana": "Entire contents",
|
"hexcasting.debug.all_mana": "Entire contents",
|
||||||
|
"hexcasting.debug.infinite_mana": "Infinite",
|
||||||
|
|
||||||
"hexcasting.message.cant_overcast": "That Hex needed more media than I had... I should double-check my math.",
|
"hexcasting.message.cant_overcast": "That Hex needed more media than I had... I should double-check my math.",
|
||||||
"hexcasting.message.cant_great_spell": "The spell failed, somehow... am I not skilled enough?",
|
"hexcasting.message.cant_great_spell": "The spell failed, somehow... am I not skilled enough?",
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
"MixinReloadableServerResources",
|
"MixinReloadableServerResources",
|
||||||
"MixinVillager",
|
"MixinVillager",
|
||||||
"MixinWitch",
|
"MixinWitch",
|
||||||
|
"accessor.AccessorEntity",
|
||||||
"accessor.AccessorLivingEntity",
|
"accessor.AccessorLivingEntity",
|
||||||
"accessor.AccessorLootTable",
|
"accessor.AccessorLootTable",
|
||||||
"accessor.AccessorPoiType",
|
"accessor.AccessorPoiType",
|
||||||
|
|
|
@ -57,6 +57,8 @@ dependencies {
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabricVersion}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabricVersion}"
|
||||||
|
|
||||||
// Reqs
|
// Reqs
|
||||||
|
compileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
|
||||||
|
testCompileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
|
||||||
compileOnly "com.demonwav.mcdev:annotations:1.0"
|
compileOnly "com.demonwav.mcdev:annotations:1.0"
|
||||||
|
|
||||||
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
|
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
|
||||||
|
@ -69,7 +71,6 @@ dependencies {
|
||||||
include "me.zeroeightsix:fiber:$fiberVersion"
|
include "me.zeroeightsix:fiber:$fiberVersion"
|
||||||
|
|
||||||
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-api:$cardinalComponentsVersion"
|
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-api:$cardinalComponentsVersion"
|
||||||
include "dev.onyxstudios.cardinal-components-api:cardinal-components-api:$cardinalComponentsVersion"
|
|
||||||
|
|
||||||
modImplementation "com.jamieswhiteshirt:reach-entity-attributes:2.1.1"
|
modImplementation "com.jamieswhiteshirt:reach-entity-attributes:2.1.1"
|
||||||
include "com.jamieswhiteshirt:reach-entity-attributes:2.1.1"
|
include "com.jamieswhiteshirt:reach-entity-attributes:2.1.1"
|
||||||
|
|
|
@ -3,7 +3,7 @@ fabricVersion=0.51.1+1.18.2
|
||||||
fabricLoaderVersion=0.14.5
|
fabricLoaderVersion=0.14.5
|
||||||
|
|
||||||
fiberVersion=0.23.0-2
|
fiberVersion=0.23.0-2
|
||||||
cardinalComponentsVersion=4.1.4
|
cardinalComponentsVersion=4.2.0
|
||||||
serializationHooksVersion=0.3.22
|
serializationHooksVersion=0.3.22
|
||||||
|
|
||||||
reiVersion=8.0.442
|
reiVersion=8.0.442
|
||||||
|
|
|
@ -62,6 +62,11 @@ public abstract class CCManaHolder extends ItemComponent implements ManaHolder {
|
||||||
public int withdrawMana(int cost, boolean simulate) {
|
public int withdrawMana(int cost, boolean simulate) {
|
||||||
return this.manaHolder.withdrawMana(this.stack, cost, simulate);
|
return this.manaHolder.withdrawMana(this.stack, cost, simulate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insertMana(int amount, boolean simulate) {
|
||||||
|
return this.manaHolder.insertMana(this.stack, amount, simulate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Static extends CCManaHolder {
|
public static class Static extends CCManaHolder {
|
||||||
|
|
|
@ -1,18 +1,25 @@
|
||||||
package at.petrak.hexcasting.fabric.interop.trinkets;
|
package at.petrak.hexcasting.fabric.interop.trinkets;
|
||||||
|
|
||||||
import at.petrak.hexcasting.common.items.ItemLens;
|
import at.petrak.hexcasting.api.misc.DiscoveryHandlers;
|
||||||
|
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.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
|
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||||
import dev.emi.trinkets.api.TrinketComponent;
|
import dev.emi.trinkets.api.TrinketComponent;
|
||||||
import dev.emi.trinkets.api.TrinketsApi;
|
import dev.emi.trinkets.api.TrinketsApi;
|
||||||
import dev.emi.trinkets.api.client.TrinketRendererRegistry;
|
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 java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class TrinketsApiInterop {
|
public class TrinketsApiInterop {
|
||||||
public static void init() {
|
public static void init() {
|
||||||
ItemLens.addLensHUDPredicate(player -> {
|
DiscoveryHandlers.addLensPredicate(player -> {
|
||||||
Optional<TrinketComponent> optional = TrinketsApi.getTrinketComponent(player);
|
Optional<TrinketComponent> optional = TrinketsApi.getTrinketComponent(player);
|
||||||
if (optional.isPresent()) {
|
if (optional.isPresent()) {
|
||||||
TrinketComponent component = optional.get();
|
TrinketComponent component = optional.get();
|
||||||
|
@ -20,6 +27,31 @@ public class TrinketsApiInterop {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
DiscoveryHandlers.addManaHolderDiscoverer(harness -> {
|
||||||
|
Optional<TrinketComponent> optional = TrinketsApi.getTrinketComponent(harness.getCtx().getCaster());
|
||||||
|
if (optional.isPresent()) {
|
||||||
|
TrinketComponent component = optional.get();
|
||||||
|
return component.getEquipped(ManaHelper::isManaItem).stream()
|
||||||
|
.map(Tuple::getB)
|
||||||
|
.map(IXplatAbstractions.INSTANCE::findManaHolder)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
return List.of();
|
||||||
|
});
|
||||||
|
|
||||||
|
DiscoveryHandlers.addManaHolderDiscoverer(harness -> {
|
||||||
|
Optional<TrinketComponent> optional = TrinketsApi.getTrinketComponent(harness.getCtx().getCaster());
|
||||||
|
if (optional.isPresent()) {
|
||||||
|
TrinketComponent component = optional.get();
|
||||||
|
var equipped = component.getEquipped(ItemCreativeUnlocker::isDebug);
|
||||||
|
if (!equipped.isEmpty()) {
|
||||||
|
return List.of(new DebugUnlockerHolder(equipped.get(0).getB()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return List.of();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
"minecraft": "=1.18.2",
|
"minecraft": "=1.18.2",
|
||||||
"java": ">=17",
|
"java": ">=17",
|
||||||
"fabric-language-kotlin": ">=1.7.4+kotlin.1.6.21",
|
"fabric-language-kotlin": ">=1.7.4+kotlin.1.6.21",
|
||||||
"cardinal-components": "~4.1.4",
|
"cardinal-components": ">=4.2.0",
|
||||||
"patchouli": ">=1.18.2-69",
|
"patchouli": ">=1.18.2-69",
|
||||||
"paucal": "~0.4.6"
|
"paucal": "~0.4.6"
|
||||||
},
|
},
|
||||||
|
|
|
@ -132,6 +132,9 @@ dependencies {
|
||||||
minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}"
|
minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}"
|
||||||
compileOnly project(":Common")
|
compileOnly project(":Common")
|
||||||
|
|
||||||
|
compileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
|
||||||
|
testCompileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
|
||||||
|
|
||||||
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
|
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
|
||||||
|
|
||||||
compileOnly fg.deobf("at.petra-k.paucal:paucal-forge-$minecraftVersion:$paucalVersion")
|
compileOnly fg.deobf("at.petra-k.paucal:paucal-forge-$minecraftVersion:$paucalVersion")
|
||||||
|
|
|
@ -211,6 +211,11 @@ public class ForgeCapabilityHandler {
|
||||||
public int withdrawMana(int cost, boolean simulate) {
|
public int withdrawMana(int cost, boolean simulate) {
|
||||||
return holder.withdrawMana(stack, cost, simulate);
|
return holder.withdrawMana(stack, cost, simulate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insertMana(int amount, boolean simulate) {
|
||||||
|
return holder.insertMana(stack, amount, simulate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record StaticDatumHolder(Function<ItemStack, SpellDatum<?>> provider,
|
private record StaticDatumHolder(Function<ItemStack, SpellDatum<?>> provider,
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
package at.petrak.hexcasting.forge.interop.curios;
|
package at.petrak.hexcasting.forge.interop.curios;
|
||||||
|
|
||||||
import at.petrak.hexcasting.common.items.ItemLens;
|
import at.petrak.hexcasting.api.addldata.ManaHolder;
|
||||||
|
import at.petrak.hexcasting.api.misc.DiscoveryHandlers;
|
||||||
|
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.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 com.google.common.collect.Lists;
|
||||||
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;
|
||||||
|
@ -11,19 +17,67 @@ import top.theillusivec4.curios.api.SlotTypeMessage;
|
||||||
import top.theillusivec4.curios.api.SlotTypePreset;
|
import top.theillusivec4.curios.api.SlotTypePreset;
|
||||||
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
|
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class CuriosApiInterop {
|
public class CuriosApiInterop {
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
ItemLens.addLensHUDPredicate(player -> {
|
DiscoveryHandlers.addLensPredicate(player -> {
|
||||||
AtomicBoolean hasLens = new AtomicBoolean(false);
|
AtomicBoolean hasLens = new AtomicBoolean(false);
|
||||||
player.getCapability(CuriosCapability.INVENTORY).ifPresent(handler -> {
|
player.getCapability(CuriosCapability.INVENTORY).ifPresent(handler -> {
|
||||||
ICurioStacksHandler stacksHandler = handler.getCurios().get("head");
|
ICurioStacksHandler stacksHandler = handler.getCurios().get("head");
|
||||||
if(stacksHandler != null) hasLens.set(stacksHandler.getStacks().getStackInSlot(0).is(HexItems.SCRYING_LENS));
|
if(stacksHandler != null) {
|
||||||
|
var stacks = stacksHandler.getStacks();
|
||||||
|
for (int i = 0; i < stacks.getSlots(); i++) {
|
||||||
|
if (stacks.getStackInSlot(i).is(HexItems.SCRYING_LENS)) {
|
||||||
|
hasLens.set(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return hasLens.get();
|
return hasLens.get();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
DiscoveryHandlers.addManaHolderDiscoverer(harness -> {
|
||||||
|
List<ManaHolder> holders = Lists.newArrayList();
|
||||||
|
harness.getCtx().getCaster().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 (ManaHelper.isManaItem(stack)) {
|
||||||
|
var holder = IXplatAbstractions.INSTANCE.findManaHolder(stack);
|
||||||
|
if (holder != null) {
|
||||||
|
holders.add(holder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return holders;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
DiscoveryHandlers.addManaHolderDiscoverer(harness -> {
|
||||||
|
List<ManaHolder> holders = Lists.newArrayList();
|
||||||
|
harness.getCtx().getCaster().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 (ItemCreativeUnlocker.isDebug(stack)) {
|
||||||
|
holders.add(new DebugUnlockerHolder(stack));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return holders;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onInterModEnqueue(final InterModEnqueueEvent event) {
|
public static void onInterModEnqueue(final InterModEnqueueEvent event) {
|
||||||
|
|
|
@ -6,6 +6,8 @@ org.gradle.daemon=false
|
||||||
modID=hexcasting
|
modID=hexcasting
|
||||||
modName=Hex Casting
|
modName=Hex Casting
|
||||||
|
|
||||||
|
jetbrainsAnnotationsVersion=23.0.0
|
||||||
|
|
||||||
minecraftVersion=1.18.2
|
minecraftVersion=1.18.2
|
||||||
kotlinVersion=1.6.21
|
kotlinVersion=1.6.21
|
||||||
modVersion=0.9.2
|
modVersion=0.9.2
|
||||||
|
|
Loading…
Reference in a new issue