diff --git a/CHANGELOG.md b/CHANGELOG.md index 0319e92f9d..f4498b2755 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [UNRELEASED] +### Added + +- Added the `cannot_modify_cost` tag for patterns that should ignore the `media_consumption` attribute when calculating cost, by Robotgiggle in [987](https://github.com/FallingColors/HexMod/pull/987). + +### Changed + +- Changed the `media_consumption` attribute to only apply to player-based casting, by Robotgiggle in [987](https://github.com/FallingColors/HexMod/pull/987). + ### Fixed - Fixed a crash loop when trying to generate a creative-mode ancient scroll for a Great Spell whose per-world pattern hasn't been calculated yet, by Robotgiggle in [992](https://github.com/FallingColors/HexMod/pull/992). diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java index 2345eb4267..54e033b013 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java @@ -2,6 +2,7 @@ import at.petrak.hexcasting.api.casting.ParticleSpray; import at.petrak.hexcasting.api.casting.PatternShapeMatch; +import at.petrak.hexcasting.api.casting.eval.env.PlayerBasedCastEnv; import at.petrak.hexcasting.api.casting.eval.vm.CastingImage; import at.petrak.hexcasting.api.casting.mishaps.Mishap; import at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation; @@ -186,11 +187,20 @@ public T getExtension(@NotNull CastingEn public void precheckAction(PatternShapeMatch match) throws Mishap { // TODO: this doesn't let you select special handlers. // Might be worth making a "no casting" tag on each thing - ResourceLocation key = actionKey(match); + ResourceLocation loc = actionKey(match); - if (!HexConfig.server().isActionAllowed(key)) { - throw new MishapDisallowedSpell("disallowed", key); + if (!HexConfig.server().isActionAllowed(loc)) { + throw new MishapDisallowedSpell("disallowed", loc); } + + costModifier = this.getCostModifier(match); + } + + /** + * Casting env subclasses can override this to modify the cost for a given action + */ + protected double getCostModifier(PatternShapeMatch match) { + return 1.0; } @Nullable @@ -241,6 +251,8 @@ public boolean isEnlightened() { return false; } + private double costModifier = 1.0; + /** * Attempt to extract the given amount of media. Returns the amount of media left in the cost. *

@@ -248,9 +260,7 @@ public boolean isEnlightened() { * positive. */ public long extractMedia(long cost, boolean simulate) { - if (this.getCastingEntity() != null){ - cost = (long) (cost * this.getCastingEntity().getAttributeValue(HexAttributes.MEDIA_CONSUMPTION_MODIFIER)); - } + cost = (long) (cost * costModifier); for (var extractMediaComponent : preMediaExtract) cost = extractMediaComponent.onExtractMedia(cost, simulate); cost = extractMediaEnvironment(cost, simulate); diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/PlayerBasedCastEnv.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/PlayerBasedCastEnv.java index 83e58a818b..1f5b6703ff 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/PlayerBasedCastEnv.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/PlayerBasedCastEnv.java @@ -3,6 +3,7 @@ import at.petrak.hexcasting.api.HexAPI; import at.petrak.hexcasting.api.addldata.ADMediaHolder; import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers; +import at.petrak.hexcasting.api.casting.PatternShapeMatch; import at.petrak.hexcasting.api.casting.ParticleSpray; import at.petrak.hexcasting.api.casting.eval.CastResult; import at.petrak.hexcasting.api.casting.eval.CastingEnvironment; @@ -11,6 +12,7 @@ import at.petrak.hexcasting.api.casting.mishaps.Mishap; import at.petrak.hexcasting.api.mod.HexConfig; import at.petrak.hexcasting.api.mod.HexStatistics; +import at.petrak.hexcasting.api.mod.HexTags; import at.petrak.hexcasting.api.pigment.FrozenPigment; import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.api.utils.MediaHelper; @@ -21,6 +23,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Inventory; @@ -34,6 +37,7 @@ import java.util.function.Predicate; import static at.petrak.hexcasting.api.HexAPI.modLoc; +import static at.petrak.hexcasting.api.utils.HexUtils.isOfTag; public abstract class PlayerBasedCastEnv extends CastingEnvironment { public static final double DEFAULT_AMBIT_RADIUS = 32.0; @@ -62,6 +66,16 @@ public ServerPlayer getCaster() { return this.caster; } + @Override + protected double getCostModifier(PatternShapeMatch match) { + ResourceLocation loc = actionKey(match); + if (isOfTag(IXplatAbstractions.INSTANCE.getActionRegistry(), loc, HexTags.Actions.CANNOT_MODIFY_COST)) { + return 1.0; + } else { + return this.caster.getAttributeValue(HexAttributes.MEDIA_CONSUMPTION_MODIFIER); + } + } + @Override public void postExecution(CastResult result) { super.postExecution(result); diff --git a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexTags.java b/Common/src/main/java/at/petrak/hexcasting/api/mod/HexTags.java index 3317bdbc80..34992378a9 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexTags.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/mod/HexTags.java @@ -86,6 +86,11 @@ public static final class Actions { */ public static final TagKey CAN_START_ENLIGHTEN = create("can_start_enlighten"); + /** + * Actions that should not be affected by the media_consumption attribute + */ + public static final TagKey CANNOT_MODIFY_COST = create("cannot_modify_cost"); + public static TagKey create(String name) { return TagKey.create(IXplatAbstractions.INSTANCE.getActionRegistry().key(), modLoc(name)); } diff --git a/Fabric/src/generated/resources/data/hexcasting/tags/action/cannot_modify_cost.json b/Fabric/src/generated/resources/data/hexcasting/tags/action/cannot_modify_cost.json new file mode 100644 index 0000000000..5e8aecc986 --- /dev/null +++ b/Fabric/src/generated/resources/data/hexcasting/tags/action/cannot_modify_cost.json @@ -0,0 +1,4 @@ +{ + "replace": false, + "values": [] +} \ No newline at end of file diff --git a/Forge/src/generated/resources/data/hexcasting/tags/hexcasting/action/cannot_modify_cost.json b/Forge/src/generated/resources/data/hexcasting/tags/hexcasting/action/cannot_modify_cost.json new file mode 100644 index 0000000000..f72d209df7 --- /dev/null +++ b/Forge/src/generated/resources/data/hexcasting/tags/hexcasting/action/cannot_modify_cost.json @@ -0,0 +1,3 @@ +{ + "values": [] +} \ No newline at end of file