Skip to content

Commit

Permalink
Generalize Particle Registration
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph T. McQuigg <[email protected]>
  • Loading branch information
JT122406 committed Dec 1, 2024
1 parent 437a246 commit c96eafd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 2.2.6
- Add Spanish (Chile) Translations (es_cl) (Credits: Ganbare-Lucifer)
- Generalize Particle Registration

# 2.2.5
- Make Pale Pumpkin Set Compostable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
import net.minecraft.client.model.ChestBoatModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.particle.ParticleProvider;
import net.minecraft.client.particle.SpriteSet;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.blockentity.*;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.EntityRenderers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.properties.WoodType;
import net.minecraft.world.level.levelgen.XoroshiroRandomSource;
import net.minecraft.world.level.levelgen.synth.ImprovedNoise;
import net.potionstudios.biomeswevegone.client.particle.BWGParticles;
import net.potionstudios.biomeswevegone.client.particle.particles.FallingLeafParticle;
import net.potionstudios.biomeswevegone.client.particle.particles.FireFlyParticle;
import net.potionstudios.biomeswevegone.client.renderer.BWGBoatRenderer;
import net.potionstudios.biomeswevegone.world.entity.BWGEntities;
import net.potionstudios.biomeswevegone.world.entity.boats.BWGBoatEntity;
Expand All @@ -28,6 +34,7 @@

import java.awt.*;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -88,6 +95,24 @@ public static void registerLayerDefinitions(BiConsumer<ModelLayerLocation, Suppl
}
}

/**
* Registers the Particle Providers for the mod.
* @see ParticleProvider
*/
public static void registerParticles(BiConsumer<SimpleParticleType, Function<SpriteSet, ParticleProvider<SimpleParticleType>>> consumer) {
consumer.accept(BWGParticles.FIREFLY.get(), FireFlyParticle.Provider::new);
consumer.accept(BWGParticles.BOREALIS_GLINT.get(), FallingLeafParticle.Provider::new);
consumer.accept(BWGParticles.WITCH_HAZEL_LEAVES.get(), FallingLeafParticle.Provider::new);
consumer.accept(BWGParticles.WHITE_SAKURA_LEAVES.get(), FallingLeafParticle.Provider::new);
consumer.accept(BWGParticles.YELLOW_SAKURA_LEAVES.get(), FallingLeafParticle.Provider::new);
consumer.accept(BWGParticles.RED_MAPLE_LEAVES.get(), FallingLeafParticle.Provider::new);
consumer.accept(BWGParticles.SILVER_MAPLE_LEAVES.get(), FallingLeafParticle.Provider::new);
consumer.accept(BWGParticles.IRONWOOD_LEAVES.get(), FallingLeafParticle.Provider::new);
consumer.accept(BWGParticles.SPIRIT.get(), FallingLeafParticle.Provider::new);
consumer.accept(BWGParticles.SPIRIT_LEAVES.get(), FallingLeafParticle.Provider::new);
}


private static final ImprovedNoise NOISE = new ImprovedNoise(new XoroshiroRandomSource(1));

