2019-12-05 23:42:01 +01:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
import com.simibubi.create.foundation.utility.Lang;
|
2020-01-20 13:41:41 +01:00
|
|
|
import com.simibubi.create.modules.contraptions.particle.AirFlowParticleData;
|
|
|
|
import com.simibubi.create.modules.contraptions.particle.ICustomParticle;
|
|
|
|
import com.simibubi.create.modules.contraptions.particle.RotationIndicatorParticleData;
|
2019-12-05 23:42:01 +01:00
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.particle.ParticleManager;
|
|
|
|
import net.minecraft.particles.IParticleData;
|
|
|
|
import net.minecraft.particles.ParticleType;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2020-01-20 13:41:41 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2019-12-05 23:42:01 +01:00
|
|
|
import net.minecraftforge.client.event.ParticleFactoryRegisterEvent;
|
|
|
|
import net.minecraftforge.event.RegistryEvent;
|
|
|
|
import net.minecraftforge.registries.IForgeRegistry;
|
|
|
|
|
|
|
|
public enum AllParticles {
|
|
|
|
|
2020-01-20 13:41:41 +01:00
|
|
|
ROTATION_INDICATOR(RotationIndicatorParticleData::new),
|
|
|
|
AIR_FLOW(AirFlowParticleData::new),
|
2019-12-05 23:42:01 +01:00
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
private ParticleEntry<?> entry;
|
|
|
|
|
2020-01-20 13:41:41 +01:00
|
|
|
private <D extends IParticleData> AllParticles(Supplier<? extends ICustomParticle<D>> typeFactory) {
|
2019-12-05 23:42:01 +01:00
|
|
|
String asId = Lang.asId(this.name().toLowerCase());
|
2020-01-20 13:41:41 +01:00
|
|
|
entry = new ParticleEntry<D>(new ResourceLocation(Create.ID, asId), typeFactory);
|
2019-12-05 23:42:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void register(RegistryEvent.Register<ParticleType<?>> event) {
|
|
|
|
for (AllParticles particle : values())
|
|
|
|
particle.entry.register(event.getRegistry());
|
|
|
|
}
|
|
|
|
|
2020-01-20 13:41:41 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-12-05 23:42:01 +01:00
|
|
|
public static void registerFactories(ParticleFactoryRegisterEvent event) {
|
|
|
|
ParticleManager particles = Minecraft.getInstance().particles;
|
2020-01-20 13:41:41 +01:00
|
|
|
for (AllParticles particle : values())
|
2019-12-05 23:42:01 +01:00
|
|
|
particle.entry.registerFactory(particles);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ParticleType<?> get() {
|
|
|
|
return entry.getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String parameter() {
|
|
|
|
return Lang.asId(name());
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ParticleEntry<D extends IParticleData> {
|
2020-01-20 13:41:41 +01:00
|
|
|
Supplier<? extends ICustomParticle<D>> typeFactory;
|
2019-12-05 23:42:01 +01:00
|
|
|
ParticleType<D> type;
|
|
|
|
ResourceLocation id;
|
|
|
|
|
2020-01-20 13:41:41 +01:00
|
|
|
public ParticleEntry(ResourceLocation id, Supplier<? extends ICustomParticle<D>> typeFactory) {
|
2019-12-05 23:42:01 +01:00
|
|
|
this.id = id;
|
|
|
|
this.typeFactory = typeFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParticleType<?> getType() {
|
|
|
|
makeType();
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void register(IForgeRegistry<ParticleType<?>> registry) {
|
|
|
|
makeType();
|
|
|
|
registry.register(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void makeType() {
|
|
|
|
if (type == null) {
|
2020-01-20 13:41:41 +01:00
|
|
|
type = typeFactory.get().createType();
|
2019-12-05 23:42:01 +01:00
|
|
|
type.setRegistryName(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-20 13:41:41 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-12-05 23:42:01 +01:00
|
|
|
void registerFactory(ParticleManager particles) {
|
|
|
|
makeType();
|
2020-01-20 13:41:41 +01:00
|
|
|
particles.registerFactory(type, typeFactory.get().getFactory());
|
2019-12-05 23:42:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|