mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
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:
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);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,12 @@ import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
*
|
||||
* @see ModelProvider
|
||||
* @see ModelBuilder
|
||||
*
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public class BlockModelBuilder extends ModelBuilder<BlockModelBuilder>
|
||||
{
|
||||
public BlockModelBuilder(ResourceLocation outputLocation, ExistingFileHelper existingFileHelper)
|
||||
|
||||
@@ -12,7 +12,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* Stub class to extend for block model data providers, eliminates some
|
||||
* boilerplate constructor parameters.
|
||||
*
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public abstract class BlockModelProvider extends ModelProvider<BlockModelBuilder> {
|
||||
|
||||
public BlockModelProvider(PackOutput output, String modid, ExistingFileHelper existingFileHelper) {
|
||||
|
||||
@@ -63,10 +63,17 @@ import org.jetbrains.annotations.VisibleForTesting;
|
||||
/**
|
||||
* Data provider for blockstate files. Extends {@link BlockModelProvider} so that
|
||||
* blockstates and their referenced models can be provided in tandem.
|
||||
*
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public abstract class BlockStateProvider implements DataProvider {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
@SuppressWarnings("unused")
|
||||
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -28,7 +28,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
* Can be manually constructed, created by static factory such as
|
||||
* {@link #allYRotations(ModelFile, int, boolean)}, or created by builder via
|
||||
* {@link #builder()}.
|
||||
*
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public final class ConfiguredModel {
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,16 @@ import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
*
|
||||
* This is the only class that doesn't seem to have a vanilla alternative however, it should be a simple helper
|
||||
* function to replace this functionality for your custom models
|
||||
*
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public abstract class CustomLoaderBuilder<T extends ModelBuilder<T>>
|
||||
{
|
||||
protected final ResourceLocation loaderId;
|
||||
|
||||
@@ -8,6 +8,12 @@ package net.minecraftforge.client.model.generators;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.jetbrains.annotations.VisibleForTesting;
|
||||
|
||||
/**
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
@VisibleForTesting
|
||||
public interface IGeneratedBlockState
|
||||
{
|
||||
|
||||
@@ -20,7 +20,12 @@ import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
/**
|
||||
* Builder for item models, adds the ability to build overrides via
|
||||
* {@link #override()}.
|
||||
*
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public class ItemModelBuilder extends ModelBuilder<ItemModelBuilder> {
|
||||
|
||||
protected List<OverrideBuilder> overrides = new ArrayList<>();
|
||||
@@ -37,7 +42,7 @@ public class ItemModelBuilder extends ModelBuilder<ItemModelBuilder> {
|
||||
|
||||
/**
|
||||
* Get an existing override builder
|
||||
*
|
||||
*
|
||||
* @param index the index of the existing override builder
|
||||
* @return the override builder
|
||||
* @throws IndexOutOfBoundsException if {@code} index is out of bounds
|
||||
|
||||
@@ -17,7 +17,12 @@ import java.util.Objects;
|
||||
/**
|
||||
* Stub class to extend for item model data providers, eliminates some
|
||||
* boilerplate constructor parameters.
|
||||
*
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public abstract class ItemModelProvider extends ModelProvider<ItemModelBuilder> {
|
||||
|
||||
public ItemModelProvider(PackOutput output, String modid, ExistingFileHelper existingFileHelper) {
|
||||
|
||||
@@ -50,7 +50,12 @@ import org.joml.Vector3f;
|
||||
* @see ItemModelBuilder
|
||||
*
|
||||
* @param <T> Self type, for simpler chaining of methods.
|
||||
*
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -10,6 +10,12 @@ import com.google.common.base.Preconditions;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
/**
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public abstract class ModelFile {
|
||||
|
||||
protected ResourceLocation location;
|
||||
|
||||
@@ -21,6 +21,12 @@ import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper.ResourceType;
|
||||
import org.jetbrains.annotations.VisibleForTesting;
|
||||
|
||||
/**
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataProvider {
|
||||
|
||||
public static final String BLOCK_FOLDER = "block";
|
||||
|
||||
+6
@@ -21,6 +21,12 @@ import com.google.gson.JsonObject;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
|
||||
/**
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public final class MultiPartBlockStateBuilder implements IGeneratedBlockState {
|
||||
private final List<PartBuilder> parts = new ArrayList<>();
|
||||
private final Block owner;
|
||||
|
||||
@@ -50,7 +50,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
* values.
|
||||
*
|
||||
* @see BlockStateProvider
|
||||
*
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
@Deprecated(since = "1.21.4", forRemoval = true)
|
||||
public class VariantBlockStateBuilder implements IGeneratedBlockState
|
||||
{
|
||||
|
||||
@@ -284,6 +289,7 @@ public class VariantBlockStateBuilder implements IGeneratedBlockState
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
|
||||
+5
@@ -15,6 +15,11 @@ import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
public class CompositeModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "composite");
|
||||
|
||||
+5
@@ -14,6 +14,11 @@ import net.minecraftforge.client.model.generators.ModelBuilder;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
/**
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
public class DynamicFluidContainerModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "fluid_container");
|
||||
|
||||
+5
@@ -24,6 +24,11 @@ import net.minecraftforge.client.model.generators.CustomLoaderBuilder;
|
||||
import net.minecraftforge.client.model.generators.ModelBuilder;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
/**
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
public class ItemLayerModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "item_layers");
|
||||
|
||||
@@ -13,6 +13,11 @@ import net.minecraftforge.client.model.generators.CustomLoaderBuilder;
|
||||
import net.minecraftforge.client.model.generators.ModelBuilder;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
/**
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
public class ObjModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "obj");
|
||||
|
||||
+5
-1
@@ -7,7 +7,6 @@ package net.minecraftforge.client.model.generators.loaders;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraftforge.client.model.generators.CustomLoaderBuilder;
|
||||
@@ -17,6 +16,11 @@ import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* In 1.21.4 Mojang exposed their data generators for their models. So it should be feasible to just use theirs.
|
||||
* If you find something lacking feel free to open a PR so that we can extend it.
|
||||
* @deprecated Use Vanilla's providers {@link net.minecraft.client.data.models.ModelProvider}
|
||||
*/
|
||||
public class SeparateTransformsModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "separate_transforms");
|
||||
|
||||
@@ -35,7 +35,7 @@ public class BakedModelRenderable implements IRenderable<BakedModelRenderable.Co
|
||||
* Constructs a {@link BakedModelRenderable} from the given model location.
|
||||
* The model is expected to have been baked ahead of time.
|
||||
*
|
||||
* @see net.minecraftforge.client.event.ModelEvent.RegisterAdditional
|
||||
* @see net.minecraftforge.client.event.ModelEvent.RegisterModelStateDefinitions
|
||||
*/
|
||||
public static BakedModelRenderable of(ModelResourceLocation model) {
|
||||
return of(Minecraft.getInstance().getModelManager().getModel(model));
|
||||
|
||||
Reference in new issue
Block a user