Skip to content

Commit 3a3badd

Browse files
authored
Add player attributes from Hexxy Attributes (#823)
2 parents 84c4889 + c5c8f3f commit 3a3badd

File tree

10 files changed

+73
-11
lines changed

10 files changed

+73
-11
lines changed

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import at.petrak.hexcasting.api.mod.HexConfig;
1111
import at.petrak.hexcasting.api.pigment.FrozenPigment;
1212
import at.petrak.hexcasting.api.utils.HexUtils;
13+
import at.petrak.hexcasting.common.lib.HexAttributes;
1314
import net.minecraft.core.BlockPos;
1415
import net.minecraft.nbt.CompoundTag;
1516
import net.minecraft.network.chat.Component;
@@ -247,6 +248,9 @@ public boolean isEnlightened() {
247248
* positive.
248249
*/
249250
public long extractMedia(long cost, boolean simulate) {
251+
if (this.getCastingEntity() != null){
252+
cost = (long) (cost * this.getCastingEntity().getAttributeValue(HexAttributes.MEDIA_CONSUMPTION_MODIFIER));
253+
}
250254
for (var extractMediaComponent : preMediaExtract)
251255
cost = extractMediaComponent.onExtractMedia(cost, simulate);
252256
cost = extractMediaEnvironment(cost, simulate);

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/CircleCastEnv.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import at.petrak.hexcasting.api.casting.mishaps.MishapDisallowedSpell;
1414
import at.petrak.hexcasting.api.mod.HexConfig;
1515
import at.petrak.hexcasting.api.pigment.FrozenPigment;
16+
import at.petrak.hexcasting.common.lib.HexAttributes;
1617
import net.minecraft.core.BlockPos;
1718
import net.minecraft.network.chat.Component;
1819
import net.minecraft.resources.ResourceLocation;
@@ -29,8 +30,6 @@
2930
import java.util.List;
3031
import java.util.function.Predicate;
3132

32-
import static at.petrak.hexcasting.api.casting.eval.env.PlayerBasedCastEnv.SENTINEL_RADIUS;
33-
3433
public class CircleCastEnv extends CastingEnvironment {
3534
protected final CircleExecutionState execState;
3635

@@ -133,6 +132,7 @@ public long extractMediaEnvironment(long cost, boolean simulate) {
133132
public boolean isVecInRangeEnvironment(Vec3 vec) {
134133
var caster = this.execState.getCaster(this.world);
135134
if (caster != null) {
135+
double sentinelRadius = caster.getAttributeValue(HexAttributes.SENTINEL_RADIUS);
136136
if (vec.distanceToSqr(caster.position()) <= caster.getBbHeight() * caster.getBbHeight()) {
137137
return true;
138138
}
@@ -141,7 +141,7 @@ public boolean isVecInRangeEnvironment(Vec3 vec) {
141141
if (sentinel != null
142142
&& sentinel.extendsRange()
143143
&& caster.level().dimension() == sentinel.dimension()
144-
&& vec.distanceToSqr(sentinel.position()) <= SENTINEL_RADIUS * SENTINEL_RADIUS + 0.00000000001
144+
&& vec.distanceToSqr(sentinel.position()) <= sentinelRadius * sentinelRadius + 0.00000000001
145145
) {
146146
return true;
147147
}

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/env/PlayerBasedCastEnv.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import at.petrak.hexcasting.api.pigment.FrozenPigment;
1515
import at.petrak.hexcasting.api.utils.HexUtils;
1616
import at.petrak.hexcasting.api.utils.MediaHelper;
17+
import at.petrak.hexcasting.common.lib.HexAttributes;
1718
import at.petrak.hexcasting.common.lib.HexDamageTypes;
1819
import at.petrak.hexcasting.xplat.IXplatAbstractions;
1920
import net.minecraft.core.BlockPos;
@@ -35,8 +36,10 @@
3536
import static at.petrak.hexcasting.api.HexAPI.modLoc;
3637

3738
public abstract class PlayerBasedCastEnv extends CastingEnvironment {
38-
public static final double AMBIT_RADIUS = 32.0;
39-
public static final double SENTINEL_RADIUS = 16.0;
39+
public static final double DEFAULT_AMBIT_RADIUS = 32.0;
40+
private double ambitRadius;
41+
public static final double DEFAULT_SENTINEL_RADIUS = 16.0;
42+
private double sentinelRadius;
4043

4144
protected final ServerPlayer caster;
4245
protected final InteractionHand castingHand;
@@ -45,6 +48,8 @@ protected PlayerBasedCastEnv(ServerPlayer caster, InteractionHand castingHand) {
4548
super(caster.serverLevel());
4649
this.caster = caster;
4750
this.castingHand = castingHand;
51+
this.ambitRadius = caster.getAttributeValue(HexAttributes.AMBIT_RADIUS);
52+
this.sentinelRadius = caster.getAttributeValue(HexAttributes.SENTINEL_RADIUS);
4853
}
4954

5055
@Override
@@ -66,6 +71,16 @@ public void postExecution(CastResult result) {
6671
this.sendMishapMsgToPlayer(doMishap);
6772
}
6873
}
74+
if (this.caster != null){
75+
double ambitAttribute = this.caster.getAttributeValue(HexAttributes.AMBIT_RADIUS);
76+
if (this.ambitRadius != ambitAttribute){
77+
this.ambitRadius = ambitAttribute;
78+
}
79+
double sentinelAttribute = this.caster.getAttributeValue(HexAttributes.SENTINEL_RADIUS);
80+
if (this.sentinelRadius != sentinelAttribute){
81+
this.sentinelRadius = sentinelAttribute;
82+
}
83+
}
6984
}
7085

7186
@Override
@@ -78,6 +93,14 @@ protected List<HeldItemInfo> getPrimaryStacks() {
7893
return getPrimaryStacksForPlayer(this.castingHand, this.caster);
7994
}
8095

96+
public double getAmbitRadius() {
97+
return this.ambitRadius;
98+
}
99+
100+
public double getSentinelRadius(){
101+
return this.sentinelRadius;
102+
}
103+
81104
@Override
82105
public boolean replaceItem(Predicate<ItemStack> stackOk, ItemStack replaceWith, @Nullable InteractionHand hand) {
83106
return replaceItemForPlayer(stackOk, replaceWith, hand, this.caster);
@@ -90,12 +113,12 @@ public boolean isVecInRangeEnvironment(Vec3 vec) {
90113
&& sentinel.extendsRange()
91114
&& this.caster.level().dimension() == sentinel.dimension()
92115
// adding 0.00000000001 to avoid machine precision errors at specific angles
93-
&& vec.distanceToSqr(sentinel.position()) <= SENTINEL_RADIUS * SENTINEL_RADIUS + 0.00000000001
116+
&& vec.distanceToSqr(sentinel.position()) <= sentinelRadius * sentinelRadius + 0.00000000001
94117
) {
95118
return true;
96119
}
97120

98-
return vec.distanceToSqr(this.caster.position()) <= AMBIT_RADIUS * AMBIT_RADIUS + 0.00000000001;
121+
return vec.distanceToSqr(this.caster.position()) <= ambitRadius * ambitRadius + 0.00000000001;
99122
}
100123

101124
@Override

Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class GuiSpellcasting constructor(
122122
val player = minecraft.player
123123
if (player != null) {
124124
val heldItem = player.getItemInHand(handOpenedWith)
125-
if (heldItem.isEmpty || !heldItem.`is`(HexTags.Items.STAVES))
125+
if (heldItem.isEmpty || !heldItem.`is`(HexTags.Items.STAVES) || player.getAttributeValue(HexAttributes.FEEBLE_MIND) > 0)
126126
closeForReal()
127127
}
128128
}

Common/src/main/java/at/petrak/hexcasting/client/render/HexAdditionalRenderers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private static void tryRenderScryingLensOverlay(GuiGraphics graphics, float part
159159
return;
160160
}
161161

162-
if (player.getAttributeValue(HexAttributes.SCRY_SIGHT) <= 0.0)
162+
if (player.getAttributeValue(HexAttributes.SCRY_SIGHT) <= 0.0 || player.getAttributeValue(HexAttributes.FEEBLE_MIND) > 0)
163163
return;
164164

165165
var hitRes = mc.hitResult;

Common/src/main/java/at/petrak/hexcasting/common/items/ItemStaff.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package at.petrak.hexcasting.common.items;
22

33
import at.petrak.hexcasting.api.HexAPI;
4+
import at.petrak.hexcasting.common.lib.HexAttributes;
45
import at.petrak.hexcasting.common.lib.HexSounds;
56
import at.petrak.hexcasting.common.msgs.MsgClearSpiralPatternsS2C;
67
import at.petrak.hexcasting.common.msgs.MsgOpenSpellGuiS2C;
@@ -25,6 +26,9 @@ public ItemStaff(Properties pProperties) {
2526

2627
@Override
2728
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
29+
if (player.getAttributeValue(HexAttributes.FEEBLE_MIND) > 0){
30+
return InteractionResultHolder.fail(player.getItemInHand(hand));
31+
}
2832
if (player.isShiftKeyDown()) {
2933
if (world.isClientSide()) {
3034
player.playSound(HexSounds.STAFF_RESET, 1f, 1f);

Common/src/main/java/at/petrak/hexcasting/common/lib/HexAttributes.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package at.petrak.hexcasting.common.lib;
22

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

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

28+
private static final String MOD_ID = HexAPI.MOD_ID;
29+
2730
public static final Attribute GRID_ZOOM = make("grid_zoom", new RangedAttribute(
28-
HexAPI.MOD_ID + ".attributes.grid_zoom", 1.0, 0.5, 4.0)).setSyncable(true);
31+
MOD_ID + ".attributes.grid_zoom", 1.0, 0.5, 4.0)).setSyncable(true);
2932

3033
/**
3134
* Whether you have the lens overlay when looking at something. 0 = no, > 0 = yes.
3235
*/
3336
public static final Attribute SCRY_SIGHT = make("scry_sight", new RangedAttribute(
34-
HexAPI.MOD_ID + ".attributes.scry_sight", 0.0, 0.0, 1.0)).setSyncable(true);
37+
MOD_ID + ".attributes.scry_sight", 0.0, 0.0, 1.0)).setSyncable(true);
38+
39+
//whether the player is allowed to use staffcasting and scrying lenses
40+
public static final Attribute FEEBLE_MIND = make("feeble_mind", new RangedAttribute(
41+
MOD_ID + ".attributes.feeble_mind", 0.0, 0.0, 1.0).setSyncable(true));
42+
43+
//a multiplier to adjust media consumption across the board
44+
public static final Attribute MEDIA_CONSUMPTION_MODIFIER = make("media_consumption", new RangedAttribute(
45+
MOD_ID + ".attributes.media_consumption", 1.0, 0.0, Double.MAX_VALUE).setSyncable(true));
46+
47+
public static final Attribute AMBIT_RADIUS = make("ambit_radius", new RangedAttribute(
48+
MOD_ID + ".attributes.ambit_radius", PlayerBasedCastEnv.DEFAULT_AMBIT_RADIUS, 0.0, Double.MAX_VALUE).setSyncable(true));
49+
50+
public static final Attribute SENTINEL_RADIUS = make("sentinel_radius", new RangedAttribute(
51+
MOD_ID + ".attributes.sentinel_radius", PlayerBasedCastEnv.DEFAULT_SENTINEL_RADIUS, 0.0, Double.MAX_VALUE).setSyncable(true));
52+
53+
3554

3655
private static <T extends Attribute> T make(String id, T attr) {
3756
var old = ATTRIBUTES.put(modLoc(id), attr);

Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,12 @@
615615

616616
attributes: {
617617
grid_zoom: "Casting Grid Size",
618+
media_consumption: "Media Consumption",
619+
ambit_radius: "Player Ambit Radius",
620+
sentinel_radius: "Sentinel Ambit Radius",
618621
// TODO: the +1 is kind of janky
619622
scry_sight: "Scrying Sight",
623+
feeble_mind: "Feeble Mind"
620624
},
621625

622626
// Action localizations

Fabric/src/main/java/at/petrak/hexcasting/fabric/mixin/FabricPlayerMixin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ protected FabricPlayerMixin(EntityType<? extends LivingEntity> entityType, Level
2222
var out = cir.getReturnValue();
2323
out.add(HexAttributes.GRID_ZOOM);
2424
out.add(HexAttributes.SCRY_SIGHT);
25+
out.add(HexAttributes.FEEBLE_MIND);
26+
out.add(HexAttributes.MEDIA_CONSUMPTION_MODIFIER);
27+
out.add(HexAttributes.AMBIT_RADIUS);
28+
out.add(HexAttributes.SENTINEL_RADIUS);
2529
}
2630
}

Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexInitializer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ private static void initListeners() {
277277
modBus.addListener((EntityAttributeModificationEvent e) -> {
278278
e.add(EntityType.PLAYER, HexAttributes.GRID_ZOOM);
279279
e.add(EntityType.PLAYER, HexAttributes.SCRY_SIGHT);
280+
e.add(EntityType.PLAYER, HexAttributes.FEEBLE_MIND);
281+
e.add(EntityType.PLAYER, HexAttributes.MEDIA_CONSUMPTION_MODIFIER);
282+
e.add(EntityType.PLAYER, HexAttributes.AMBIT_RADIUS);
283+
e.add(EntityType.PLAYER, HexAttributes.SENTINEL_RADIUS);
280284
});
281285

282286
if (ModList.get().isLoaded(HexInterop.Forge.CURIOS_API_ID)) {

0 commit comments

Comments
 (0)