mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Merge branch '1.18.2' into 1.19
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
|
||||
package dev.architectury.registry.client.particle;
|
||||
|
||||
import dev.architectury.event.events.client.ClientLifecycleEvent;
|
||||
import dev.architectury.injectables.annotations.ExpectPlatform;
|
||||
import dev.architectury.registry.registries.RegistrySupplier;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.particle.ParticleProvider;
|
||||
@@ -31,6 +33,17 @@ import net.minecraft.core.particles.ParticleType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A utility class for registering custom {@link ParticleProvider}s for particle types.
|
||||
* <p>
|
||||
* This class's methods should be invoked <b>before</b> {@link ClientLifecycleEvent#CLIENT_SETUP},
|
||||
* as doing so afterwards will result in the providers not being registered properly on Forge, causing crashes on startup.
|
||||
* <p>
|
||||
* Generally speaking, you should either listen to the registration of your particle type yourself and use either
|
||||
* {@link #register(ParticleType, ParticleProvider)} or {@link #register(ParticleType, DeferredParticleProvider)} to register the provider,
|
||||
* or use the helper methods {@link #register(RegistrySupplier, ParticleProvider)} and {@link #register(RegistrySupplier, DeferredParticleProvider)},
|
||||
* which will automatically handle the listening for you.
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class ParticleProviderRegistry {
|
||||
public interface ExtendedSpriteSet extends SpriteSet {
|
||||
@@ -39,6 +52,14 @@ public final class ParticleProviderRegistry {
|
||||
List<TextureAtlasSprite> getSprites();
|
||||
}
|
||||
|
||||
public static <T extends ParticleOptions> void register(RegistrySupplier<? extends ParticleType<T>> supplier, ParticleProvider<T> provider) {
|
||||
supplier.listen(it -> register(it, provider));
|
||||
}
|
||||
|
||||
public static <T extends ParticleOptions> void register(RegistrySupplier<? extends ParticleType<T>> supplier, DeferredParticleProvider<T> provider) {
|
||||
supplier.listen(it -> register(it, provider));
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static <T extends ParticleOptions> void register(ParticleType<T> type, ParticleProvider<T> provider) {
|
||||
throw new AssertionError();
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"depends": {
|
||||
"minecraft": "~1.19-",
|
||||
"fabricloader": ">=0.13.0",
|
||||
"fabric": ">=0.50.0"
|
||||
"fabric": ">=0.54.0"
|
||||
},
|
||||
"breaks": {
|
||||
"optifabric": "<1.13.0"
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package dev.architectury.registry.client.particle.forge;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import dev.architectury.forge.ArchitecturyForge;
|
||||
import dev.architectury.registry.client.particle.ParticleProviderRegistry;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -34,13 +35,17 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RegisterParticleProvidersEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = ArchitecturyForge.MOD_ID, value = Dist.CLIENT)
|
||||
@Mod.EventBusSubscriber(modid = ArchitecturyForge.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class ParticleProviderRegistryImpl {
|
||||
|
||||
public static final Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
private static final class ExtendedSpriteSetImpl implements ParticleProviderRegistry.ExtendedSpriteSet {
|
||||
private final ParticleEngine engine;
|
||||
private final SpriteSet delegate;
|
||||
@@ -73,28 +78,30 @@ public class ParticleProviderRegistryImpl {
|
||||
|
||||
private static List<Consumer<ParticleProviderRegistrar>> deferred = new ArrayList<>();
|
||||
|
||||
private static <T extends ParticleOptions> void _register(ParticleProviderRegistrar registrar, ParticleType<T> type, ParticleProvider<T> provider) {
|
||||
private static <T extends ParticleOptions> void doRegister(ParticleProviderRegistrar registrar, ParticleType<T> type, ParticleProvider<T> provider) {
|
||||
registrar.register(type, provider);
|
||||
}
|
||||
|
||||
private static <T extends ParticleOptions> void _register(ParticleProviderRegistrar registrar, ParticleType<T> type, ParticleProviderRegistry.DeferredParticleProvider<T> provider) {
|
||||
private static <T extends ParticleOptions> void doRegister(ParticleProviderRegistrar registrar, ParticleType<T> type, ParticleProviderRegistry.DeferredParticleProvider<T> provider) {
|
||||
registrar.register(type, sprites ->
|
||||
provider.create(new ExtendedSpriteSetImpl(Minecraft.getInstance().particleEngine, sprites)));
|
||||
}
|
||||
|
||||
public static <T extends ParticleOptions> void register(ParticleType<T> type, ParticleProvider<T> provider) {
|
||||
if (deferred == null) {
|
||||
_register(ParticleProviderRegistrar.ofFallback(), type, provider);
|
||||
LOGGER.warn("Something is attempting to register particle providers at a later point than intended! This might cause issues!", new Throwable());
|
||||
doRegister(ParticleProviderRegistrar.ofFallback(), type, provider);
|
||||
} else {
|
||||
deferred.add(registrar -> _register(registrar, type, provider));
|
||||
deferred.add(registrar -> doRegister(registrar, type, provider));
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends ParticleOptions> void register(ParticleType<T> type, ParticleProviderRegistry.DeferredParticleProvider<T> provider) {
|
||||
if (deferred == null) {
|
||||
_register(ParticleProviderRegistrar.ofFallback(), type, provider);
|
||||
LOGGER.warn("Something is attempting to register particle providers at a later point than intended! This might cause issues!", new Throwable());
|
||||
doRegister(ParticleProviderRegistrar.ofFallback(), type, provider);
|
||||
} else {
|
||||
deferred.add(registrar -> _register(registrar, type, provider));
|
||||
deferred.add(registrar -> doRegister(registrar, type, provider));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,7 @@ public class TestParticles {
|
||||
public static void initialize() {
|
||||
PARTICLE_TYPES.register();
|
||||
if (Platform.getEnvironment() == Env.CLIENT) {
|
||||
ClientLifecycleEvent.CLIENT_SETUP.register(instance -> {
|
||||
ParticleProviderRegistry.register(TEST_PARTICLE.get(), HeartParticle.Provider::new);
|
||||
});
|
||||
ParticleProviderRegistry.register(TEST_PARTICLE, HeartParticle.Provider::new);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user