Skip to content

Commit

Permalink
add RegisterLayerDefinitionsEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Oct 4, 2024
1 parent 52bcd66 commit 22e4438
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.upcraft.sparkweave.api.client.event;

import dev.upcraft.sparkweave.api.event.Event;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.builders.LayerDefinition;

import java.util.function.Supplier;

public interface RegisterLayerDefinitionsEvent {

void registerModelLayers(ModelLayerLocation layerLocation, Supplier<LayerDefinition> supplier);

Event<RegisterLayerDefinitionsEvent.Callback> EVENT = Event.create(RegisterLayerDefinitionsEvent.Callback.class, callbacks -> event -> {
for (RegisterLayerDefinitionsEvent.Callback callback : callbacks) {
callback.registerModelLayers(event);
}
});

@FunctionalInterface
interface Callback {
void registerModelLayers(RegisterLayerDefinitionsEvent event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import dev.upcraft.sparkweave.client.event.RegisterItemPropertiesEventImpl;
import dev.upcraft.sparkweave.entrypoint.EntrypointHelper;
import dev.upcraft.sparkweave.fabric.client.command.ClientRootCommand;
import dev.upcraft.sparkweave.fabric.impl.registry.RegisterBlockEntityRenderersEventImpl;
import dev.upcraft.sparkweave.fabric.impl.registry.RegisterEntityRenderersEventImpl;
import dev.upcraft.sparkweave.fabric.impl.registry.RegisterMenuScreensEventImpl;
import dev.upcraft.sparkweave.fabric.impl.registry.RegisterParticleFactoriesEventImpl;
import dev.upcraft.sparkweave.fabric.impl.registry.*;
import dev.upcraft.sparkweave.validation.TranslationChecker;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -64,6 +61,7 @@ public Collection<ResourceLocation> getFabricDependencies() {

RegisterBlockEntityRenderersEvent.EVENT.invoker().registerBlockEntityRenderers(new RegisterBlockEntityRenderersEventImpl());
RegisterEntityRenderersEvent.EVENT.invoker().registerEntityRenderers(new RegisterEntityRenderersEventImpl());
RegisterLayerDefinitionsEvent.EVENT.invoker().registerModelLayers(new RegisterLayerDefinitionsEventImpl());
RegisterItemPropertiesEvent.EVENT.invoker().registerItemProperties(new RegisterItemPropertiesEventImpl());
RegisterMenuScreensEvent.EVENT.invoker().registerMenuScreens(new RegisterMenuScreensEventImpl());
RegisterParticleFactoriesEvent.EVENT.invoker().registerParticleFactories(new RegisterParticleFactoriesEventImpl());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.upcraft.sparkweave.fabric.impl.registry;

import dev.upcraft.sparkweave.api.client.event.RegisterLayerDefinitionsEvent;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.builders.LayerDefinition;

import java.util.function.Supplier;

public class RegisterLayerDefinitionsEventImpl implements RegisterLayerDefinitionsEvent {

@Override
public void registerModelLayers(ModelLayerLocation layerLocation, Supplier<LayerDefinition> supplier) {
EntityModelLayerRegistry.registerModelLayer(layerLocation, supplier::get);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public static void onRegisterParticles(RegisterParticleProvidersEvent event) {
RegisterParticleFactoriesEvent.EVENT.invoker().registerParticleFactories(new RegisterParticleFactoriesEventImpl(event));
}

@SubscribeEvent
public static void onRegisterLayerDefinitions(EntityRenderersEvent.RegisterLayerDefinitions event) {
RegisterLayerDefinitionsEvent.EVENT.invoker().registerModelLayers(event::registerLayerDefinition);
}

}

0 comments on commit 22e4438

Please sign in to comment.