From b29ccdcfc9e92941feb6bf5f053f8bf64f63e248 Mon Sep 17 00:00:00 2001 From: Half_nothing <50048293+half-nothing@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:41:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=8A=B6=E6=80=81=E6=95=88?= =?UTF-8?q?=E6=9E=9C&&=E4=BF=AE=E5=A4=8D=E7=8A=B6=E6=80=81=E5=86=B2?= =?UTF-8?q?=E7=AA=81bug=20(#19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * #fix: 优化扳手的行为逻辑,修复扳手工具提示错误 * #feat: DataGen添加战利品表提供器,为可挖掘方块添加战利品表(钻头等多方块结构暂未添加),现在他们可以在挖掘后掉落自身了 * #feat: 添加了AssesstransFormer,可以修改可见性 * #feat: 将状态效果互斥抽象为函数,提高复用性 * #fix: 修复效果互斥不对等问题 * #fix: 修复accesstransformer文件名错误 --- build.gradle | 5 +- gradle.properties | 1 - .../hechu/mindustry/kiwi/MobEffectModule.java | 2 +- .../mindustry/mixin/MixinLivingEntity.java | 36 ++++++++---- .../world/effect/BlastedMobEffect.java | 2 +- .../world/effect/BurningMobEffect.java | 50 ++++------------ .../world/effect/ElectrifiedMobEffect.java | 14 ++--- .../world/effect/FreezingMobEffect.java | 23 ++++---- .../world/effect/MeltingMobEffect.java | 57 +++++-------------- .../world/effect/MindustryMobEffect.java | 56 +++++++++++++++++- .../world/effect/OverclockMobEffect.java | 16 +++--- .../world/effect/OverdriveMobEffect.java | 37 ++++-------- .../world/effect/SappedMobEffect.java | 5 +- .../world/effect/ShockedMobEffect.java | 3 +- .../world/effect/SporeSlowedMobEffect.java | 8 ++- .../world/effect/TarredMobEffect.java | 9 +-- .../world/effect/UnmovingMobEffect.java | 9 +-- .../mindustry/world/effect/WetMobEffect.java | 17 ++++-- .../resources/META-INF/accesstransformer.cfg | 1 + 19 files changed, 177 insertions(+), 174 deletions(-) create mode 100644 src/main/resources/META-INF/accesstransformer.cfg diff --git a/build.gradle b/build.gradle index be03234..1dd647d 100644 --- a/build.gradle +++ b/build.gradle @@ -67,7 +67,7 @@ minecraft { // However, it must be at "META-INF/accesstransformer.cfg" in the final mod jar to be loaded by Forge. // This default location is a best practice to automatically put the file in the right place in the final jar. // See https://docs.minecraftforge.net/en/latest/advanced/accesstransformers/ for more information. - // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') + accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Default run configurations. // These can be tweaked, removed, or duplicated as needed. @@ -286,7 +286,8 @@ jar { "Implementation-Version" : project.jar.archiveVersion, "Implementation-Vendor" : mod_authors, "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - "MixinConfigs": "mixins.mindustry.json" + "MixinConfigs" : "mixins.mindustry.json", + 'FMLAT' : "accesstransformer.cfg" ]) } } diff --git a/gradle.properties b/gradle.properties index 0e0a2a5..b0f0e2a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -55,4 +55,3 @@ justEnoughCharacters_id=4620585 betterF3_id=4641169 clothConfigAPI_id=4633444 kiwi_fileId=4688568 -kiwi_fileId=4688568 diff --git a/src/main/java/com/hechu/mindustry/kiwi/MobEffectModule.java b/src/main/java/com/hechu/mindustry/kiwi/MobEffectModule.java index 4cf9038..ac6691f 100644 --- a/src/main/java/com/hechu/mindustry/kiwi/MobEffectModule.java +++ b/src/main/java/com/hechu/mindustry/kiwi/MobEffectModule.java @@ -10,9 +10,9 @@ public class MobEffectModule extends AbstractModule { public static final KiwiGO WET = go(WetMobEffect::create); public static final KiwiGO BURNING = go(BurningMobEffect::create); - public static final KiwiGO FREEZING = go(FreezingMobEffect::create); public static final KiwiGO UNMOVING = go(UnmovingMobEffect::create); public static final KiwiGO MELTING = go(MeltingMobEffect::create); + public static final KiwiGO FREEZING = go(FreezingMobEffect::create); public static final KiwiGO SAPPED = go(SappedMobEffect::create); public static final KiwiGO ELECTRIFIED = go(ElectrifiedMobEffect::create); public static final KiwiGO SPORE_SLOWED = go(SporeSlowedMobEffect::create); diff --git a/src/main/java/com/hechu/mindustry/mixin/MixinLivingEntity.java b/src/main/java/com/hechu/mindustry/mixin/MixinLivingEntity.java index 25fdb4e..9094a9d 100644 --- a/src/main/java/com/hechu/mindustry/mixin/MixinLivingEntity.java +++ b/src/main/java/com/hechu/mindustry/mixin/MixinLivingEntity.java @@ -11,8 +11,6 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.Level; -import net.minecraftforge.common.ForgeMod; -import net.minecraftforge.fluids.FluidType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -21,6 +19,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import javax.annotation.Nullable; +import java.util.Objects; @Mixin(LivingEntity.class) public abstract class MixinLivingEntity extends Entity implements Attackable, net.minecraftforge.common.extensions.IForgeLivingEntity { @@ -37,6 +36,9 @@ public abstract class MixinLivingEntity extends Entity implements Attackable, ne @Shadow public abstract boolean addEffect(MobEffectInstance pEffectInstance); + @Shadow + public abstract boolean addEffect(MobEffectInstance pEffectInstance, @org.jetbrains.annotations.Nullable Entity pEntity); + public MixinLivingEntity(EntityType pEntityType, Level pLevel) { super(pEntityType, pLevel); } @@ -81,14 +83,28 @@ protected void onGetDamageAfterMagicAbsorb(DamageSource damageSource, float dama @Inject(method = "baseTick", at = @At("HEAD"), cancellable = true) public void onBaseTick(CallbackInfo ci) { - if (this.isAlive() && this.isInWaterRainOrBubble()) { - if (!this.hasEffect(MobEffectModule.WET.get()) - || - (this.hasEffect(MobEffectModule.WET.get()) - && this.getEffect(MobEffectModule.WET.get()).getAmplifier() <= 0 - && this.getEffect(MobEffectModule.WET.get()).getDuration() <= 15 * 20)) { - this.removeEffect(MobEffectModule.WET.get()); - this.addEffect(new MobEffectInstance(MobEffectModule.WET.get(), 15 * 20 + 1, 0)); + if (this.isAlive()) { + if (this.isInWaterRainOrBubble() && + (!this.hasEffect(MobEffectModule.WET.get()) || + (this.hasEffect(MobEffectModule.WET.get()) && + this.getEffect(MobEffectModule.WET.get()).getAmplifier() <= 0 && + this.getEffect(MobEffectModule.WET.get()).getDuration() <= 15 * 20))) { + if (this.hasEffect(MobEffectModule.WET.get())) { + Objects.requireNonNull(this.getEffect(MobEffectModule.WET.get())).duration = 15 * 20 + 1; + } else { + this.addEffect(new MobEffectInstance(MobEffectModule.WET.get(), 15 * 20 + 1)); + } + } + if ((this.isInLava() || this.isOnFire()) && + (!this.hasEffect(MobEffectModule.BURNING.get()) || + (this.hasEffect(MobEffectModule.BURNING.get()) && + this.getEffect(MobEffectModule.BURNING.get()).getAmplifier() <= 0 && + this.getEffect(MobEffectModule.BURNING.get()).getDuration() <= 15 * 20))) { + if (this.hasEffect(MobEffectModule.BURNING.get())) { + Objects.requireNonNull(this.getEffect(MobEffectModule.BURNING.get())).duration = 15 * 20 + 1; + } else { + this.addEffect(new MobEffectInstance(MobEffectModule.BURNING.get(), 15 * 20 + 1)); + } } } } diff --git a/src/main/java/com/hechu/mindustry/world/effect/BlastedMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/BlastedMobEffect.java index 6eb6372..5af2929 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/BlastedMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/BlastedMobEffect.java @@ -10,7 +10,7 @@ protected BlastedMobEffect() { public static BlastedMobEffect create() { return (BlastedMobEffect) new BlastedMobEffect() - .reactive(MobEffectModule.FREEZING.get(), params -> { + .reactive(MobEffectModule.FREEZING, params -> { float j = (float) (9.0F * Math.pow(2, params.amplifier)); params.livingEntity.hurt(params.livingEntity.damageSources().magic(), j); }); diff --git a/src/main/java/com/hechu/mindustry/world/effect/BurningMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/BurningMobEffect.java index a0c3e17..2fd74cb 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/BurningMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/BurningMobEffect.java @@ -1,67 +1,37 @@ package com.hechu.mindustry.world.effect; import com.hechu.mindustry.kiwi.MobEffectModule; -import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectCategory; -import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.NotNull; public class BurningMobEffect extends MindustryMobEffect { + public static final double BASE_DAMAGE = 1f; + public BurningMobEffect() { - super(MobEffectCategory.HARMFUL, 16761940); + super(MobEffectCategory.HARMFUL, 16761940, 20); } public static BurningMobEffect create() { return (BurningMobEffect) new BurningMobEffect() - .reactive(MobEffectModule.WET.get(), params -> { - MobEffectInstance wetEffect = params.livingEntity.getEffect(MobEffectModule.WET.get()); - MobEffectInstance burningEffect = params.livingEntity.getEffect(MobEffectModule.BURNING.get()); - if (wetEffect != null && burningEffect != null) { - int t = burningEffect.getDuration() - wetEffect.getDuration(); - // 不知道怎么缩减时间,所以这么处理 - params.livingEntity.removeEffect(MobEffectModule.BURNING.get()); - params.livingEntity.removeEffect(MobEffectModule.WET.get()); - if (t > 0) { - params.livingEntity.addEffect(new MobEffectInstance(MobEffectModule.BURNING.get(), t, burningEffect.getAmplifier())); - } else { - params.livingEntity.addEffect(new MobEffectInstance(MobEffectModule.WET.get(), -t, wetEffect.getAmplifier())); - } - } - }); + .reactive(MobEffectModule.WET, params -> + reactiveHandler(params, MobEffectModule.BURNING.get(), MobEffectModule.WET.get())) + .reactive(MobEffectModule.FREEZING, params -> + reactiveHandler(params, MobEffectModule.FREEZING.get(), MobEffectModule.MELTING.get())); } - public static final int BASE_DURATION = 20; - public static final float BASE_DAMAGE = 1f; - @Override public void applyEffectTick(@NotNull LivingEntity livingEntity, int amplifier) { super.applyEffectTick(livingEntity, amplifier); if (livingEntity instanceof Player player && player.isCreative()) return; - float j = (float) (BASE_DURATION / Math.pow(2d, amplifier)); + double j = applyTimeInterval / Math.pow(2d, amplifier); if (livingEntity.hasEffect(MobEffectModule.TARRED.get())) - j += 4.0F; + j += 4.0f; livingEntity.setRemainingFireTicks(j >= 1 ? (int) j : 1); - livingEntity.hurt(livingEntity.damageSources().onFire(), j < 1f ? (BASE_DAMAGE / j) : BASE_DAMAGE); - } - - /** - * Checks whether the effect is ready to be applied this tick. - * - * @param duration - * @param amplifier - */ - @Override - public boolean isDurationEffectTick(int duration, int amplifier) { - int j = (int) (BASE_DURATION / Math.pow(2d, amplifier)); - if (j > 0) { - return duration % j == 0; - } else { - return true; - } + livingEntity.hurt(livingEntity.damageSources().onFire(), (float) (j < 1f ? (BASE_DAMAGE / j) : BASE_DAMAGE)); } } diff --git a/src/main/java/com/hechu/mindustry/world/effect/ElectrifiedMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/ElectrifiedMobEffect.java index 494ff69..1b4f867 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/ElectrifiedMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/ElectrifiedMobEffect.java @@ -6,19 +6,19 @@ import net.minecraft.world.entity.ai.attributes.Attributes; public class ElectrifiedMobEffect extends MobEffect { + public static final float BASE_SPEED_MULTIPLIER = 0.7f; + public static final float BASE_RELOAD_MULTIPLIER = 0.6f; + protected ElectrifiedMobEffect() { super(MobEffectCategory.BENEFICIAL, 9961127); } public static ElectrifiedMobEffect create() { return (ElectrifiedMobEffect) new ElectrifiedMobEffect() - .addAttributeModifier(Attributes.MOVEMENT_SPEED, - "1138CD6F-BFE8-4DE9-A4E2-269C953961E6", BASE_SPEED_MULTIPLIER - 1f, - AttributeModifier.Operation.MULTIPLY_TOTAL) - .addAttributeModifier(Attributes.ATTACK_SPEED, "072A22B9-C5FD-4F7D-8957-D8621A5D17B1", BASE_RELOAD_MULTIPLIER - 1f, - AttributeModifier.Operation.MULTIPLY_TOTAL); + .addAttributeModifier(Attributes.MOVEMENT_SPEED, "1138CD6F-BFE8-4DE9-A4E2-269C953961E6", + BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL) + .addAttributeModifier(Attributes.ATTACK_SPEED, "072A22B9-C5FD-4F7D-8957-D8621A5D17B1", + BASE_RELOAD_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); } - public static final float BASE_SPEED_MULTIPLIER = 0.7f; - public static final float BASE_RELOAD_MULTIPLIER = 0.6f; } diff --git a/src/main/java/com/hechu/mindustry/world/effect/FreezingMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/FreezingMobEffect.java index 8692cc5..d938158 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/FreezingMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/FreezingMobEffect.java @@ -1,24 +1,27 @@ package com.hechu.mindustry.world.effect; -import net.minecraft.world.effect.MobEffect; +import com.hechu.mindustry.kiwi.MobEffectModule; import net.minecraft.world.effect.MobEffectCategory; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.ai.attributes.Attribute; -import net.minecraft.world.entity.ai.attributes.AttributeMap; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; -import net.minecraft.world.entity.player.Player; -public class FreezingMobEffect extends MobEffect { +public class FreezingMobEffect extends MindustryMobEffect { + public static final float BASE_SPEED_MULTIPLIER = 0.6f; + public static final float BASE_HEALTH_MULTIPLIER = 0.8f; + protected FreezingMobEffect() { super(MobEffectCategory.HARMFUL, 7063782); } public static FreezingMobEffect create() { - return (FreezingMobEffect) new FreezingMobEffect().addAttributeModifier(Attributes.MOVEMENT_SPEED, - "6069378B-E74B-4712-8BDC-401451175BC2", BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); + return (FreezingMobEffect) new FreezingMobEffect() + .reactive(MobEffectModule.BURNING, params -> + reactiveHandler(params, MobEffectModule.FREEZING.get(), MobEffectModule.BURNING.get())) + .reactive(MobEffectModule.MELTING, params -> + reactiveHandler(params, MobEffectModule.FREEZING.get(), MobEffectModule.MELTING.get())) + .addAttributeModifier(Attributes.MOVEMENT_SPEED, "6069378B-E74B-4712-8BDC-401451175BC2", + BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); } - public static final float BASE_SPEED_MULTIPLIER = 0.6f; - public static final float BASE_HEALTH_MULTIPLIER = 0.8f;//TODO: 等待使用Mixin实现 + //TODO: 等待使用Mixin实现 } diff --git a/src/main/java/com/hechu/mindustry/world/effect/MeltingMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/MeltingMobEffect.java index 43b32d3..7d1a375 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/MeltingMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/MeltingMobEffect.java @@ -1,9 +1,7 @@ package com.hechu.mindustry.world.effect; import com.hechu.mindustry.kiwi.MobEffectModule; -import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectCategory; -import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; @@ -11,60 +9,33 @@ import org.jetbrains.annotations.NotNull; public class MeltingMobEffect extends MindustryMobEffect { + public static final float BASE_SPEED_MULTIPLIER = 0.8f; + public static final float BASE_HEALTH_MULTIPLIER = 0.8f; + public static final float BASE_DAMAGE = 1.8f; + protected MeltingMobEffect() { - super(MobEffectCategory.HARMFUL, 16752742); + super(MobEffectCategory.HARMFUL, 16752742, 20); } public static MeltingMobEffect create() { return (MeltingMobEffect) new MeltingMobEffect() - .reactive(MobEffectModule.WET.get(), params -> { - MobEffectInstance wetEffect = params.livingEntity.getEffect(MobEffectModule.WET.get()); - MobEffectInstance meltingEffect = params.livingEntity.getEffect(MobEffectModule.MELTING.get()); - if (wetEffect != null && meltingEffect != null) { - int t = meltingEffect.getDuration() - wetEffect.getDuration(); - // 不知道怎么缩减时间,所以这么处理 - params.livingEntity.removeEffect(MobEffectModule.MELTING.get()); - params.livingEntity.removeEffect(MobEffectModule.WET.get()); - if (t > 0) { - params.livingEntity.addEffect(new MobEffectInstance(MobEffectModule.MELTING.get(), t, meltingEffect.getAmplifier())); - } else { - params.livingEntity.addEffect(new MobEffectInstance(MobEffectModule.WET.get(), -t, wetEffect.getAmplifier())); - } - } - }) - .addAttributeModifier(Attributes.MOVEMENT_SPEED, - "09C9E884-72C0-448B-944D-B19B3EA34FEB", BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); + .reactive(MobEffectModule.WET, params -> + reactiveHandler(params, MobEffectModule.MELTING.get(), MobEffectModule.WET.get())) + .reactive(MobEffectModule.FREEZING, params -> + reactiveHandler(params, MobEffectModule.FREEZING.get(), MobEffectModule.BURNING.get())) + .addAttributeModifier(Attributes.MOVEMENT_SPEED, "09C9E884-72C0-448B-944D-B19B3EA34FEB", + BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); } - public static final float BASE_SPEED_MULTIPLIER = 0.8f; - public static final float BASE_HEALTH_MULTIPLIER = 0.8f; - - public static final int BASE_DURATION = 20; - public static final float BASE_DAMAGE = 1.8f; - @Override public void applyEffectTick(@NotNull LivingEntity livingEntity, int amplifier) { super.applyEffectTick(livingEntity, amplifier); if (livingEntity instanceof Player player && player.isCreative()) return; - float j = (float) (BASE_DURATION / Math.pow(2d, amplifier)); + float j = (float) (applyTimeInterval / Math.pow(2d, amplifier)); + if (livingEntity.hasEffect(MobEffectModule.TARRED.get())) + j += 8; livingEntity.setRemainingFireTicks(j >= 1 ? (int) j : 1); livingEntity.hurt(livingEntity.damageSources().onFire(), j < 1f ? (BASE_DAMAGE / j) : BASE_DAMAGE); } - - /** - * Checks whether the effect is ready to be applied this tick. - * - * @param duration - * @param amplifier - */ - @Override - public boolean isDurationEffectTick(int duration, int amplifier) { - int j = (int) (BASE_DURATION / Math.pow(2d, amplifier)); - if (j > 0) { - return duration % j == 0; - } else { - return true; - } - } } diff --git a/src/main/java/com/hechu/mindustry/world/effect/MindustryMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/MindustryMobEffect.java index b279187..a501349 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/MindustryMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/MindustryMobEffect.java @@ -2,20 +2,30 @@ import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectCategory; +import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.LivingEntity; import org.jetbrains.annotations.NotNull; +import snownee.kiwi.KiwiGO; import java.util.Map; import java.util.function.Consumer; +import static com.hechu.mindustry.MindustryConstants.logger; + public abstract class MindustryMobEffect extends MobEffect { - private final Map> affinities = new java.util.HashMap<>(); + public final double applyTimeInterval; + private final Map, Consumer> affinities = new java.util.HashMap<>(); public MindustryMobEffect(MobEffectCategory pCategory, int pColor) { + this(pCategory, pColor, 0); + } + + public MindustryMobEffect(MobEffectCategory pCategory, int pColor, int applyTimeInterval) { super(pCategory, pColor); + this.applyTimeInterval = applyTimeInterval; } - public MindustryMobEffect reactive(MobEffect effect, Consumer consumer) { + public MindustryMobEffect reactive(KiwiGO effect, Consumer consumer) { affinities.put(effect, consumer); return this; } @@ -23,7 +33,9 @@ public MindustryMobEffect reactive(MobEffect effect, Consumer @Override public void applyEffectTick(@NotNull LivingEntity livingEntity, int amplifier) { ApplyEffectParams effectParams = new ApplyEffectParams(livingEntity, amplifier); - affinities.keySet().stream().filter(livingEntity::hasEffect).map(affinities::get).forEach(consumer -> consumer.accept(effectParams)); + affinities.entrySet().stream() + .filter(entry -> livingEntity.hasEffect(entry.getKey().get())) + .forEach(entry -> entry.getValue().accept(effectParams)); } public static class ApplyEffectParams { @@ -35,4 +47,42 @@ public ApplyEffectParams(@NotNull LivingEntity livingEntity, int amplifier) { public @NotNull LivingEntity livingEntity; public int amplifier; } + + /** + * Checks whether the effect is ready to be applied this tick. + * + * @param duration + * @param amplifier + */ + @Override + public boolean isDurationEffectTick(int duration, int amplifier) { + int j = (int) (applyTimeInterval / Math.pow(2d, amplifier)); + if (j > 0) + return duration % j == 0; + return true; + } + + protected static synchronized void reactiveHandler(ApplyEffectParams params, MobEffect effect1, MobEffect effect2) { + // TODO 修改时长可能会导致客户端无法立刻刷新持续时间,所以可能还是要改 + MobEffectInstance effectInstance1 = params.livingEntity.getEffect(effect1); + MobEffectInstance effectInstance2 = params.livingEntity.getEffect(effect2); + if (effectInstance1 == null || effectInstance2 == null) + return; + logger.debug("Effect1 %s(%d), Effect2 %s(%d)" + .formatted(effect1.getDisplayName(), effectInstance1.getDuration(), + effect2.getDisplayName(), effectInstance2.getDuration())); + int t = effectInstance1.getDuration() - effectInstance2.getDuration(); + if (t == 0) { + params.livingEntity.removeEffect(effect1); + params.livingEntity.removeEffect(effect2); + return; + } + if (t > 0) { + params.livingEntity.removeEffect(effect2); + effectInstance1.duration = t; + return; + } + params.livingEntity.removeEffect(effect1); + effectInstance2.duration = -t; + } } diff --git a/src/main/java/com/hechu/mindustry/world/effect/OverclockMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/OverclockMobEffect.java index 9652e2a..8f14b61 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/OverclockMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/OverclockMobEffect.java @@ -6,21 +6,21 @@ import net.minecraft.world.entity.ai.attributes.Attributes; public class OverclockMobEffect extends MobEffect { + public static final float BASE_ATTACK_DAMAGE_MULTIPLIER = 1.15f; + public static final float BASE_SPEED_MULTIPLIER = 1.15f; + public static final float BASE_RELOAD_MULTIPLIER = 1.25f; + protected OverclockMobEffect() { super(MobEffectCategory.BENEFICIAL, 16765566); } public static OverclockMobEffect create() { return (OverclockMobEffect) new OverclockMobEffect() - .addAttributeModifier(Attributes.MOVEMENT_SPEED, - "5F2966A3-777D-4531-A663-CC80F9DBFB86", BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL) + .addAttributeModifier(Attributes.MOVEMENT_SPEED, "5F2966A3-777D-4531-A663-CC80F9DBFB86", + BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL) .addAttributeModifier(Attributes.ATTACK_DAMAGE, "CEDC5617-712E-4DEA-A237-7C2B32BD85A9", BASE_ATTACK_DAMAGE_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL) - .addAttributeModifier(Attributes.ATTACK_SPEED, "1B3287F2-CFE6-4B57-B549-0E601BCAB4DA", BASE_RELOAD_MULTIPLIER - 1f, - AttributeModifier.Operation.MULTIPLY_TOTAL); + .addAttributeModifier(Attributes.ATTACK_SPEED, "1B3287F2-CFE6-4B57-B549-0E601BCAB4DA", + BASE_RELOAD_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); } - - public static final float BASE_ATTACK_DAMAGE_MULTIPLIER = 1.15f; - public static final float BASE_SPEED_MULTIPLIER = 1.15f; - public static final float BASE_RELOAD_MULTIPLIER = 1.25f; } diff --git a/src/main/java/com/hechu/mindustry/world/effect/OverdriveMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/OverdriveMobEffect.java index c815fd3..924c4b3 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/OverdriveMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/OverdriveMobEffect.java @@ -1,6 +1,5 @@ package com.hechu.mindustry.world.effect; -import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectCategory; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.AttributeModifier; @@ -8,14 +7,20 @@ import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.NotNull; -public class OverdriveMobEffect extends MobEffect { +public class OverdriveMobEffect extends MindustryMobEffect { + public static final float BASE_SPEED_MULTIPLIER = 1.15f; + public static final float BASE_HEALTH_MULTIPLIER = 0.95f; + public static final float BASE_ATTACK_DAMAGE_MULTIPLIER = 1.4f; + public static final float BASE_HEAL_PER_SECOND = 0.6f; + protected OverdriveMobEffect() { super(MobEffectCategory.BENEFICIAL, 16765566); } public static OverdriveMobEffect create() { - return (OverdriveMobEffect) new OverdriveMobEffect().addAttributeModifier(Attributes.MOVEMENT_SPEED, - "F06556B6-259F-470E-8E09-6FE6C902C786", BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL) + return (OverdriveMobEffect) new OverdriveMobEffect() + .addAttributeModifier(Attributes.MOVEMENT_SPEED, "F06556B6-259F-470E-8E09-6FE6C902C786", + BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL) .addAttributeModifier(Attributes.ATTACK_DAMAGE, "CEDC5617-712E-4DEA-A237-7C2B32BD85A9", BASE_ATTACK_DAMAGE_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); } @@ -25,29 +30,7 @@ public void applyEffectTick(@NotNull LivingEntity livingEntity, int amplifier) { super.applyEffectTick(livingEntity, amplifier); if (livingEntity instanceof Player player && player.isCreative()) return; - float j = (float) (BASE_DURATION / Math.pow(2d, amplifier)); + float j = (float) (applyTimeInterval / Math.pow(2d, amplifier)); livingEntity.heal(j < 1f ? (BASE_HEAL_PER_SECOND / j) : BASE_HEAL_PER_SECOND); } - - /** - * Checks whether the effect is ready to be applied this tick. - * - * @param duration - * @param amplifier - */ - @Override - public boolean isDurationEffectTick(int duration, int amplifier) { - int j = (int) (BASE_DURATION / Math.pow(2d, amplifier)); - if (j > 0) { - return duration % j == 0; - } else { - return true; - } - } - - public static final float BASE_SPEED_MULTIPLIER = 1.15f; - public static final float BASE_HEALTH_MULTIPLIER = 0.95f; - public static final float BASE_ATTACK_DAMAGE_MULTIPLIER = 1.4f; - public static final float BASE_HEAL_PER_SECOND = 0.6f; - public static final int BASE_DURATION = 20; } diff --git a/src/main/java/com/hechu/mindustry/world/effect/SappedMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/SappedMobEffect.java index 9779cba..71133a4 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/SappedMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/SappedMobEffect.java @@ -11,8 +11,9 @@ protected SappedMobEffect() { } public static SappedMobEffect create() { - return (SappedMobEffect) new SappedMobEffect().addAttributeModifier(Attributes.MOVEMENT_SPEED, - "0412E7B6-7A9B-4206-8291-F8911C9D4F67", BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); + return (SappedMobEffect) new SappedMobEffect() + .addAttributeModifier(Attributes.MOVEMENT_SPEED, "0412E7B6-7A9B-4206-8291-F8911C9D4F67", + BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); } public static final float BASE_SPEED_MULTIPLIER = 0.8f; diff --git a/src/main/java/com/hechu/mindustry/world/effect/ShockedMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/ShockedMobEffect.java index ee9312a..5c338ec 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/ShockedMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/ShockedMobEffect.java @@ -1,7 +1,6 @@ package com.hechu.mindustry.world.effect; import com.hechu.mindustry.kiwi.MobEffectModule; -import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectCategory; public class ShockedMobEffect extends MindustryInstantenousMobEffect { @@ -11,7 +10,7 @@ protected ShockedMobEffect() { public static ShockedMobEffect create() { return (ShockedMobEffect) new ShockedMobEffect() - .reactive(MobEffectModule.WET.get(), params -> { + .reactive(MobEffectModule.WET, params -> { float j = (float) (7.0F * Math.pow(2, params.amplifier)); params.livingEntity.hurt(params.livingEntity.damageSources().magic(), j); }); diff --git a/src/main/java/com/hechu/mindustry/world/effect/SporeSlowedMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/SporeSlowedMobEffect.java index d1561e9..a0abdff 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/SporeSlowedMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/SporeSlowedMobEffect.java @@ -6,14 +6,16 @@ import net.minecraft.world.entity.ai.attributes.Attributes; public class SporeSlowedMobEffect extends MobEffect { + public static final float BASE_SPEED_MULTIPLIER = 0.8f; + protected SporeSlowedMobEffect() { super(MobEffectCategory.NEUTRAL, 7624654); } public static SporeSlowedMobEffect create() { - return (SporeSlowedMobEffect) new SporeSlowedMobEffect().addAttributeModifier(Attributes.MOVEMENT_SPEED, - "6011DBE7-8DC8-4279-BAB2-99267A65B6C6", BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); + return (SporeSlowedMobEffect) new SporeSlowedMobEffect() + .addAttributeModifier(Attributes.MOVEMENT_SPEED, "6011DBE7-8DC8-4279-BAB2-99267A65B6C6", + BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); } - public static final float BASE_SPEED_MULTIPLIER = 0.8f; } diff --git a/src/main/java/com/hechu/mindustry/world/effect/TarredMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/TarredMobEffect.java index 8cc6afc..9fb418d 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/TarredMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/TarredMobEffect.java @@ -6,14 +6,15 @@ import net.minecraft.world.entity.ai.attributes.Attributes; public class TarredMobEffect extends MobEffect { + public static final float BASE_SPEED_MULTIPLIER = 0.6f; + protected TarredMobEffect() { super(MobEffectCategory.NEUTRAL, 3223857); } public static TarredMobEffect create() { - return (TarredMobEffect) new TarredMobEffect().addAttributeModifier(Attributes.MOVEMENT_SPEED, - "876CE14E-6630-461C-87A6-F7C0458581B2", BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); + return (TarredMobEffect) new TarredMobEffect() + .addAttributeModifier(Attributes.MOVEMENT_SPEED, "876CE14E-6630-461C-87A6-F7C0458581B2", + BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); } - - public static final float BASE_SPEED_MULTIPLIER = 0.6f; } diff --git a/src/main/java/com/hechu/mindustry/world/effect/UnmovingMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/UnmovingMobEffect.java index 951b7b1..1822287 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/UnmovingMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/UnmovingMobEffect.java @@ -11,9 +11,10 @@ protected UnmovingMobEffect() { } public static UnmovingMobEffect create() { - return (UnmovingMobEffect) new UnmovingMobEffect().addAttributeModifier(Attributes.MOVEMENT_SPEED, - "DBFFFCE7-5055-4E1F-ABD3-196EE8F94DED", -1f, AttributeModifier.Operation.MULTIPLY_TOTAL); - //.addAttributeModifier(Attributes.JUMP_STRENGTH, - // "B0E07E41-FFF9-4D50-89F7-82482CFA7618", -1f, AttributeModifier.Operation.MULTIPLY_TOTAL);//TODO: 等待使用Mixin实现 + return (UnmovingMobEffect) new UnmovingMobEffect() + .addAttributeModifier(Attributes.MOVEMENT_SPEED, "DBFFFCE7-5055-4E1F-ABD3-196EE8F94DED", + -1f, AttributeModifier.Operation.MULTIPLY_TOTAL); + //.addAttributeModifier(Attributes.JUMP_STRENGTH, + // "B0E07E41-FFF9-4D50-89F7-82482CFA7618", -1f, AttributeModifier.Operation.MULTIPLY_TOTAL);//TODO: 等待使用Mixin实现 } } diff --git a/src/main/java/com/hechu/mindustry/world/effect/WetMobEffect.java b/src/main/java/com/hechu/mindustry/world/effect/WetMobEffect.java index f34153f..6ca9a49 100644 --- a/src/main/java/com/hechu/mindustry/world/effect/WetMobEffect.java +++ b/src/main/java/com/hechu/mindustry/world/effect/WetMobEffect.java @@ -1,19 +1,24 @@ package com.hechu.mindustry.world.effect; -import net.minecraft.world.effect.MobEffect; +import com.hechu.mindustry.kiwi.MobEffectModule; import net.minecraft.world.effect.MobEffectCategory; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; -public class WetMobEffect extends MobEffect { +public class WetMobEffect extends MindustryMobEffect { + public static final float BASE_SPEED_MULTIPLIER = 0.94f; + protected WetMobEffect() { super(MobEffectCategory.NEUTRAL, 4286688); } public static WetMobEffect create() { - return (WetMobEffect) new WetMobEffect().addAttributeModifier(Attributes.MOVEMENT_SPEED, - "D59732C5-E09A-4952-8505-ED83BCF77402", BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); + return (WetMobEffect) new WetMobEffect() + .reactive(MobEffectModule.BURNING, params -> + reactiveHandler(params, MobEffectModule.BURNING.get(), MobEffectModule.WET.get())) + .reactive(MobEffectModule.MELTING, params -> + reactiveHandler(params, MobEffectModule.MELTING.get(), MobEffectModule.WET.get())) + .addAttributeModifier(Attributes.MOVEMENT_SPEED, "D59732C5-E09A-4952-8505-ED83BCF77402", + BASE_SPEED_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL); } - - public static final float BASE_SPEED_MULTIPLIER = 0.94f; } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg new file mode 100644 index 0000000..69231cd --- /dev/null +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -0,0 +1 @@ +public net.minecraft.world.effect.MobEffectInstance f_19503_ # duration \ No newline at end of file