Skip to content

Commit

Permalink
更新 effectReg
Browse files Browse the repository at this point in the history
  • Loading branch information
MegumiKasuga committed Oct 2, 2024
1 parent f6a37e6 commit 04e434d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/main/java/kasuga/lib/registrations/common/EffectReg.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import net.minecraftforge.registries.RegistryObject;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Objects;
import java.util.function.Consumer;

/**
* This registration is used for poison effect registration. You could register your custom poison effect with it.
Expand All @@ -19,6 +21,7 @@ public class EffectReg<T extends MobEffect> extends Reg {
private MobEffectCategory category = MobEffectCategory.NEUTRAL;
private RegistryObject<T> registryObject = null;
private EffectBuilder<T> builder = null;
private ArrayList<Consumer<T>> arrributes;
private int color = 0xffffff;

/**
Expand All @@ -27,6 +30,7 @@ public class EffectReg<T extends MobEffect> extends Reg {
*/
public EffectReg(String registrationKey) {
super(registrationKey);
this.arrributes = new ArrayList<>();
}

/**
Expand Down Expand Up @@ -76,17 +80,32 @@ public EffectReg<T> color(int integerColor) {
return this;
}

/**
* Apply and Attributes for your effect.
* @param attributeModifier your attribute modifier lambda
* @return self.
*/
@Optional
public EffectReg<T> attritube(Consumer<T> attributeModifier) {
this.arrributes.add(attributeModifier);
return this;
}

/**
* Submit your config to forge and minecraft.
* @param registry the mod SimpleRegistry.
* @return self.
*/
@Override
public Reg submit(SimpleRegistry registry) {
public EffectReg<T> submit(SimpleRegistry registry) {
if (builder == null) {
crashOnNotPresent(EffectBuilder.class, "effectType", "submit");
}
registryObject = registry.mob_effect().register(registrationKey, () -> builder.build(category, color));
registryObject = registry.mob_effect().register(registrationKey, () -> {
T effect = builder.build(category, color);
this.arrributes.forEach(c -> c.accept(effect));
return effect;
});
return this;
}

Expand Down

0 comments on commit 04e434d

Please sign in to comment.