Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -186,11 +187,20 @@ public <T extends CastingEnvironmentComponent> 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.checkCostModifier(loc);
}

/**
* Casting env subclasses can override this to modify the cost for a given action
*/
protected double checkCostModifier(ResourceLocation loc) {
return 1.0;
}

@Nullable
Expand Down Expand Up @@ -241,16 +251,16 @@ public boolean isEnlightened() {
return false;
}

protected double costModifier = 1.0;

/**
* Attempt to extract the given amount of media. Returns the amount of media left in the cost.
* <p>
* If there was enough media found, it will return less or equal to zero; if there wasn't, it will be
* 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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;
Expand All @@ -21,6 +22,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;
Expand All @@ -34,6 +36,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;
Expand Down Expand Up @@ -62,6 +65,14 @@ public ServerPlayer getCaster() {
return this.caster;
}

@Override
protected double checkCostModifier(ResourceLocation loc) {
if (this.getCastingEntity() != null && !isOfTag(IXplatAbstractions.INSTANCE.getActionRegistry(), loc, HexTags.Actions.CANNOT_MODIFY_COST)) {
return this.getCastingEntity().getAttributeValue(HexAttributes.MEDIA_CONSUMPTION_MODIFIER);
}
return 1.0;
}

@Override
public void postExecution(CastResult result) {
super.postExecution(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public static final class Actions {
*/
public static final TagKey<ActionRegistryEntry> CAN_START_ENLIGHTEN = create("can_start_enlighten");

/**
* Actions that should not be affected by the media_consumption attribute
*/
public static final TagKey<ActionRegistryEntry> CANNOT_MODIFY_COST = create("cannot_modify_cost");

public static TagKey<ActionRegistryEntry> create(String name) {
return TagKey.create(IXplatAbstractions.INSTANCE.getActionRegistry().key(), modLoc(name));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"replace": false,
"values": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": []
}
Loading