Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
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 All @@ -66,6 +71,16 @@ public void postExecution(CastResult result) {
this.sendMishapMsgToPlayer(doMishap);
}
}
if (this.caster != null){
double ambitAttribute = this.caster.getAttributeValue(HexAttributes.AMBIT_RADIUS);
if (this.ambitRadius != ambitAttribute){
this.ambitRadius = ambitAttribute;
}
double sentinelAttribute = this.caster.getAttributeValue(HexAttributes.SENTINEL_RADIUS);
if (this.sentinelRadius != sentinelAttribute){
this.sentinelRadius = sentinelAttribute;
}
}
}

@Override
Expand All @@ -78,6 +93,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 +113,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
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class GuiSpellcasting constructor(
val player = minecraft.player
if (player != null) {
val heldItem = player.getItemInHand(handOpenedWith)
if (heldItem.isEmpty || !heldItem.`is`(HexTags.Items.STAVES))
if (heldItem.isEmpty || !heldItem.`is`(HexTags.Items.STAVES) || player.getAttributeValue(HexAttributes.FEEBLE_MIND) > 0)
closeForReal()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static void tryRenderScryingLensOverlay(GuiGraphics graphics, float part
return;
}

if (player.getAttributeValue(HexAttributes.SCRY_SIGHT) <= 0.0)
if (player.getAttributeValue(HexAttributes.SCRY_SIGHT) <= 0.0 || player.getAttributeValue(HexAttributes.FEEBLE_MIND) > 0)
return;

var hitRes = mc.hitResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.petrak.hexcasting.common.items;

import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.common.lib.HexAttributes;
import at.petrak.hexcasting.common.lib.HexSounds;
import at.petrak.hexcasting.common.msgs.MsgClearSpiralPatternsS2C;
import at.petrak.hexcasting.common.msgs.MsgOpenSpellGuiS2C;
Expand All @@ -25,6 +26,9 @@ public ItemStaff(Properties pProperties) {

@Override
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
if (player.getAttributeValue(HexAttributes.FEEBLE_MIND) > 0){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this fine on client?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, I think it should be fine since they're marked syncable?

return InteractionResultHolder.fail(player.getItemInHand(hand));
}
if (player.isShiftKeyDown()) {
if (world.isClientSide()) {
player.playSound(HexSounds.STAFF_RESET, 1f, 1f);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.petrak.hexcasting.common.lib;

import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.api.casting.eval.env.PlayerBasedCastEnv;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.RangedAttribute;
Expand All @@ -24,14 +25,32 @@ public static void register(BiConsumer<Attribute, ResourceLocation> r) {

private static final Map<ResourceLocation, Attribute> ATTRIBUTES = new LinkedHashMap<>();

private static final String MOD_ID = HexAPI.MOD_ID;

public static final Attribute GRID_ZOOM = make("grid_zoom", new RangedAttribute(
HexAPI.MOD_ID + ".attributes.grid_zoom", 1.0, 0.5, 4.0)).setSyncable(true);
MOD_ID + ".attributes.grid_zoom", 1.0, 0.5, 4.0)).setSyncable(true);

/**
* Whether you have the lens overlay when looking at something. 0 = no, > 0 = yes.
*/
public static final Attribute SCRY_SIGHT = make("scry_sight", new RangedAttribute(
HexAPI.MOD_ID + ".attributes.scry_sight", 0.0, 0.0, 1.0)).setSyncable(true);
MOD_ID + ".attributes.scry_sight", 0.0, 0.0, 1.0)).setSyncable(true);

//whether the player is allowed to use staffcasting and scrying lenses
public static final Attribute FEEBLE_MIND = make("feeble_mind", new RangedAttribute(
MOD_ID + ".attributes.feeble_mind", 0.0, 0.0, 1.0).setSyncable(true));

//a multiplier to adjust media consumption across the board
public static final Attribute MEDIA_CONSUMPTION_MODIFIER = make("media_consumption", new RangedAttribute(
MOD_ID + ".attributes.media_consumption", 1.0, 0.0, Double.MAX_VALUE).setSyncable(true));

public static final Attribute AMBIT_RADIUS = make("ambit_radius", new RangedAttribute(
MOD_ID + ".attributes.ambit_radius", PlayerBasedCastEnv.DEFAULT_AMBIT_RADIUS, 0.0, Double.MAX_VALUE).setSyncable(true));

public static final Attribute SENTINEL_RADIUS = make("sentinel_radius", new RangedAttribute(
MOD_ID + ".attributes.sentinel_radius", PlayerBasedCastEnv.DEFAULT_SENTINEL_RADIUS, 0.0, Double.MAX_VALUE).setSyncable(true));



private static <T extends Attribute> T make(String id, T attr) {
var old = ATTRIBUTES.put(modLoc(id), attr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,12 @@

attributes: {
grid_zoom: "Casting Grid Size",
media_consumption: "Media Consumption",
ambit_radius: "Player Ambit Radius",
sentinel_radius: "Sentinel Ambit Radius",
// TODO: the +1 is kind of janky
scry_sight: "Scrying Sight",
feeble_mind: "Feeble Mind"
},

// Action localizations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ protected FabricPlayerMixin(EntityType<? extends LivingEntity> entityType, Level
var out = cir.getReturnValue();
out.add(HexAttributes.GRID_ZOOM);
out.add(HexAttributes.SCRY_SIGHT);
out.add(HexAttributes.FEEBLE_MIND);
out.add(HexAttributes.MEDIA_CONSUMPTION_MODIFIER);
out.add(HexAttributes.AMBIT_RADIUS);
out.add(HexAttributes.SENTINEL_RADIUS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be like,, auto grabbed out of the HexAttributes instead of manually listed in 3 separate places?

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ private static void initListeners() {
modBus.addListener((EntityAttributeModificationEvent e) -> {
e.add(EntityType.PLAYER, HexAttributes.GRID_ZOOM);
e.add(EntityType.PLAYER, HexAttributes.SCRY_SIGHT);
e.add(EntityType.PLAYER, HexAttributes.FEEBLE_MIND);
e.add(EntityType.PLAYER, HexAttributes.MEDIA_CONSUMPTION_MODIFIER);
e.add(EntityType.PLAYER, HexAttributes.AMBIT_RADIUS);
e.add(EntityType.PLAYER, HexAttributes.SENTINEL_RADIUS);
});

if (ModList.get().isLoaded(HexInterop.Forge.CURIOS_API_ID)) {
Expand Down
Loading