public static int getBorealisIceColor(BlockPos pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
import net.minecraft.world.level.GrassColor;
import net.minecraft.world.level.block.*;
import net.potionstudios.biomeswevegone.client.BiomesWeveGoneClient;
import net.potionstudios.biomeswevegone.client.particle.BWGParticles;
import net.potionstudios.biomeswevegone.client.particle.particles.FallingLeafParticle;
import net.potionstudios.biomeswevegone.client.particle.particles.FireFlyParticle;
import net.potionstudios.biomeswevegone.world.level.block.BWGBlocks;
import net.potionstudios.biomeswevegone.world.level.block.custom.BWGSpreadableBlock;
import net.potionstudios.biomeswevegone.world.level.block.plants.cactus.BWGCactusBlock;
Expand All @@ -46,7 +43,7 @@ public void onInitializeClient() {
registerRenderTypes();
BiomesWeveGoneClient.registerEntityRenderers(EntityRendererRegistry::register);
BiomesWeveGoneClient.registerBlockEntityRenderers(BlockEntityRenderers::register);
registerParticles();
BiomesWeveGoneClient.registerParticles((type, spriteProviderFactory) -> ParticleFactoryRegistry.getInstance().register(type, spriteProviderFactory::apply));
BiomesWeveGoneClient.registerLayerDefinitions((a, b) -> EntityModelLayerRegistry.registerModelLayer(a, b::get));
registerColorChangingBlocks();
}
Expand All @@ -72,19 +69,6 @@ else if (block instanceof StainedGlassPaneBlock || block instanceof HalfTranspar
BlockRenderLayerMap.INSTANCE.putBlock(block, RenderType.translucent());
}

private void registerParticles() {
ParticleFactoryRegistry.getInstance().register(BWGParticles.FIREFLY.get(), FireFlyParticle.Provider::new);
ParticleFactoryRegistry.getInstance().register(BWGParticles.BOREALIS_GLINT.get(), FallingLeafParticle.Provider::new);
ParticleFactoryRegistry.getInstance().register(BWGParticles.WITCH_HAZEL_LEAVES.get(), FallingLeafParticle.Provider::new);
ParticleFactoryRegistry.getInstance().register(BWGParticles.WHITE_SAKURA_LEAVES.get(), FallingLeafParticle.Provider::new);
ParticleFactoryRegistry.getInstance().register(BWGParticles.YELLOW_SAKURA_LEAVES.get(), FallingLeafParticle.Provider::new);
ParticleFactoryRegistry.getInstance().register(BWGParticles.RED_MAPLE_LEAVES.get(), FallingLeafParticle.Provider::new);
ParticleFactoryRegistry.getInstance().register(BWGParticles.SILVER_MAPLE_LEAVES.get(), FallingLeafParticle.Provider::new);
ParticleFactoryRegistry.getInstance().register(BWGParticles.IRONWOOD_LEAVES.get(), FallingLeafParticle.Provider::new);
ParticleFactoryRegistry.getInstance().register(BWGParticles.SPIRIT.get(), FallingLeafParticle.Provider::new);
ParticleFactoryRegistry.getInstance().register(BWGParticles.SPIRIT_LEAVES.get(), FallingLeafParticle.Provider::new);
}

private void registerColorChangingBlocks() {
ColorProviderRegistry.BLOCK.register((state, view, pos, tintIndex) -> view != null && pos != null ? BiomeColors.getAverageGrassColor(view, pos) : GrassColor.getDefaultColor(), BWGBlocks.FLOWER_PATCH.get(), BWGBlocks.TINY_LILY_PADS.get(), BWGBlocks.FLOWERING_TINY_LILY_PADS.get(), BWGBlocks.OVERGROWN_DACITE.get(), BWGBlocks.OVERGROWN_STONE.get(), BWGBlocks.LUSH_GRASS_BLOCK.get(), BWGBlocks.WHITE_SAKURA_PETALS.get(), BWGBlocks.YELLOW_SAKURA_PETALS.get());
ColorProviderRegistry.BLOCK.register((state, view, pos, tintIndex) -> view != null && pos != null ? BiomeColors.getAverageFoliageColor(view, pos) : FoliageColor.get(0.5D, 1.0D), BWGBlocks.CLOVER_PATCH.get(), BWGBlocks.LEAF_PILE.get(), BWGBlocks.POISON_IVY.get(), BWGWood.MAHOGANY.leaves(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.potionstudios.biomeswevegone.client.BiomesWeveGoneClient;
import net.potionstudios.biomeswevegone.client.particle.BWGParticles;
import net.potionstudios.biomeswevegone.client.particle.particles.FallingLeafParticle;
import net.potionstudios.biomeswevegone.client.particle.particles.FireFlyParticle;
import net.potionstudios.biomeswevegone.world.level.block.BWGBlocks;
import net.potionstudios.biomeswevegone.world.level.block.wood.BWGWood;

Expand All @@ -43,7 +40,7 @@ public static void init(IEventBus eventBus) {
eventBus.addListener(BiomesWeveGoneClientForge::forgeClientSetup);
eventBus.addListener((Consumer<EntityRenderersEvent.RegisterRenderers>) event -> BiomesWeveGoneClient.registerEntityRenderers(event::registerEntityRenderer));
eventBus.addListener((Consumer<EntityRenderersEvent.RegisterRenderers>) event -> BiomesWeveGoneClient.registerBlockEntityRenderers(event::registerBlockEntityRenderer));
eventBus.addListener(BiomesWeveGoneClientForge::registerParticles);
eventBus.addListener((RegisterParticleProvidersEvent event) -> BiomesWeveGoneClient.registerParticles((type, spriteProviderFactory) -> event.registerSpriteSet(type, spriteProviderFactory::apply)));
eventBus.addListener((Consumer<EntityRenderersEvent.RegisterLayerDefinitions>) event -> BiomesWeveGoneClient.registerLayerDefinitions(event::registerLayerDefinition));
eventBus.addListener(BiomesWeveGoneClientForge::registerColorChangingBlocks);
eventBus.addListener(BiomesWeveGoneClientForge::registerItemColorHandlers);
Expand All @@ -58,24 +55,6 @@ private static void forgeClientSetup(final FMLClientSetupEvent event) {
BiomesWeveGoneClient.onInitialize(Minecraft.getInstance());
}

/**
* Registers the custom particles for the mod.
* @param event The event to register the particles to.
* @see RegisterParticleProvidersEvent
*/
private static void registerParticles(final RegisterParticleProvidersEvent event) {
event.registerSpriteSet(BWGParticles.FIREFLY.get(), FireFlyParticle.Provider::new);
event.registerSpriteSet(BWGParticles.BOREALIS_GLINT.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.WITCH_HAZEL_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.WHITE_SAKURA_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.YELLOW_SAKURA_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.RED_MAPLE_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.SILVER_MAPLE_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.IRONWOOD_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.SPIRIT.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.SPIRIT_LEAVES.get(), FallingLeafParticle.Provider::new);
}

/**
* Registers the blocks that change color based on the biome.
* @param event The event to register the blocks to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import net.neoforged.neoforge.client.gui.VanillaGuiLayers;
import net.potionstudios.biomeswevegone.BiomesWeveGone;
import net.potionstudios.biomeswevegone.client.BiomesWeveGoneClient;
import net.potionstudios.biomeswevegone.client.particle.BWGParticles;
import net.potionstudios.biomeswevegone.client.particle.particles.FallingLeafParticle;
import net.potionstudios.biomeswevegone.client.particle.particles.FireFlyParticle;
import net.potionstudios.biomeswevegone.world.level.block.BWGBlocks;
import net.potionstudios.biomeswevegone.world.level.block.wood.BWGWood;

Expand Down Expand Up @@ -55,7 +52,7 @@ public static void init(IEventBus eventBus) {
eventBus.addListener(BiomesWeveGoneClientNeoForge::neoForgeClientSetup);
eventBus.addListener((Consumer<EntityRenderersEvent.RegisterRenderers>) event -> BiomesWeveGoneClient.registerEntityRenderers(event::registerEntityRenderer));
eventBus.addListener((Consumer<EntityRenderersEvent.RegisterRenderers>) event -> BiomesWeveGoneClient.registerBlockEntityRenderers(event::registerBlockEntityRenderer));
eventBus.addListener(BiomesWeveGoneClientNeoForge::registerParticles);
eventBus.addListener((RegisterParticleProvidersEvent event) -> BiomesWeveGoneClient.registerParticles((type, spriteProviderFactory) -> event.registerSpriteSet(type, spriteProviderFactory::apply)));
eventBus.addListener((Consumer<EntityRenderersEvent.RegisterLayerDefinitions>) event -> BiomesWeveGoneClient.registerLayerDefinitions(event::registerLayerDefinition));
eventBus.addListener(BiomesWeveGoneClientNeoForge::registerColorChangingBlocks);
eventBus.addListener(BiomesWeveGoneClientNeoForge::registerItemColorHandlers);
Expand All @@ -71,25 +68,6 @@ private static void neoForgeClientSetup(final FMLClientSetupEvent event) {
BiomesWeveGoneClient.onInitialize(Minecraft.getInstance());
}

/**
* Registers the custom particles for the mod.
* @param event The event to register the particles to.
* @see RegisterParticleProvidersEvent
*/
private static void registerParticles(final RegisterParticleProvidersEvent event) {
event.registerSpriteSet(BWGParticles.FIREFLY.get(), FireFlyParticle.Provider::new);
event.registerSpriteSet(BWGParticles.BOREALIS_GLINT.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.WITCH_HAZEL_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.WHITE_SAKURA_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.YELLOW_SAKURA_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.RED_MAPLE_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.SILVER_MAPLE_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.IRONWOOD_LEAVES.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.SPIRIT.get(), FallingLeafParticle.Provider::new);
event.registerSpriteSet(BWGParticles.SPIRIT_LEAVES.get(), FallingLeafParticle.Provider::new);

}

/**
* Registers the blocks that change color based on the biome.
* @param event The event to register the blocks to.
Expand Down

0 comments on commit c96eafd

Please sign in to comment.