Skip to content

Commit

Permalink
在模组中加入像素工厂的状态效果 (#18)
Browse files Browse the repository at this point in the history
* #feat: 添加了一些状态效果

* #feat: 添加了语言文件

* #feat: 完善状态效果
  • Loading branch information
HeChuQIU authored Jan 12, 2024
1 parent 4732ce8 commit 1b46b33
Show file tree
Hide file tree
Showing 38 changed files with 757 additions and 2 deletions.
16 changes: 15 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ minecraft {
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {

client {
workingDirectory project.file('run')

Expand All @@ -82,6 +83,8 @@ minecraft {
// "REGISTRYDUMP": For getting the contents of all registries.
property 'forge.logging.markers', 'REGISTRIES'

// property 'mixin.env.remapRefMap', 'true'
// property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg"

// Recommended logging level for the console
// You can set various levels here.
Expand All @@ -91,6 +94,8 @@ minecraft {
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', mod_id

arg '--mixin.config=mixins.mindustry.json'

mods {
"${mod_id}" {
source sourceSets.main
Expand All @@ -107,6 +112,8 @@ minecraft {

property 'forge.enabledGameTestNamespaces', mod_id

arg '--mixin.config=mixins.mindustry.json'

mods {
"${mod_id}" {
source sourceSets.main
Expand Down Expand Up @@ -155,6 +162,10 @@ minecraft {
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

mixin {
add sourceSets.main, "mixins.mindustry.refmap.json"
}

repositories {
// Put repositories for dependencies here
// ForgeGradle automatically adds the Forge maven and Maven Central for you
Expand Down Expand Up @@ -224,6 +235,8 @@ dependencies {

minecraftLibrary 'io.reactivex.rxjava3:rxjava:3.1.8'
jarJar(group: 'io.reactivex.rxjava3', name: 'rxjava', version: '[3.1.8,)')

annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
// annotationProcessor "curse.maven:kiwi-303657:${kiwi_fileId}"
// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
Expand Down Expand Up @@ -272,7 +285,8 @@ jar {
"Implementation-Title" : project.name,
"Implementation-Version" : project.jar.archiveVersion,
"Implementation-Vendor" : mod_authors,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"MixinConfigs": "mixins.mindustry.json"
])
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/hechu/mindustry/kiwi/MobEffectModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.hechu.mindustry.kiwi;

import com.hechu.mindustry.world.effect.*;
import net.minecraft.world.effect.MobEffect;
import snownee.kiwi.AbstractModule;
import snownee.kiwi.KiwiGO;
import snownee.kiwi.KiwiModule;

@KiwiModule(value = "mob_effect")
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> SAPPED = go(SappedMobEffect::create);
public static final KiwiGO<MobEffect> ELECTRIFIED = go(ElectrifiedMobEffect::create);
public static final KiwiGO<MobEffect> SPORE_SLOWED = go(SporeSlowedMobEffect::create);
public static final KiwiGO<MobEffect> TARRED = go(TarredMobEffect::create);
public static final KiwiGO<MobEffect> OVERDRIVE = go(OverdriveMobEffect::create);
public static final KiwiGO<MobEffect> OVERCLOCK = go(OverclockMobEffect::create);
public static final KiwiGO<MobEffect> BOSS = go(BossMobEffect::create);
public static final KiwiGO<MobEffect> SHOCKED = go(ShockedMobEffect::create);
public static final KiwiGO<MobEffect> BLASTED = go(BlastedMobEffect::create);
}
27 changes: 27 additions & 0 deletions src/main/java/com/hechu/mindustry/kiwi/PotionModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.hechu.mindustry.kiwi;

import com.hechu.mindustry.world.effect.*;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.item.alchemy.Potion;
import snownee.kiwi.AbstractModule;
import snownee.kiwi.KiwiGO;
import snownee.kiwi.KiwiModule;

@KiwiModule(value = "potion", dependencies = "mob_effect")
public class PotionModule extends AbstractModule {
public static final KiwiGO<Potion> BURNING = go(() -> new Potion(new MobEffectInstance(MobEffectModule.BURNING.get(),3600)));
public static final KiwiGO<Potion> FREEZING = go(() -> new Potion(new MobEffectInstance(MobEffectModule.FREEZING.get(),3600)));
public static final KiwiGO<Potion> UNMOVING = go(() -> new Potion(new MobEffectInstance(MobEffectModule.UNMOVING.get(),3600)));
public static final KiwiGO<Potion> WET = go(() -> new Potion(new MobEffectInstance(MobEffectModule.WET.get(),3600)));
public static final KiwiGO<Potion> MELTING = go(() -> new Potion(new MobEffectInstance(MobEffectModule.MELTING.get(),3600)));
public static final KiwiGO<Potion> SAPPED = go(() -> new Potion(new MobEffectInstance(MobEffectModule.SAPPED.get(),3600)));
public static final KiwiGO<Potion> ELECTRIFIED = go(() -> new Potion(new MobEffectInstance(MobEffectModule.ELECTRIFIED.get(),3600)));
public static final KiwiGO<Potion> SPORE_SLOWED = go(() -> new Potion(new MobEffectInstance(MobEffectModule.SPORE_SLOWED.get(),3600)));
public static final KiwiGO<Potion> TARRED = go(() -> new Potion(new MobEffectInstance(MobEffectModule.TARRED.get(),3600)));
public static final KiwiGO<Potion> OVERDRIVE = go(() -> new Potion(new MobEffectInstance(MobEffectModule.OVERDRIVE.get(),3600)));
public static final KiwiGO<Potion> OVERCLOCK = go(() -> new Potion(new MobEffectInstance(MobEffectModule.OVERCLOCK.get(),3600)));
public static final KiwiGO<Potion> BOSS = go(() -> new Potion(new MobEffectInstance(MobEffectModule.BOSS.get(),3600)));
public static final KiwiGO<Potion> SHOCKED = go(() -> new Potion(new MobEffectInstance(MobEffectModule.SHOCKED.get(),1)));
public static final KiwiGO<Potion> BLASTED = go(() -> new Potion(new MobEffectInstance(MobEffectModule.BLASTED.get(),1)));
}
95 changes: 95 additions & 0 deletions src/main/java/com/hechu/mindustry/mixin/MixinLivingEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.hechu.mindustry.mixin;

import com.hechu.mindustry.kiwi.MobEffectModule;
import com.hechu.mindustry.world.effect.*;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Attackable;
import net.minecraft.world.entity.Entity;
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;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import javax.annotation.Nullable;

@Mixin(LivingEntity.class)
public abstract class MixinLivingEntity extends Entity implements Attackable, net.minecraftforge.common.extensions.IForgeLivingEntity {
@Shadow
public abstract boolean hasEffect(MobEffect pEffect);

@Shadow
@Nullable
public abstract MobEffectInstance getEffect(MobEffect pEffect);

@Shadow
public abstract boolean removeEffect(MobEffect pEffect);

@Shadow
public abstract boolean addEffect(MobEffectInstance pEffectInstance);

public MixinLivingEntity(EntityType<?> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}

@Inject(method = "getDamageAfterMagicAbsorb", at = @At("RETURN"), cancellable = true)
protected void onGetDamageAfterMagicAbsorb(DamageSource damageSource, float damageAmount, CallbackInfoReturnable<Float> cir) {
float damage = cir.getReturnValue();
if (!damageSource.is(DamageTypeTags.BYPASSES_EFFECTS)) {
if (this.hasEffect(MobEffectModule.FREEZING.get())) {
MobEffectInstance effect = this.getEffect(MobEffectModule.FREEZING.get());
if (effect != null) {
damage /= (float) Math.pow(FreezingMobEffect.BASE_HEALTH_MULTIPLIER, effect.getAmplifier() + 1);
}
}
if (this.hasEffect(MobEffectModule.MELTING.get())) {
MobEffectInstance effect = this.getEffect(MobEffectModule.MELTING.get());
if (effect != null) {
damage /= (float) Math.pow(MeltingMobEffect.BASE_HEALTH_MULTIPLIER, effect.getAmplifier() + 1);
}
}
if (this.hasEffect(MobEffectModule.SAPPED.get())) {
MobEffectInstance effect = this.getEffect(MobEffectModule.SAPPED.get());
if (effect != null) {
damage /= (float) Math.pow(SappedMobEffect.BASE_HEALTH_MULTIPLIER, effect.getAmplifier() + 1);
}
}
if (this.hasEffect(MobEffectModule.OVERDRIVE.get())) {
MobEffectInstance effect = this.getEffect(MobEffectModule.OVERDRIVE.get());
if (effect != null) {
damage /= (float) Math.pow(OverdriveMobEffect.BASE_HEALTH_MULTIPLIER, effect.getAmplifier() + 1);
}
}
if (this.hasEffect(MobEffectModule.BOSS.get())) {
MobEffectInstance effect = this.getEffect(MobEffectModule.BOSS.get());
if (effect != null) {
damage /= (float) Math.pow(BossMobEffect.BASE_HEALTH_MULTIPLIER, effect.getAmplifier() + 1);
}
}
cir.setReturnValue(damage);
}
}

@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));
}
}
}
}
52 changes: 52 additions & 0 deletions src/main/java/com/hechu/mindustry/mixin/MixinPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.hechu.mindustry.mixin;

import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

public class MixinPlugin implements IMixinConfigPlugin {
private boolean isFrameworkInstalled;
@Override
public void onLoad(String mixinPackage) {
try {
//这个字符串对应你的项目主类
Class.forName("com.hechu.mindustry.Mindustry", false, this.getClass().getClassLoader());
isFrameworkInstalled = true;
} catch (Exception e) {
isFrameworkInstalled = false;
}
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return isFrameworkInstalled; // this makes sure that forge's helpful mods not found screen shows up
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.hechu.mindustry.world.effect;

import com.hechu.mindustry.kiwi.MobEffectModule;
import net.minecraft.world.effect.MobEffectCategory;

public class BlastedMobEffect extends MindustryInstantenousMobEffect {
protected BlastedMobEffect() {
super(MobEffectCategory.HARMFUL, 16742494);
}

public static BlastedMobEffect create() {
return (BlastedMobEffect) new BlastedMobEffect()
.reactive(MobEffectModule.FREEZING.get(), params -> {
float j = (float) (9.0F * Math.pow(2, params.amplifier));
params.livingEntity.hurt(params.livingEntity.damageSources().magic(), j);
});
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/hechu/mindustry/world/effect/BossMobEffect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.hechu.mindustry.world.effect;

import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;

public class BossMobEffect extends MobEffect {
protected BossMobEffect() {
super(MobEffectCategory.BENEFICIAL, 15750228);
}

public static BossMobEffect create() {
return (BossMobEffect) new BossMobEffect()
.addAttributeModifier(Attributes.ATTACK_DAMAGE, "125CA66E-C7B3-4E3C-8A60-80D974AFAEE6",
BASE_ATTACK_DAMAGE_MULTIPLIER - 1f, AttributeModifier.Operation.MULTIPLY_TOTAL);
}

public static final float BASE_ATTACK_DAMAGE_MULTIPLIER = 1.3f;
public static final float BASE_HEALTH_MULTIPLIER = 1.5f;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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 BurningMobEffect() {
super(MobEffectCategory.HARMFUL, 16761940);
}

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()));
}
}
});
}

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));

if (livingEntity.hasEffect(MobEffectModule.TARRED.get()))
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;
}
}
}
Loading

0 comments on commit 1b46b33

Please sign in to comment.