Skip to content

Commit

Permalink
优化状态效果&&修复状态冲突bug (#19)
Browse files Browse the repository at this point in the history
* #fix: 优化扳手的行为逻辑,修复扳手工具提示错误

* #feat: DataGen添加战利品表提供器,为可挖掘方块添加战利品表(钻头等多方块结构暂未添加),现在他们可以在挖掘后掉落自身了

* #feat: 添加了AssesstransFormer,可以修改可见性

* #feat: 将状态效果互斥抽象为函数,提高复用性

* #fix: 修复效果互斥不对等问题

* #fix: 修复accesstransformer文件名错误
  • Loading branch information
half-nothing authored Jan 12, 2024
1 parent 1b46b33 commit b29ccdc
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 174 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
])
}
}
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,3 @@ justEnoughCharacters_id=4620585
betterF3_id=4641169
clothConfigAPI_id=4633444
kiwi_fileId=4688568
kiwi_fileId=4688568
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
public class MobEffectModule extends AbstractModule {
public static final KiwiGO<MobEffect> WET = go(WetMobEffect::create);
public static final KiwiGO<MobEffect> BURNING = go(BurningMobEffect::create);
public static final KiwiGO<MobEffect> FREEZING = go(FreezingMobEffect::create);
public static final KiwiGO<MobEffect> UNMOVING = go(UnmovingMobEffect::create);
public static final KiwiGO<MobEffect> MELTING = go(MeltingMobEffect::create);
public static final KiwiGO<MobEffect> FREEZING = go(FreezingMobEffect::create);
public static final KiwiGO<MobEffect> SAPPED = go(SappedMobEffect::create);
public static final KiwiGO<MobEffect> ELECTRIFIED = go(ElectrifiedMobEffect::create);
public static final KiwiGO<MobEffect> SPORE_SLOWED = go(SporeSlowedMobEffect::create);
Expand Down
36 changes: 26 additions & 10 deletions src/main/java/com/hechu/mindustry/mixin/MixinLivingEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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实现
}
Original file line number Diff line number Diff line change
@@ -1,70 +1,41 @@
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;
import net.minecraft.world.entity.player.Player;
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;
}
}
}
Loading

0 comments on commit b29ccdc

Please sign in to comment.