Updated ParticleType API

This commit is contained in:
Frank 2022-06-08 11:57:48 +02:00
parent 73b20f88c5
commit 8227cf2f6a

View file

@ -1,14 +1,48 @@
package org.betterx.bclib.particles;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.resources.ResourceLocation;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import com.mojang.serialization.Codec;
public class BCLParticleType {
public static SimpleParticleType simple(boolean alwaysSpawn) {
return new SimpleParticleType(alwaysSpawn) {
public static <T extends ParticleOptions> ParticleType<T> deserializer(ParticleOptions.Deserializer<T> factory,
Codec<T> codec) {
return deserializer(false, factory, codec);
}
public static <T extends ParticleOptions> ParticleType<T> deserializer(boolean overrideLimiter,
ParticleOptions.Deserializer<T> factory,
Codec<T> codec) {
return new ParticleType<T>(overrideLimiter, factory) {
@Override
public Codec<T> codec() {
return codec;
}
};
}
public static <T extends ParticleOptions> ParticleType<T> register(ResourceLocation location,
ParticleOptions.Deserializer<T> factory,
Codec<T> codec) {
return register(location, false, factory, codec);
}
public static <T extends ParticleOptions> ParticleType<T> register(ResourceLocation location,
boolean overrideLimiter,
ParticleOptions.Deserializer<T> factory,
Codec<T> codec) {
return Registry.register(Registry.PARTICLE_TYPE, location, deserializer(overrideLimiter, factory, codec));
}
public static SimpleParticleType simple(boolean overrideLimiter) {
return new SimpleParticleType(overrideLimiter) {
};
}
@ -16,23 +50,23 @@ public class BCLParticleType {
return simple(false);
}
public static SimpleParticleType registerSimple(ResourceLocation location) {
return registerSimple(location, false);
public static SimpleParticleType register(ResourceLocation location) {
return register(location, false);
}
public static SimpleParticleType registerSimple(ResourceLocation location, boolean alwaysSpawn) {
return Registry.register(Registry.PARTICLE_TYPE, location, simple(alwaysSpawn));
public static SimpleParticleType register(ResourceLocation location, boolean overrideLimiter) {
return Registry.register(Registry.PARTICLE_TYPE, location, simple(overrideLimiter));
}
public static SimpleParticleType registerSimple(ResourceLocation location,
ParticleFactoryRegistry.PendingParticleFactory<SimpleParticleType> provider) {
return registerSimple(location, false, provider);
public static SimpleParticleType register(ResourceLocation location,
ParticleFactoryRegistry.PendingParticleFactory<SimpleParticleType> provider) {
return register(location, false, provider);
}
public static SimpleParticleType registerSimple(ResourceLocation location,
boolean alwaysSpawn,
ParticleFactoryRegistry.PendingParticleFactory<SimpleParticleType> provider) {
SimpleParticleType type = Registry.register(Registry.PARTICLE_TYPE, location, simple(alwaysSpawn));
public static SimpleParticleType register(ResourceLocation location,
boolean overrideLimiter,
ParticleFactoryRegistry.PendingParticleFactory<SimpleParticleType> provider) {
SimpleParticleType type = Registry.register(Registry.PARTICLE_TYPE, location, simple(overrideLimiter));
ParticleFactoryRegistry.getInstance().register(type, provider);
return type;
}