Skip to content

Commit

Permalink
Custom attribute level curve in MobEffect, restoring `getAttributeMod…
Browse files Browse the repository at this point in the history
…ifierValue` (#1334)

This allows mob effects to provide non-linear attribute modifier values
  • Loading branch information
lcy0x1 committed Aug 6, 2024
1 parent 74a0608 commit 7d32e69
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions patches/net/minecraft/world/effect/MobEffect.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,48 @@
public static final Codec<Holder<MobEffect>> CODEC = BuiltInRegistries.MOB_EFFECT.holderByNameCodec();
public static final StreamCodec<RegistryFriendlyByteBuf, Holder<MobEffect>> STREAM_CODEC = ByteBufCodecs.holderRegistry(Registries.MOB_EFFECT);
private static final int AMBIENT_ALPHA = Mth.floor(38.25F);
@@ -179,6 +_,14 @@
@Override
public FeatureFlagSet requiredFeatures() {
return this.requiredFeatures;
@@ -130,6 +_,18 @@
return this;
}

+ /**
+ * Neo: attribute template with custom level curve, for mob effects providing non-linear attribute modifiers.
+ * @param attribute The attribute of the modifier
+ * @param id ID of the modifier
+ * @param operation Operation of the modifier
+ * @param curve A function mapping effect instance amplifier to modifier amount
+ */
+ public MobEffect addAttributeModifier(Holder<Attribute> attribute, ResourceLocation id, AttributeModifier.Operation operation, it.unimi.dsi.fastutil.ints.Int2DoubleFunction curve) {
+ this.attributeModifiers.put(attribute, new MobEffect.AttributeTemplate(id, curve.apply(0), operation, curve));
+ return this;
+ }
+
public MobEffect setBlendDuration(int p_316265_) {
this.blendDurationTicks = p_316265_;
return this;
@@ -181,8 +_,24 @@
return this.requiredFeatures;
}

- static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) {
+ /**
+ * Neo: Allowing mods to define client behavior for their MobEffects
+ * @deprecated Use {@link net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent} instead
+ */
+ @Deprecated(forRemoval = true, since = "1.21")
+ public void initializeClient(java.util.function.Consumer<net.neoforged.neoforge.client.extensions.common.IClientMobEffectExtensions> consumer) {
+ }
+
+ static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation, @Nullable it.unimi.dsi.fastutil.ints.Int2DoubleFunction curve) {
+
+ public AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) {
+ this(id, amount, operation, null);
+ }
+
public AttributeModifier create(int p_316614_) {
+ if (curve != null) { // Neo: Use the custom attribute value curve if one is present
+ return new AttributeModifier(this.id, this.curve.apply(p_316614_), this.operation);
+ }
return new AttributeModifier(this.id, this.amount * (double)(p_316614_ + 1), this.operation);
}
}

static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) {

0 comments on commit 7d32e69

Please sign in to comment.