Skip to content

Commit

Permalink
put back formerly-conflicting code
Browse files Browse the repository at this point in the history
  • Loading branch information
beholderface committed Jan 10, 2025
1 parent 6555994 commit 432da23
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.common.lib.HexAttributes;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -247,6 +248,9 @@ 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));
}
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 @@ -13,6 +13,7 @@
import at.petrak.hexcasting.api.casting.mishaps.MishapDisallowedSpell;
import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.lib.HexAttributes;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -29,8 +30,6 @@
import java.util.List;
import java.util.function.Predicate;

import static at.petrak.hexcasting.api.casting.eval.env.PlayerBasedCastEnv.SENTINEL_RADIUS;

public class CircleCastEnv extends CastingEnvironment {
protected final CircleExecutionState execState;

Expand Down Expand Up @@ -133,6 +132,7 @@ public long extractMediaEnvironment(long cost, boolean simulate) {
public boolean isVecInRangeEnvironment(Vec3 vec) {
var caster = this.execState.getCaster(this.world);
if (caster != null) {
double sentinelRadius = caster.getAttributeValue(HexAttributes.SENTINEL_RADIUS);
if (vec.distanceToSqr(caster.position()) <= caster.getBbHeight() * caster.getBbHeight()) {
return true;
}
Expand All @@ -141,7 +141,7 @@ public boolean isVecInRangeEnvironment(Vec3 vec) {
if (sentinel != null
&& sentinel.extendsRange()
&& caster.level().dimension() == sentinel.dimension()
&& vec.distanceToSqr(sentinel.position()) <= SENTINEL_RADIUS * SENTINEL_RADIUS + 0.00000000001
&& vec.distanceToSqr(sentinel.position()) <= sentinelRadius * sentinelRadius + 0.00000000001
) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.api.utils.MediaHelper;
import at.petrak.hexcasting.common.lib.HexAttributes;
import at.petrak.hexcasting.common.lib.HexDamageTypes;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.core.BlockPos;
Expand All @@ -35,8 +36,10 @@
import static at.petrak.hexcasting.api.HexAPI.modLoc;

public abstract class PlayerBasedCastEnv extends CastingEnvironment {
public static final double AMBIT_RADIUS = 32.0;
public static final double SENTINEL_RADIUS = 16.0;
public static final double DEFAULT_AMBIT_RADIUS = 32.0;
private double ambitRadius;
public static final double DEFAULT_SENTINEL_RADIUS = 16.0;
private double sentinelRadius;

protected final ServerPlayer caster;
protected final InteractionHand castingHand;
Expand All @@ -45,6 +48,8 @@ protected PlayerBasedCastEnv(ServerPlayer caster, InteractionHand castingHand) {
super(caster.serverLevel());
this.caster = caster;
this.castingHand = castingHand;
this.ambitRadius = caster.getAttributeValue(HexAttributes.AMBIT_RADIUS);
this.sentinelRadius = caster.getAttributeValue(HexAttributes.SENTINEL_RADIUS);
}

@Override
Expand Down Expand Up @@ -78,6 +83,14 @@ protected List<HeldItemInfo> getPrimaryStacks() {
return getPrimaryStacksForPlayer(this.castingHand, this.caster);
}

public double getAmbitRadius() {
return this.ambitRadius;
}

public double getSentinelRadius(){
return this.sentinelRadius;
}

@Override
public boolean replaceItem(Predicate<ItemStack> stackOk, ItemStack replaceWith, @Nullable InteractionHand hand) {
return replaceItemForPlayer(stackOk, replaceWith, hand, this.caster);
Expand All @@ -90,12 +103,12 @@ public boolean isVecInRangeEnvironment(Vec3 vec) {
&& sentinel.extendsRange()
&& this.caster.level().dimension() == sentinel.dimension()
// adding 0.00000000001 to avoid machine precision errors at specific angles
&& vec.distanceToSqr(sentinel.position()) <= SENTINEL_RADIUS * SENTINEL_RADIUS + 0.00000000001
&& vec.distanceToSqr(sentinel.position()) <= sentinelRadius * sentinelRadius + 0.00000000001
) {
return true;
}

return vec.distanceToSqr(this.caster.position()) <= AMBIT_RADIUS * AMBIT_RADIUS + 0.00000000001;
return vec.distanceToSqr(this.caster.position()) <= ambitRadius * ambitRadius + 0.00000000001;
}

@Override
Expand Down

0 comments on commit 432da23

Please sign in to comment.