Add hooks for using Vanilla's new Client data generator (#10206)

Add new hook for custom block models that do not have real blocks backing them
Some workspace cleanup fixing log4j annotation processor
This commit is contained in:
LexManos authored and GitHub committed 2024-12-19 10:41:21 -08:00
1 parent 07977ba242
commit 0e74886f8d
55 files changed
+1346 -75

No files matched your search

@@ -94,14 +94,14 @@ public final class ForgeEventFactoryClient {
/**
* Post an event to the {@link ModLoader#get()} event bus
*/
private static <T extends Event & IModBusEvent> T postModBus(T e) {
private static <T extends Event & IModBusEvent> T fireModBus(T e) {
ML.postEvent(e);
return e;
}
public static void onGatherLayers(Map<EntityType<?>, EntityRenderer<?, ?>> renderers, Map<Model, EntityRenderer<? extends Player, ?>> playerRenderers, Context context) {
// TODO: Why is this a ModLoader event...
postModBus(new EntityRenderersEvent.AddLayers(renderers, playerRenderers, context));
fireModBus(new EntityRenderersEvent.AddLayers(renderers, playerRenderers, context));
}
public static boolean onScreenMouseReleased(Screen screen, double mouseX, double mouseY, int button) {
@@ -295,7 +295,12 @@ public final class ForgeEventFactoryClient {
public static Map<Type, Function<EntityModelSet, SkullModelBase>> onCreateSkullModels() {
var builder = ImmutableMap.<Type, Function<EntityModelSet, SkullModelBase>>builder();
postModBus(new EntityRenderersEvent.CreateSkullModels(builder));
fireModBus(new EntityRenderersEvent.CreateSkullModels(builder));
return builder.build();
}
public static ModelEvent.RegisterModelStateDefinitions onRegisterModeStateDefinitions() {
// This is on the mod bus because it happens during the initial texture reload, which is while the Forge bus is shut down.
return fireModBus(new ModelEvent.RegisterModelStateDefinitions());
}
}
@@ -6,11 +6,12 @@
package net.minecraftforge.client.event;
import com.google.common.base.Preconditions;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraftforge.client.model.geometry.IGeometryLoader;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
@@ -20,6 +21,8 @@ import net.minecraftforge.fml.event.IModBusEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.jetbrains.annotations.ApiStatus;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
@@ -106,6 +109,37 @@ public abstract class ModelEvent extends Event {
}
}
/**
* Fired when the {@link net.minecraft.client.resources.model.BlockStateModelLoader BlockStateModelLoader} is notified of the resource manager reloading.
* Allows developers to register {@link net.minecraft.world.level.block.state.StateDefinition StateDefinitons} for blocks that are not in the normal Block registry.
* This is designed to allow for extra models to be loaded in connection with a blockstates json file. This is not intended to allow
* overriding or modification of StateDefinitions from registered Blocks
*
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
*/
public static class RegisterModelStateDefinitions extends ModelEvent implements IModBusEvent {
private final Map<ResourceLocation, StateDefinition<Block, BlockState>> states = new HashMap<>();
private final Map<ResourceLocation, StateDefinition<Block, BlockState>> view = Collections.unmodifiableMap(states);
@ApiStatus.Internal
public RegisterModelStateDefinitions() { }
/**
* Returns a read only view of the extra registered models
*/
public Map<ResourceLocation, StateDefinition<Block, BlockState>> getStates() {
return this.view;
}
/**
* Registers a StateDefinition for a synthetic block.
*/
public void register(ResourceLocation key, StateDefinition<Block, BlockState> value) {
states.put(key, value);
}
}
/**
* Allows users to register their own {@link IGeometryLoader geometry loaders} for use in block/item models.
*
@@ -126,7 +160,9 @@ public abstract class ModelEvent extends Event {
* Registers a new geometry loader.
*/
public void register(String name, IGeometryLoader<?> loader) {
var key = ResourceLocation.fromNamespaceAndPath(ModLoadingContext.get().getActiveNamespace(), name);
@SuppressWarnings("removal")
var namespace = ModLoadingContext.get().getActiveNamespace();
var key = ResourceLocation.fromNamespaceAndPath(namespace, name);
Preconditions.checkArgument(!loaders.containsKey(key), "Geometry loader already registered: " + key);
loaders.put(key, loader);
}