mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 19:59:42 +00:00
1.21 Update
Co-authored-by: RealMangoRage <[email protected]> Co-authored-by: Daniel Norris <[email protected]> Co-authored-by: Ven <[email protected]>
This commit is contained in:
941 files changed
+3119
-4266
No files matched your search
@@ -68,7 +68,7 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
Material particleLocation = context.getMaterial("particle");
|
||||
TextureAtlasSprite particle = spriteGetter.apply(particleLocation);
|
||||
@@ -84,7 +84,7 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
if (!context.isComponentVisible(name, true))
|
||||
continue;
|
||||
var model = entry.getValue();
|
||||
bakedPartsBuilder.put(name, model.bake(baker, model, spriteGetter, modelState, modelLocation, true));
|
||||
bakedPartsBuilder.put(name, model.bake(baker, model, spriteGetter, modelState, true));
|
||||
}
|
||||
var bakedParts = bakedPartsBuilder.build();
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ import org.joml.Vector3f;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static net.minecraftforge.client.model.geometry.StandaloneGeometryBakingContext.LOCATION;
|
||||
|
||||
/**
|
||||
* A dynamic fluid container model, capable of re-texturing itself at runtime to match the contained fluid.
|
||||
* <p>
|
||||
@@ -88,7 +90,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
Material particleLocation = context.hasMaterial("particle") ? context.getMaterial("particle") : null;
|
||||
Material baseLocation = context.hasMaterial("base") ? context.getMaterial("base") : null;
|
||||
@@ -114,7 +116,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
}
|
||||
|
||||
// We need to disable GUI 3D and block lighting for this to render properly
|
||||
var itemContext = StandaloneGeometryBakingContext.builder(context).withGui3d(false).withUseBlockLight(false).build(modelLocation);
|
||||
var itemContext = StandaloneGeometryBakingContext.builder(context).withGui3d(false).withUseBlockLight(false).build(LOCATION);
|
||||
var modelBuilder = CompositeModel.Baked.builder(itemContext, particleSprite, new ContainedFluidOverrideHandler(overrides, baker, itemContext, this), context.getTransforms());
|
||||
|
||||
var normalRenderTypes = getLayerRenderTypes(false);
|
||||
@@ -123,7 +125,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
{
|
||||
// Base texture
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemElements(0, baseSprite.contents());
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> baseSprite, modelState, modelLocation);
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> baseSprite, modelState);
|
||||
modelBuilder.addQuads(normalRenderTypes, quads);
|
||||
}
|
||||
|
||||
@@ -135,7 +137,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
// Fluid layer
|
||||
var transformedState = new SimpleModelState(modelState.getRotation().compose(FLUID_TRANSFORM), modelState.isUvLocked());
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemMaskElements(1, templateSprite.contents()); // Use template as mask
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> fluidSprite, transformedState, modelLocation); // Bake with fluid texture
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> fluidSprite, transformedState); // Bake with fluid texture
|
||||
|
||||
var emissive = applyFluidLuminosity && fluid.getFluidType().getLightLevel() > 0;
|
||||
var renderTypes = getLayerRenderTypes(emissive);
|
||||
@@ -153,7 +155,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
// Cover/overlay
|
||||
var transformedState = new SimpleModelState(modelState.getRotation().compose(COVER_TRANSFORM), modelState.isUvLocked());
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemMaskElements(2, coverSprite.contents()); // Use cover as mask
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> sprite, transformedState, modelLocation); // Bake with selected texture
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> sprite, transformedState); // Bake with selected texture
|
||||
modelBuilder.addQuads(normalRenderTypes, quads);
|
||||
}
|
||||
}
|
||||
@@ -177,7 +179,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
if (!jsonObject.has("fluid"))
|
||||
throw new RuntimeException("Bucket model requires 'fluid' value.");
|
||||
|
||||
ResourceLocation fluidName = new ResourceLocation(jsonObject.get("fluid").getAsString());
|
||||
ResourceLocation fluidName = ResourceLocation.parse(jsonObject.get("fluid").getAsString());
|
||||
|
||||
Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidName);
|
||||
|
||||
@@ -219,7 +221,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
if (!cache.containsKey(name))
|
||||
{
|
||||
DynamicFluidContainerModel unbaked = this.parent.withFluid(fluid);
|
||||
BakedModel bakedModel = unbaked.bake(owner, baker, Material::sprite, BlockModelRotation.X0_Y0, this, new ResourceLocation("forge:bucket_override"));
|
||||
BakedModel bakedModel = unbaked.bake(owner, baker, Material::sprite, BlockModelRotation.X0_Y0, originalModel.getOverrides());
|
||||
cache.put(name, bakedModel);
|
||||
return bakedModel;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ElementsModel extends SimpleUnbakedGeometry<ElementsModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addQuads(IGeometryBakingContext context, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ResourceLocation modelLocation)
|
||||
protected void addQuads(IGeometryBakingContext context, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState)
|
||||
{
|
||||
// If there is a root transform, undo the ModelState transform, apply it, then re-apply the ModelState transform.
|
||||
// This is necessary because of things like UV locking, which should only respond to the ModelState, and as such
|
||||
@@ -54,14 +54,14 @@ public class ElementsModel extends SimpleUnbakedGeometry<ElementsModel>
|
||||
for (Direction direction : element.faces.keySet())
|
||||
{
|
||||
var face = element.faces.get(direction);
|
||||
var sprite = spriteGetter.apply(context.getMaterial(face.texture));
|
||||
var quad = BlockModel.bakeFace(element, face, sprite, direction, modelState, modelLocation);
|
||||
var sprite = spriteGetter.apply(context.getMaterial(face.texture()));
|
||||
var quad = BlockModel.bakeFace(element, face, sprite, direction, modelState);
|
||||
postTransform.processInPlace(quad);
|
||||
|
||||
if (face.cullForDirection == null)
|
||||
if (face.cullForDirection() == null)
|
||||
modelBuilder.addUnculledFace(quad);
|
||||
else
|
||||
modelBuilder.addCulledFace(modelState.getRotation().rotateTransform(face.cullForDirection), quad);
|
||||
modelBuilder.addCulledFace(modelState.getRotation().rotateTransform(face.cullForDirection()), quad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ public class EmptyModel extends SimpleUnbakedGeometry<EmptyModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation)
|
||||
protected void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform)
|
||||
{
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
return BAKED;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class ExtendedBlockModelDeserializer extends BlockModel.Deserializer
|
||||
if (jsonobject.has("render_type"))
|
||||
{
|
||||
var renderTypeHintName = GsonHelper.getAsString(jsonobject, "render_type");
|
||||
model.customData.setRenderTypeHint(new ResourceLocation(renderTypeHintName));
|
||||
model.customData.setRenderTypeHint(ResourceLocation.parse(renderTypeHintName));
|
||||
}
|
||||
|
||||
if (jsonobject.has("visibility"))
|
||||
@@ -91,7 +91,7 @@ public class ExtendedBlockModelDeserializer extends BlockModel.Deserializer
|
||||
if (!object.has("loader"))
|
||||
return null;
|
||||
|
||||
var name = new ResourceLocation(GsonHelper.getAsString(object, "loader"));
|
||||
var name = ResourceLocation.parse(GsonHelper.getAsString(object, "loader"));
|
||||
var loader = GeometryLoaderManager.get(name);
|
||||
if (loader == null)
|
||||
throw new JsonParseException(String.format(Locale.ENGLISH, "Model loader '%s' not found. Registered loaders: %s", name, GeometryLoaderManager.getLoaderList()));
|
||||
|
||||
@@ -30,10 +30,8 @@ import net.minecraft.util.ExtraCodecs;
|
||||
* @param ambientOcclusion If this face has AO
|
||||
* @param calculateNormals If we should manually calculate the normals for this block or inherit facing normals like vanilla
|
||||
*/
|
||||
public record ForgeFaceData(int color, int blockLight, int skyLight, boolean ambientOcclusion, boolean calculateNormals)
|
||||
{
|
||||
public ForgeFaceData(int color, int blockLight, int skyLight, boolean ambientOcclusion)
|
||||
{
|
||||
public record ForgeFaceData(int color, int blockLight, int skyLight, boolean ambientOcclusion, boolean calculateNormals) {
|
||||
public ForgeFaceData(int color, int blockLight, int skyLight, boolean ambientOcclusion) {
|
||||
this(color, blockLight, skyLight, ambientOcclusion, false);
|
||||
}
|
||||
|
||||
@@ -59,12 +57,9 @@ public record ForgeFaceData(int color, int blockLight, int skyLight, boolean amb
|
||||
* @throws JsonParseException
|
||||
*/
|
||||
@Nullable
|
||||
public static ForgeFaceData read(@Nullable JsonElement obj, @Nullable ForgeFaceData fallback) throws JsonParseException
|
||||
{
|
||||
if(obj == null)
|
||||
{
|
||||
public static ForgeFaceData read(@Nullable JsonElement obj, @Nullable ForgeFaceData fallback) throws JsonParseException {
|
||||
if (obj == null)
|
||||
return fallback;
|
||||
}
|
||||
return CODEC.parse(JsonOps.INSTANCE, obj).getOrThrow(JsonParseException::new);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,6 @@ public class ForgeItemModelShaper extends ItemModelShaper {
|
||||
|
||||
public ModelResourceLocation getLocation(@NotNull ItemStack stack) {
|
||||
ModelResourceLocation location = locations.get(ForgeRegistries.ITEMS.getDelegateOrThrow(stack.getItem()));
|
||||
return location == null ? ModelBakery.MISSING_MODEL_LOCATION : location;
|
||||
return location == null ? ModelBakery.MISSING_MODEL_VARIANT : location;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ package net.minecraftforge.client.model;
|
||||
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
||||
import com.mojang.math.Transformation;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -18,54 +17,47 @@ import java.util.List;
|
||||
*
|
||||
* @see QuadTransformers
|
||||
*/
|
||||
public interface IQuadTransformer
|
||||
{
|
||||
int STRIDE = DefaultVertexFormat.BLOCK.getIntegerSize();
|
||||
int POSITION = findOffset(DefaultVertexFormat.ELEMENT_POSITION);
|
||||
int COLOR = findOffset(DefaultVertexFormat.ELEMENT_COLOR);
|
||||
int UV0 = findOffset(DefaultVertexFormat.ELEMENT_UV0);
|
||||
int UV1 = findOffset(DefaultVertexFormat.ELEMENT_UV1);
|
||||
int UV2 = findOffset(DefaultVertexFormat.ELEMENT_UV2);
|
||||
int NORMAL = findOffset(DefaultVertexFormat.ELEMENT_NORMAL);
|
||||
public interface IQuadTransformer {
|
||||
int STRIDE = DefaultVertexFormat.BLOCK.getVertexSize() / 4;
|
||||
int POSITION = findOffset(VertexFormatElement.POSITION);
|
||||
int COLOR = findOffset(VertexFormatElement.COLOR);
|
||||
int UV0 = findOffset(VertexFormatElement.UV0);
|
||||
int UV1 = findOffset(VertexFormatElement.UV1);
|
||||
int UV2 = findOffset(VertexFormatElement.UV2);
|
||||
int NORMAL = findOffset(VertexFormatElement.NORMAL);
|
||||
|
||||
void processInPlace(BakedQuad quad);
|
||||
|
||||
default void processInPlace(List<BakedQuad> quads)
|
||||
{
|
||||
default void processInPlace(List<BakedQuad> quads) {
|
||||
for (BakedQuad quad : quads)
|
||||
processInPlace(quad);
|
||||
}
|
||||
|
||||
default BakedQuad process(BakedQuad quad)
|
||||
{
|
||||
default BakedQuad process(BakedQuad quad) {
|
||||
var copy = copy(quad);
|
||||
processInPlace(copy);
|
||||
return copy;
|
||||
}
|
||||
|
||||
default List<BakedQuad> process(List<BakedQuad> inputs)
|
||||
{
|
||||
default List<BakedQuad> process(List<BakedQuad> inputs) {
|
||||
return inputs.stream().map(IQuadTransformer::copy).peek(this::processInPlace).toList();
|
||||
}
|
||||
|
||||
default IQuadTransformer andThen(IQuadTransformer other)
|
||||
{
|
||||
default IQuadTransformer andThen(IQuadTransformer other) {
|
||||
return quad -> {
|
||||
processInPlace(quad);
|
||||
other.processInPlace(quad);
|
||||
};
|
||||
}
|
||||
|
||||
private static BakedQuad copy(BakedQuad quad)
|
||||
{
|
||||
private static BakedQuad copy(BakedQuad quad) {
|
||||
var vertices = quad.getVertices();
|
||||
return new BakedQuad(Arrays.copyOf(vertices, vertices.length), quad.getTintIndex(), quad.getDirection(), quad.getSprite(), quad.isShade(), quad.hasAmbientOcclusion());
|
||||
}
|
||||
|
||||
private static int findOffset(VertexFormatElement element)
|
||||
{
|
||||
private static int findOffset(VertexFormatElement element) {
|
||||
// Divide by 4 because we want the int offset
|
||||
var index = DefaultVertexFormat.BLOCK.getElements().indexOf(element);
|
||||
return index < 0 ? -1 : DefaultVertexFormat.BLOCK.getOffset(index) / 4;
|
||||
var index = DefaultVertexFormat.BLOCK.getOffset(element);
|
||||
return index < 0 ? -1 : index / 4;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
@@ -43,18 +42,16 @@ public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel>
|
||||
{
|
||||
@Nullable
|
||||
private ImmutableList<Material> textures;
|
||||
private final Int2ObjectMap<ForgeFaceData> layerData;
|
||||
private final Int2ObjectMap<ResourceLocation> renderTypeNames;
|
||||
|
||||
private ItemLayerModel(@Nullable ImmutableList<Material> textures, Int2ObjectMap<ForgeFaceData> layerData, Int2ObjectMap<ResourceLocation> renderTypeNames)
|
||||
private ItemLayerModel(@Nullable ImmutableList<Material> textures, Int2ObjectMap<ResourceLocation> renderTypeNames)
|
||||
{
|
||||
this.textures = textures;
|
||||
this.layerData = layerData;
|
||||
this.renderTypeNames = renderTypeNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
if (textures == null)
|
||||
{
|
||||
@@ -78,8 +75,8 @@ public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel>
|
||||
for (int i = 0; i < textures.size(); i++)
|
||||
{
|
||||
TextureAtlasSprite sprite = spriteGetter.apply(textures.get(i));
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemElements(i, sprite.contents(), this.layerData.get(i));
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> sprite, modelState, modelLocation);
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemElements(i, sprite.contents());
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> sprite, modelState);
|
||||
var renderTypeName = renderTypeNames.get(i);
|
||||
var renderTypes = renderTypeName != null ? context.getRenderType(renderTypeName) : null;
|
||||
builder.addQuads(renderTypes != null ? renderTypes : normalRenderTypes, quads);
|
||||
@@ -101,20 +98,14 @@ public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel>
|
||||
var renderTypes = jsonObject.getAsJsonObject("render_types");
|
||||
for (Map.Entry<String, JsonElement> entry : renderTypes.entrySet())
|
||||
{
|
||||
var renderType = new ResourceLocation(entry.getKey());
|
||||
var renderType = ResourceLocation.parse(entry.getKey());
|
||||
for (var layer : entry.getValue().getAsJsonArray())
|
||||
if (renderTypeNames.put(layer.getAsInt(), renderType) != null)
|
||||
throw new JsonParseException("Registered duplicate render type for layer " + layer);
|
||||
}
|
||||
}
|
||||
|
||||
var emissiveLayers = new Int2ObjectArrayMap<ForgeFaceData>();
|
||||
if(jsonObject.has("forge_data"))
|
||||
{
|
||||
JsonObject forgeData = jsonObject.get("forge_data").getAsJsonObject();
|
||||
readLayerData(forgeData, "layers", renderTypeNames, emissiveLayers, false);
|
||||
}
|
||||
return new ItemLayerModel(null, emissiveLayers, renderTypeNames);
|
||||
return new ItemLayerModel(null, renderTypeNames);
|
||||
}
|
||||
|
||||
protected void readLayerData(JsonObject jsonObject, String name, Int2ObjectOpenHashMap<ResourceLocation> renderTypeNames, Int2ObjectMap<ForgeFaceData> layerData, boolean logWarning)
|
||||
|
||||
@@ -160,7 +160,7 @@ public final class QuadTransformers {
|
||||
/**
|
||||
* Converts an ARGB color to an ABGR color, as the commonly used color format is not the format colors end up packed into.
|
||||
* This function doubles as its own inverse.
|
||||
* @param color ARGB color
|
||||
* @param argb ARGB color
|
||||
* @return ABGR color
|
||||
*/
|
||||
public static int toABGR(int argb)
|
||||
|
||||
@@ -54,14 +54,14 @@ public class SeparateTransformsModel implements IUnbakedGeometry<SeparateTransfo
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
return new Baked(
|
||||
context.useAmbientOcclusion(), context.isGui3d(), context.useBlockLight(),
|
||||
spriteGetter.apply(context.getMaterial("particle")), overrides,
|
||||
baseModel.bake(baker, baseModel, spriteGetter, modelState, modelLocation, context.useBlockLight()),
|
||||
baseModel.bake(baker, baseModel, spriteGetter, modelState, context.useBlockLight()),
|
||||
ImmutableMap.copyOf(Maps.transformValues(perspectives, value -> {
|
||||
return value.bake(baker, value, spriteGetter, modelState, modelLocation, context.useBlockLight());
|
||||
return value.bake(baker, value, spriteGetter, modelState, context.useBlockLight(), context.getRenderType(context.getRenderTypeHint()));
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ package net.minecraftforge.client.model.data;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
@@ -32,61 +33,52 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
@EventBusSubscriber(modid = "forge", bus = Bus.FORGE, value = Dist.CLIENT)
|
||||
public class ModelDataManager
|
||||
{
|
||||
public class ModelDataManager {
|
||||
private final Level level;
|
||||
private final Map<ChunkPos, Set<BlockPos>> needModelDataRefresh = new ConcurrentHashMap<>();
|
||||
private final Map<ChunkPos, Map<BlockPos, ModelData>> modelDataCache = new ConcurrentHashMap<>();
|
||||
|
||||
public ModelDataManager(Level level)
|
||||
{
|
||||
public ModelDataManager(Level level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public void requestRefresh(@NotNull BlockEntity blockEntity)
|
||||
{
|
||||
public void requestRefresh(@NotNull BlockEntity blockEntity) {
|
||||
Preconditions.checkNotNull(blockEntity, "Block entity must not be null");
|
||||
needModelDataRefresh.computeIfAbsent(new ChunkPos(blockEntity.getBlockPos()), $ -> Collections.synchronizedSet(new HashSet<>()))
|
||||
.add(blockEntity.getBlockPos());
|
||||
}
|
||||
|
||||
private void refreshAt(ChunkPos chunk)
|
||||
{
|
||||
private void refreshAt(ChunkPos chunk) {
|
||||
Set<BlockPos> needUpdate = needModelDataRefresh.remove(chunk);
|
||||
|
||||
if (needUpdate != null)
|
||||
{
|
||||
if (needUpdate != null) {
|
||||
Map<BlockPos, ModelData> data = modelDataCache.computeIfAbsent(chunk, $ -> new ConcurrentHashMap<>());
|
||||
for (BlockPos pos : needUpdate)
|
||||
{
|
||||
for (BlockPos pos : needUpdate) {
|
||||
BlockEntity toUpdate = level.getBlockEntity(pos);
|
||||
if (toUpdate != null && !toUpdate.isRemoved())
|
||||
{
|
||||
data.put(pos, toUpdate.getModelData());
|
||||
}
|
||||
else
|
||||
{
|
||||
data.remove(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable ModelData getAt(BlockPos pos)
|
||||
{
|
||||
public @Nullable ModelData getAt(BlockPos pos) {
|
||||
return getAt(new ChunkPos(pos)).get(pos);
|
||||
}
|
||||
|
||||
public Map<BlockPos, ModelData> getAt(ChunkPos pos)
|
||||
{
|
||||
public Map<BlockPos, ModelData> getAt(SectionPos pos) {
|
||||
return getAt(pos.chunk());
|
||||
}
|
||||
|
||||
public Map<BlockPos, ModelData> getAt(ChunkPos pos) {
|
||||
Preconditions.checkArgument(level.isClientSide, "Cannot request model data for server level");
|
||||
refreshAt(pos);
|
||||
return modelDataCache.getOrDefault(pos, Collections.emptyMap());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onChunkUnload(ChunkEvent.Unload event)
|
||||
{
|
||||
public static void onChunkUnload(ChunkEvent.Unload event) {
|
||||
var level = event.getChunk().getWorldForge();
|
||||
if (level == null)
|
||||
return;
|
||||
|
||||
@@ -143,11 +143,11 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public ResourceLocation modLoc(String name) {
|
||||
return new ResourceLocation(modid, name);
|
||||
return ResourceLocation.fromNamespaceAndPath(modid, name);
|
||||
}
|
||||
|
||||
public ResourceLocation mcLoc(String name) {
|
||||
return new ResourceLocation(name);
|
||||
return ResourceLocation.parse(name);
|
||||
}
|
||||
|
||||
private ResourceLocation key(Block block) {
|
||||
@@ -159,12 +159,11 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public ResourceLocation blockTexture(Block block) {
|
||||
ResourceLocation name = key(block);
|
||||
return new ResourceLocation(name.getNamespace(), ModelProvider.BLOCK_FOLDER + "/" + name.getPath());
|
||||
return key(block).withPath(p -> ModelProvider.BLOCK_FOLDER + '/' + p);
|
||||
}
|
||||
|
||||
private ResourceLocation extend(ResourceLocation rl, String suffix) {
|
||||
return new ResourceLocation(rl.getNamespace(), rl.getPath() + suffix);
|
||||
return rl.withSuffix(suffix);
|
||||
}
|
||||
|
||||
public ModelFile cubeAll(Block block) {
|
||||
@@ -627,31 +626,31 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public static final ImmutableMap<Direction, Property<WallSide>> WALL_PROPS = ImmutableMap.<Direction, Property<WallSide>>builder()
|
||||
.put(Direction.EAST, BlockStateProperties.EAST_WALL)
|
||||
.put(Direction.NORTH, BlockStateProperties.NORTH_WALL)
|
||||
.put(Direction.SOUTH, BlockStateProperties.SOUTH_WALL)
|
||||
.put(Direction.WEST, BlockStateProperties.WEST_WALL)
|
||||
.build();
|
||||
.put(Direction.EAST, BlockStateProperties.EAST_WALL)
|
||||
.put(Direction.NORTH, BlockStateProperties.NORTH_WALL)
|
||||
.put(Direction.SOUTH, BlockStateProperties.SOUTH_WALL)
|
||||
.put(Direction.WEST, BlockStateProperties.WEST_WALL)
|
||||
.build();
|
||||
|
||||
public void wallBlock(WallBlock block, ModelFile post, ModelFile side, ModelFile sideTall) {
|
||||
MultiPartBlockStateBuilder builder = getMultipartBuilder(block)
|
||||
.part().modelFile(post).addModel()
|
||||
.condition(WallBlock.UP, true).end();
|
||||
WALL_PROPS.entrySet().stream()
|
||||
.filter(e -> e.getKey().getAxis().isHorizontal())
|
||||
.forEach(e -> {
|
||||
wallSidePart(builder, side, e, WallSide.LOW);
|
||||
wallSidePart(builder, sideTall, e, WallSide.TALL);
|
||||
});
|
||||
.filter(e -> e.getKey().getAxis().isHorizontal())
|
||||
.forEach(e -> {
|
||||
wallSidePart(builder, side, e, WallSide.LOW);
|
||||
wallSidePart(builder, sideTall, e, WallSide.TALL);
|
||||
});
|
||||
}
|
||||
|
||||
private void wallSidePart(MultiPartBlockStateBuilder builder, ModelFile model, Map.Entry<Direction, Property<WallSide>> entry, WallSide height) {
|
||||
builder.part()
|
||||
.modelFile(model)
|
||||
.rotationY((((int) entry.getKey().toYRot()) + 180) % 360)
|
||||
.uvLock(true)
|
||||
.addModel()
|
||||
.condition(entry.getValue(), height);
|
||||
.modelFile(model)
|
||||
.rotationY((((int) entry.getKey().toYRot()) + 180) % 360)
|
||||
.uvLock(true)
|
||||
.addModel()
|
||||
.condition(entry.getValue(), height);
|
||||
}
|
||||
|
||||
public void paneBlock(IronBarsBlock block, ResourceLocation pane, ResourceLocation edge) {
|
||||
|
||||
@@ -33,7 +33,7 @@ public abstract class ItemModelProvider extends ModelProvider<ItemModelBuilder>
|
||||
{
|
||||
return getBuilder(item.toString())
|
||||
.parent(new ModelFile.UncheckedModelFile("item/generated"))
|
||||
.texture("layer0", new ResourceLocation(item.getNamespace(), "item/" + item.getPath()));
|
||||
.texture("layer0", item.withPrefix("item/"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -119,9 +119,9 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
} else {
|
||||
ResourceLocation asLoc;
|
||||
if (texture.contains(":")) {
|
||||
asLoc = new ResourceLocation(texture);
|
||||
asLoc = ResourceLocation.parse(texture);
|
||||
} else {
|
||||
asLoc = new ResourceLocation(getLocation().getNamespace(), texture);
|
||||
asLoc = ResourceLocation.fromNamespaceAndPath(getLocation().getNamespace(), texture);
|
||||
}
|
||||
return texture(key, asLoc);
|
||||
}
|
||||
@@ -158,7 +158,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
*/
|
||||
public T renderType(String renderType) {
|
||||
Preconditions.checkNotNull(renderType, "Render type must not be null");
|
||||
return renderType(new ResourceLocation(renderType));
|
||||
return renderType(ResourceLocation.parse(renderType));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,27 +317,21 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
if (face == null) continue;
|
||||
|
||||
JsonObject faceObj = new JsonObject();
|
||||
faceObj.addProperty("texture", serializeLocOrKey(face.texture));
|
||||
if (!Arrays.equals(face.uv.uvs, part.uvsByFace(dir))) {
|
||||
faceObj.add("uv", new Gson().toJsonTree(face.uv.uvs));
|
||||
}
|
||||
if (face.cullForDirection != null) {
|
||||
faceObj.addProperty("cullface", face.cullForDirection.getSerializedName());
|
||||
}
|
||||
if (face.uv.rotation != 0) {
|
||||
faceObj.addProperty("rotation", face.uv.rotation);
|
||||
}
|
||||
if (face.tintIndex != -1) {
|
||||
faceObj.addProperty("tintindex", face.tintIndex);
|
||||
}
|
||||
if (!face.getFaceData().equals(ForgeFaceData.DEFAULT)) {
|
||||
faceObj.add("forge_data", ForgeFaceData.CODEC.encodeStart(JsonOps.INSTANCE, face.getFaceData()).result().get());
|
||||
}
|
||||
faceObj.addProperty("texture", serializeLocOrKey(face.texture()));
|
||||
if (!Arrays.equals(face.uv().uvs, part.uvsByFace(dir)))
|
||||
faceObj.add("uv", new Gson().toJsonTree(face.uv().uvs));
|
||||
if (face.cullForDirection() != null)
|
||||
faceObj.addProperty("cullface", face.cullForDirection().getSerializedName());
|
||||
if (face.uv().rotation != 0)
|
||||
faceObj.addProperty("rotation", face.uv().rotation);
|
||||
if (face.tintIndex() != -1)
|
||||
faceObj.addProperty("tintindex", face.tintIndex());
|
||||
if (face.data() != null && !ForgeFaceData.DEFAULT.equals(face.data()))
|
||||
faceObj.add("forge_data", ForgeFaceData.CODEC.encodeStart(JsonOps.INSTANCE, face.data()).result().get());
|
||||
faces.add(dir.getSerializedName(), faceObj);
|
||||
}
|
||||
if (!part.faces.isEmpty()) {
|
||||
if (!part.faces.isEmpty())
|
||||
partObj.add("faces", faces);
|
||||
}
|
||||
elements.add(partObj);
|
||||
});
|
||||
root.add("elements", elements);
|
||||
@@ -360,7 +354,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
if (tex.charAt(0) == '#') {
|
||||
return tex;
|
||||
}
|
||||
return new ResourceLocation(tex).toString();
|
||||
return ResourceLocation.parse(tex).toString();
|
||||
}
|
||||
|
||||
private JsonArray serializeVector3f(Vector3f vec) {
|
||||
@@ -385,10 +379,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
private final Map<Direction, FaceBuilder> faces = new LinkedHashMap<>();
|
||||
private RotationBuilder rotation;
|
||||
private boolean shade = true;
|
||||
private int color = 0xFFFFFFFF;
|
||||
private int blockLight = 0, skyLight = 0;
|
||||
private boolean hasAmbientOcclusion = true;
|
||||
private boolean calculateNormals = false;
|
||||
private ForgeFaceData data = ForgeFaceData.DEFAULT;
|
||||
|
||||
private void validateCoordinate(float coord, char name) {
|
||||
Preconditions.checkArgument(!(coord < -16.0F) && !(coord > 32.0F), "Position " + name + " out of range, must be within [-16, 32]. Found: %d", coord);
|
||||
@@ -530,9 +521,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public ElementBuilder emissivity(int blockLight, int skyLight) {
|
||||
this.blockLight = blockLight;
|
||||
this.skyLight = skyLight;
|
||||
return this;
|
||||
return data(new ForgeFaceData(this.data.color(), blockLight, skyLight, this.data.ambientOcclusion(), this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -542,8 +531,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public ElementBuilder color(int color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
return data(new ForgeFaceData(color, this.data.blockLight(), this.data.skyLight(), this.data.ambientOcclusion(), this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -553,8 +541,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public ElementBuilder ao(boolean ao) {
|
||||
this.hasAmbientOcclusion = ao;
|
||||
return this;
|
||||
return data(new ForgeFaceData(this.data.color(), this.data.blockLight(), this.data.skyLight(), ao, this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -564,7 +551,11 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public ElementBuilder calculateNormals(boolean calc) {
|
||||
this.calculateNormals = calc;
|
||||
return data(new ForgeFaceData(this.data.color(), this.data.blockLight(), this.data.skyLight(), this.data.ambientOcclusion(), calc));
|
||||
}
|
||||
|
||||
public ElementBuilder data(ForgeFaceData data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -575,22 +566,18 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
BlockElement build() {
|
||||
Map<Direction, BlockElementFace> faces = this.faces.entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().build(), (k1, k2) -> { throw new IllegalArgumentException(); }, LinkedHashMap::new));
|
||||
return new BlockElement(from, to, faces, rotation == null ? null : rotation.build(), shade, new ForgeFaceData(this.color, this.blockLight, this.skyLight, this.hasAmbientOcclusion, this.calculateNormals));
|
||||
return new BlockElement(from, to, faces, rotation == null ? null : rotation.build(), shade);
|
||||
}
|
||||
|
||||
public T end() { return self(); }
|
||||
|
||||
public class FaceBuilder {
|
||||
|
||||
private Direction cullface;
|
||||
private int tintindex = -1;
|
||||
private String texture = MissingTextureAtlasSprite.getLocation().toString();
|
||||
private float[] uvs;
|
||||
private FaceRotation rotation = FaceRotation.ZERO;
|
||||
private int color = 0xFFFFFFFF;
|
||||
private int blockLight = 0, skyLight = 0;
|
||||
private boolean hasAmbientOcclusion = true;
|
||||
private boolean calculateNormals = false;
|
||||
private ForgeFaceData data = ElementBuilder.this.data;
|
||||
|
||||
FaceBuilder(Direction dir) {
|
||||
// param unused for functional match
|
||||
@@ -646,9 +633,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public FaceBuilder emissivity(int blockLight, int skyLight) {
|
||||
this.blockLight = blockLight;
|
||||
this.skyLight = skyLight;
|
||||
return this;
|
||||
return data(new ForgeFaceData(this.data.color(), blockLight, skyLight, this.data.ambientOcclusion(), this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -658,8 +643,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public FaceBuilder color(int color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
return data(new ForgeFaceData(color, this.data.blockLight(), this.data.skyLight(), this.data.ambientOcclusion(), this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -669,8 +653,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public FaceBuilder ao(boolean ao) {
|
||||
this.hasAmbientOcclusion = ao;
|
||||
return this;
|
||||
return data(new ForgeFaceData(this.data.color(), this.data.blockLight(), this.data.skyLight(), ao, this.data.calculateNormals()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -680,15 +663,18 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
*/
|
||||
public FaceBuilder calculateNormals(boolean calc) {
|
||||
this.calculateNormals = calc;
|
||||
return data(new ForgeFaceData(this.data.color(), this.data.blockLight(), this.data.skyLight(), this.data.ambientOcclusion(), calc));
|
||||
}
|
||||
|
||||
public FaceBuilder data(ForgeFaceData data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
BlockElementFace build() {
|
||||
if (this.texture == null) {
|
||||
if (this.texture == null)
|
||||
throw new IllegalStateException("A model face must have a texture");
|
||||
}
|
||||
return new BlockElementFace(cullface, tintindex, texture, new BlockFaceUV(uvs, rotation.rotation), new ForgeFaceData(this.color, this.blockLight, this.skyLight, this.hasAmbientOcclusion, this.calculateNormals));
|
||||
return new BlockElementFace(cullface, tintindex, texture, new BlockFaceUV(uvs, rotation.rotation), this.data);
|
||||
}
|
||||
|
||||
public ElementBuilder end() { return ElementBuilder.this; }
|
||||
@@ -826,8 +812,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
}
|
||||
}
|
||||
|
||||
public class RootTransformsBuilder
|
||||
{
|
||||
public class RootTransformsBuilder {
|
||||
private static final Vector3f ONE = new Vector3f(1, 1, 1);
|
||||
|
||||
private Vector3f translation = new Vector3f();
|
||||
@@ -838,9 +823,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
private @Nullable TransformationHelper.TransformOrigin origin;
|
||||
private @Nullable Vector3f originVec;
|
||||
|
||||
RootTransformsBuilder()
|
||||
{
|
||||
}
|
||||
RootTransformsBuilder() { }
|
||||
|
||||
/**
|
||||
* Sets the translation of the root transform.
|
||||
@@ -849,8 +832,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code translation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder translation(Vector3f translation)
|
||||
{
|
||||
public RootTransformsBuilder translation(Vector3f translation) {
|
||||
this.translation = Preconditions.checkNotNull(translation, "Translation must not be null");
|
||||
return this;
|
||||
}
|
||||
@@ -863,8 +845,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param z z translation
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder translation(float x, float y, float z)
|
||||
{
|
||||
public RootTransformsBuilder translation(float x, float y, float z) {
|
||||
return translation(new Vector3f(x, y, z));
|
||||
}
|
||||
|
||||
@@ -875,8 +856,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code rotation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder rotation(Quaternionf rotation)
|
||||
{
|
||||
public RootTransformsBuilder rotation(Quaternionf rotation) {
|
||||
this.leftRotation = Preconditions.checkNotNull(rotation, "Rotation must not be null");
|
||||
return this;
|
||||
}
|
||||
@@ -890,8 +870,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param isDegrees whether the rotation is in degrees or radians
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder rotation(float x, float y, float z, boolean isDegrees)
|
||||
{
|
||||
public RootTransformsBuilder rotation(float x, float y, float z, boolean isDegrees) {
|
||||
return rotation(TransformationHelper.quatFromXYZ(x, y, z, isDegrees));
|
||||
}
|
||||
|
||||
@@ -902,8 +881,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code leftRotation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder leftRotation(Quaternionf leftRotation)
|
||||
{
|
||||
public RootTransformsBuilder leftRotation(Quaternionf leftRotation) {
|
||||
return rotation(leftRotation);
|
||||
}
|
||||
|
||||
@@ -916,8 +894,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param isDegrees whether the rotation is in degrees or radians
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder leftRotation(float x, float y, float z, boolean isDegrees)
|
||||
{
|
||||
public RootTransformsBuilder leftRotation(float x, float y, float z, boolean isDegrees) {
|
||||
return leftRotation(TransformationHelper.quatFromXYZ(x, y, z, isDegrees));
|
||||
}
|
||||
|
||||
@@ -928,8 +905,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code rightRotation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder rightRotation(Quaternionf rightRotation)
|
||||
{
|
||||
public RootTransformsBuilder rightRotation(Quaternionf rightRotation) {
|
||||
this.rightRotation = Preconditions.checkNotNull(rightRotation, "Rotation must not be null");
|
||||
return this;
|
||||
}
|
||||
@@ -943,8 +919,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param isDegrees whether the rotation is in degrees or radians
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder rightRotation(float x, float y, float z, boolean isDegrees)
|
||||
{
|
||||
public RootTransformsBuilder rightRotation(float x, float y, float z, boolean isDegrees) {
|
||||
return rightRotation(TransformationHelper.quatFromXYZ(x, y, z, isDegrees));
|
||||
}
|
||||
|
||||
@@ -955,8 +930,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code rightRotation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder postRotation(Quaternionf postRotation)
|
||||
{
|
||||
public RootTransformsBuilder postRotation(Quaternionf postRotation) {
|
||||
return rightRotation(postRotation);
|
||||
}
|
||||
|
||||
@@ -969,8 +943,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param isDegrees whether the rotation is in degrees or radians
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder postRotation(float x, float y, float z, boolean isDegrees)
|
||||
{
|
||||
public RootTransformsBuilder postRotation(float x, float y, float z, boolean isDegrees) {
|
||||
return postRotation(TransformationHelper.quatFromXYZ(x, y, z, isDegrees));
|
||||
}
|
||||
|
||||
@@ -980,8 +953,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param scale the scale
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder scale(float scale)
|
||||
{
|
||||
public RootTransformsBuilder scale(float scale) {
|
||||
return scale(new Vector3f(scale, scale, scale));
|
||||
}
|
||||
|
||||
@@ -993,8 +965,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @param zScale z scale
|
||||
* @return this builder
|
||||
*/
|
||||
public RootTransformsBuilder scale(float xScale, float yScale, float zScale)
|
||||
{
|
||||
public RootTransformsBuilder scale(float xScale, float yScale, float zScale) {
|
||||
return scale(new Vector3f(xScale, yScale, zScale));
|
||||
}
|
||||
|
||||
@@ -1005,8 +976,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code scale} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder scale(Vector3f scale)
|
||||
{
|
||||
public RootTransformsBuilder scale(Vector3f scale) {
|
||||
this.scale = Preconditions.checkNotNull(scale, "Scale must not be null");
|
||||
return this;
|
||||
}
|
||||
@@ -1018,8 +988,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code transformation} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder transform(Transformation transformation)
|
||||
{
|
||||
public RootTransformsBuilder transform(Transformation transformation) {
|
||||
Preconditions.checkNotNull(transformation, "Transformation must not be null");
|
||||
this.translation = transformation.getTranslation();
|
||||
this.leftRotation = transformation.getLeftRotation();
|
||||
@@ -1035,8 +1004,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code origin} is {@code null}
|
||||
*/
|
||||
public RootTransformsBuilder origin(Vector3f origin)
|
||||
{
|
||||
public RootTransformsBuilder origin(Vector3f origin) {
|
||||
this.originVec = Preconditions.checkNotNull(origin, "Origin must not be null");
|
||||
this.origin = null;
|
||||
return this;
|
||||
@@ -1050,8 +1018,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @throws NullPointerException if {@code origin} is {@code null}
|
||||
* @throws IllegalArgumentException if {@code origin} is not {@code center}, {@code corner} or {@code opposing-corner}
|
||||
*/
|
||||
public RootTransformsBuilder origin(TransformationHelper.TransformOrigin origin)
|
||||
{
|
||||
public RootTransformsBuilder origin(TransformationHelper.TransformOrigin origin) {
|
||||
this.origin = Preconditions.checkNotNull(origin, "Origin must not be null");
|
||||
this.originVec = null;
|
||||
return this;
|
||||
@@ -1061,8 +1028,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* Finish configuring the parent builder
|
||||
* @return the parent block model builder
|
||||
*/
|
||||
public ModelBuilder<T> end()
|
||||
{
|
||||
public ModelBuilder<T> end() {
|
||||
return ModelBuilder.this;
|
||||
}
|
||||
|
||||
@@ -1071,39 +1037,26 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
JsonObject transform = new JsonObject();
|
||||
|
||||
if (!translation.equals(0, 0, 0))
|
||||
{
|
||||
transform.add("translation", writeVec3(translation));
|
||||
}
|
||||
|
||||
if (!scale.equals(ONE))
|
||||
{
|
||||
transform.add("scale", writeVec3(scale));
|
||||
}
|
||||
|
||||
if (!leftRotation.equals(0, 0, 0, 1))
|
||||
{
|
||||
transform.add("rotation", writeQuaternion(leftRotation));
|
||||
}
|
||||
|
||||
if (!rightRotation.equals(0, 0, 0, 1))
|
||||
{
|
||||
transform.add("post_rotation", writeQuaternion(rightRotation));
|
||||
}
|
||||
|
||||
if (origin != null)
|
||||
{
|
||||
transform.addProperty("origin", origin.getSerializedName());
|
||||
}
|
||||
else if (originVec != null && !originVec.equals(0, 0, 0))
|
||||
{
|
||||
transform.add("origin", writeVec3(originVec));
|
||||
}
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
||||
private static JsonArray writeVec3(Vector3f vector)
|
||||
{
|
||||
private static JsonArray writeVec3(Vector3f vector) {
|
||||
JsonArray array = new JsonArray();
|
||||
array.add(vector.x());
|
||||
array.add(vector.y());
|
||||
@@ -1111,8 +1064,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
return array;
|
||||
}
|
||||
|
||||
private static JsonArray writeQuaternion(Quaternionf quaternion)
|
||||
{
|
||||
private static JsonArray writeQuaternion(Quaternionf quaternion) {
|
||||
JsonArray array = new JsonArray();
|
||||
array.add(quaternion.x());
|
||||
array.add(quaternion.y());
|
||||
|
||||
@@ -40,7 +40,7 @@ public abstract class ModelFile {
|
||||
public static class UncheckedModelFile extends ModelFile {
|
||||
|
||||
public UncheckedModelFile(String location) {
|
||||
this(new ResourceLocation(location));
|
||||
this(ResourceLocation.parse(location));
|
||||
}
|
||||
public UncheckedModelFile(ResourceLocation location) {
|
||||
super(location);
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -32,7 +30,6 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
|
||||
protected static final ResourceType MODEL = new ResourceType(PackType.CLIENT_RESOURCES, ".json", "models");
|
||||
protected static final ResourceType MODEL_WITH_EXTENSION = new ResourceType(PackType.CLIENT_RESOURCES, "", "models");
|
||||
|
||||
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().create();
|
||||
protected final PackOutput output;
|
||||
protected final String modid;
|
||||
protected final String folder;
|
||||
@@ -63,7 +60,7 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
|
||||
|
||||
public T getBuilder(String path) {
|
||||
Preconditions.checkNotNull(path, "Path must not be null");
|
||||
ResourceLocation outputLoc = extendWithFolder(path.contains(":") ? new ResourceLocation(path) : new ResourceLocation(modid, path));
|
||||
ResourceLocation outputLoc = extendWithFolder(path.contains(":") ? ResourceLocation.parse(path) : ResourceLocation.fromNamespaceAndPath(modid, path));
|
||||
this.existingFileHelper.trackGenerated(outputLoc, MODEL);
|
||||
return generatedModels.computeIfAbsent(outputLoc, factory);
|
||||
}
|
||||
@@ -72,15 +69,15 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
|
||||
if (rl.getPath().contains("/")) {
|
||||
return rl;
|
||||
}
|
||||
return new ResourceLocation(rl.getNamespace(), folder + "/" + rl.getPath());
|
||||
return rl.withPrefix(folder + '/');
|
||||
}
|
||||
|
||||
public ResourceLocation modLoc(String name) {
|
||||
return new ResourceLocation(modid, name);
|
||||
return ResourceLocation.fromNamespaceAndPath(modid, name);
|
||||
}
|
||||
|
||||
public ResourceLocation mcLoc(String name) {
|
||||
return new ResourceLocation(name);
|
||||
return ResourceLocation.parse(name);
|
||||
}
|
||||
|
||||
public T withExistingParent(String name, String parent) {
|
||||
@@ -375,9 +372,8 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
|
||||
/**
|
||||
* {@return a model builder that's not directly saved to disk. Meant for use in custom model loaders.}
|
||||
*/
|
||||
public T nested()
|
||||
{
|
||||
return factory.apply(new ResourceLocation("dummy:dummy"));
|
||||
public T nested() {
|
||||
return factory.apply(ResourceLocation.fromNamespaceAndPath("dummy", "dummy"));
|
||||
}
|
||||
|
||||
public ModelFile.ExistingModelFile getExistingFile(ResourceLocation path) {
|
||||
|
||||
+3
-1
@@ -17,6 +17,8 @@ import java.util.*;
|
||||
|
||||
public class CompositeModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "composite");
|
||||
|
||||
public static <T extends ModelBuilder<T>> CompositeModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
return new CompositeModelBuilder<>(parent, existingFileHelper);
|
||||
@@ -27,7 +29,7 @@ public class CompositeModelBuilder<T extends ModelBuilder<T>> extends CustomLoad
|
||||
|
||||
protected CompositeModelBuilder(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(new ResourceLocation("forge:composite"), parent, existingFileHelper);
|
||||
super(NAME, parent, existingFileHelper);
|
||||
}
|
||||
|
||||
public CompositeModelBuilder<T> child(String name, T modelBuilder)
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@ import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class DynamicFluidContainerModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "fluid_container");
|
||||
public static <T extends ModelBuilder<T>> DynamicFluidContainerModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
return new DynamicFluidContainerModelBuilder<>(parent, existingFileHelper);
|
||||
@@ -29,7 +30,7 @@ public class DynamicFluidContainerModelBuilder<T extends ModelBuilder<T>> extend
|
||||
|
||||
protected DynamicFluidContainerModelBuilder(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(new ResourceLocation("forge:fluid_container"), parent, existingFileHelper);
|
||||
super(NAME, parent, existingFileHelper);
|
||||
}
|
||||
|
||||
public DynamicFluidContainerModelBuilder<T> fluid(Fluid fluid)
|
||||
|
||||
+4
-3
@@ -26,6 +26,7 @@ import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
public class ItemLayerModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "item_layers");
|
||||
public static <T extends ModelBuilder<T>> ItemLayerModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
return new ItemLayerModelBuilder<>(parent, existingFileHelper);
|
||||
@@ -37,7 +38,7 @@ public class ItemLayerModelBuilder<T extends ModelBuilder<T>> extends CustomLoad
|
||||
|
||||
protected ItemLayerModelBuilder(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(new ResourceLocation("forge:item_layers"), parent, existingFileHelper);
|
||||
super(NAME, parent, existingFileHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,9 +110,9 @@ public class ItemLayerModelBuilder<T extends ModelBuilder<T>> extends CustomLoad
|
||||
Preconditions.checkNotNull(renderType, "Render type must not be null");
|
||||
ResourceLocation asLoc;
|
||||
if (renderType.contains(":"))
|
||||
asLoc = new ResourceLocation(renderType);
|
||||
asLoc = ResourceLocation.parse(renderType);
|
||||
else
|
||||
asLoc = new ResourceLocation(parent.getLocation().getNamespace(), renderType);
|
||||
asLoc = parent.getLocation().withPath(renderType);
|
||||
return renderType(asLoc, layers);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@ import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
public class ObjModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "obj");
|
||||
public static <T extends ModelBuilder<T>> ObjModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
return new ObjModelBuilder<>(parent, existingFileHelper);
|
||||
@@ -29,7 +30,7 @@ public class ObjModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuil
|
||||
|
||||
protected ObjModelBuilder(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(new ResourceLocation("forge:obj"), parent, existingFileHelper);
|
||||
super(NAME, parent, existingFileHelper);
|
||||
}
|
||||
|
||||
public ObjModelBuilder<T> modelLocation(ResourceLocation modelLocation)
|
||||
|
||||
+3
-1
@@ -19,6 +19,8 @@ import java.util.Map;
|
||||
|
||||
public class SeparateTransformsModelBuilder<T extends ModelBuilder<T>> extends CustomLoaderBuilder<T>
|
||||
{
|
||||
private static final ResourceLocation NAME = ResourceLocation.fromNamespaceAndPath("forge", "separate_transforms");
|
||||
|
||||
public static <T extends ModelBuilder<T>> SeparateTransformsModelBuilder<T> begin(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
return new SeparateTransformsModelBuilder<>(parent, existingFileHelper);
|
||||
@@ -29,7 +31,7 @@ public class SeparateTransformsModelBuilder<T extends ModelBuilder<T>> extends C
|
||||
|
||||
protected SeparateTransformsModelBuilder(T parent, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(new ResourceLocation("forge:separate_transforms"), parent, existingFileHelper);
|
||||
super(NAME, parent, existingFileHelper);
|
||||
}
|
||||
|
||||
public SeparateTransformsModelBuilder<T> base(T modelBuilder)
|
||||
|
||||
+2
-2
@@ -156,12 +156,12 @@ public class BlockGeometryBakingContext implements IGeometryBakingContext
|
||||
this.gui3d = other.gui3d;
|
||||
}
|
||||
|
||||
public BakedModel bake(ModelBaker baker, Function<Material, TextureAtlasSprite> bakedTextureGetter, ModelState modelTransform, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(ModelBaker baker, Function<Material, TextureAtlasSprite> bakedTextureGetter, ModelState modelTransform, ItemOverrides overrides)
|
||||
{
|
||||
IUnbakedGeometry<?> geometry = getCustomGeometry();
|
||||
if (geometry == null)
|
||||
throw new IllegalStateException("Can not use custom baking without custom geometry");
|
||||
return geometry.bake(this, baker, bakedTextureGetter, modelTransform, overrides, modelLocation);
|
||||
return geometry.bake(this, baker, bakedTextureGetter, modelTransform, overrides);
|
||||
}
|
||||
|
||||
public static class VisibilityData
|
||||
|
||||
@@ -26,25 +26,20 @@ import net.minecraft.resources.ResourceLocation;
|
||||
* @see IGeometryLoader
|
||||
* @see IGeometryBakingContext
|
||||
*/
|
||||
public interface IUnbakedGeometry<T extends IUnbakedGeometry<T>>
|
||||
{
|
||||
BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation);
|
||||
public interface IUnbakedGeometry<T extends IUnbakedGeometry<T>> {
|
||||
BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides);
|
||||
|
||||
/**
|
||||
* Resolve parents of nested {@link BlockModel}s which are later used in
|
||||
* {@link IUnbakedGeometry#bake(IGeometryBakingContext, ModelBaker, Function, ModelState, ItemOverrides, ResourceLocation)}
|
||||
* {@link IUnbakedGeometry#bake(IGeometryBakingContext, ModelBaker, Function, ModelState, ItemOverrides)}
|
||||
* via {@link BlockModel#resolveParents(Function)}
|
||||
*/
|
||||
default void resolveParents(Function<ResourceLocation, UnbakedModel> modelGetter, IGeometryBakingContext context)
|
||||
{
|
||||
|
||||
}
|
||||
default void resolveParents(Function<ResourceLocation, UnbakedModel> modelGetter, IGeometryBakingContext context) { }
|
||||
|
||||
/**
|
||||
* {@return a set of all the components whose visibility may be configured via {@link IGeometryBakingContext}}
|
||||
*/
|
||||
default Set<String> getConfigurableComponentNames()
|
||||
{
|
||||
default Set<String> getConfigurableComponentNames() {
|
||||
return Set.of();
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import net.minecraftforge.client.model.IModelBuilder;
|
||||
public abstract class SimpleUnbakedGeometry<T extends SimpleUnbakedGeometry<T>> implements IUnbakedGeometry<T>
|
||||
{
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
TextureAtlasSprite particle = spriteGetter.apply(context.getMaterial("particle"));
|
||||
|
||||
@@ -33,10 +33,10 @@ public abstract class SimpleUnbakedGeometry<T extends SimpleUnbakedGeometry<T>>
|
||||
IModelBuilder<?> builder = IModelBuilder.of(context.useAmbientOcclusion(), context.useBlockLight(), context.isGui3d(),
|
||||
context.getTransforms(), overrides, particle, renderTypes);
|
||||
|
||||
addQuads(context, builder, baker, spriteGetter, modelState, modelLocation);
|
||||
addQuads(context, builder, baker, spriteGetter, modelState);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected abstract void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation);
|
||||
protected abstract void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform);
|
||||
}
|
||||
+1
-1
@@ -25,7 +25,7 @@ import java.util.function.Predicate;
|
||||
*/
|
||||
public class StandaloneGeometryBakingContext implements IGeometryBakingContext
|
||||
{
|
||||
public static final ResourceLocation LOCATION = new ResourceLocation("forge", "standalone");
|
||||
public static final ResourceLocation LOCATION = ResourceLocation.fromNamespaceAndPath("forge", "standalone");
|
||||
|
||||
public static final StandaloneGeometryBakingContext INSTANCE = create(LOCATION);
|
||||
|
||||
|
||||
@@ -91,22 +91,22 @@ public class UnbakedGeometryHelper
|
||||
tex = namespace != null ? namespace + ":" + path : path;
|
||||
}
|
||||
|
||||
return new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation(tex));
|
||||
return new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.parse(tex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for baking {@link BlockModel} instances. Handles baking custom geometries and deferring item model baking.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static BakedModel bake(BlockModel blockModel, ModelBaker modelBaker, BlockModel owner, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ResourceLocation modelLocation, boolean guiLight3d)
|
||||
public static BakedModel bake(BlockModel blockModel, ModelBaker modelBaker, BlockModel owner, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, boolean guiLight3d)
|
||||
{
|
||||
IUnbakedGeometry<?> customModel = blockModel.customData.getCustomGeometry();
|
||||
if (customModel != null)
|
||||
return customModel.bake(blockModel.customData, modelBaker, spriteGetter, modelState, blockModel.getOverrides(modelBaker, owner, spriteGetter), modelLocation);
|
||||
return customModel.bake(blockModel.customData, modelBaker, spriteGetter, modelState, blockModel.getOverrides(modelBaker, owner, spriteGetter));
|
||||
|
||||
// Handle vanilla item models here, since vanilla has a shortcut for them
|
||||
if (blockModel.getRootModel() == ModelBakery.GENERATION_MARKER)
|
||||
return ITEM_MODEL_GENERATOR.generateBlockModel(spriteGetter, blockModel).bake(modelBaker, blockModel, spriteGetter, modelState, modelLocation, guiLight3d);
|
||||
return ITEM_MODEL_GENERATOR.generateBlockModel(spriteGetter, blockModel).bake(modelBaker, blockModel, spriteGetter, modelState, guiLight3d);
|
||||
|
||||
if (blockModel.getRootModel() == ModelBakery.BLOCK_ENTITY_MARKER)
|
||||
{
|
||||
@@ -115,15 +115,7 @@ public class UnbakedGeometryHelper
|
||||
}
|
||||
|
||||
var elementsModel = new ElementsModel(blockModel.getElements());
|
||||
return elementsModel.bake(blockModel.customData, modelBaker, spriteGetter, modelState, blockModel.getOverrides(modelBaker, owner, spriteGetter), modelLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #createUnbakedItemElements(int, SpriteContents, ForgeFaceData)
|
||||
*/
|
||||
public static List<BlockElement> createUnbakedItemElements(int layerIndex, SpriteContents spriteContents)
|
||||
{
|
||||
return createUnbakedItemElements(layerIndex, spriteContents, null);
|
||||
return elementsModel.bake(blockModel.customData, modelBaker, spriteGetter, modelState, blockModel.getOverrides(modelBaker, owner, spriteGetter));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,22 +124,9 @@ public class UnbakedGeometryHelper
|
||||
* <p>
|
||||
* The {@link Direction#NORTH} and {@link Direction#SOUTH} faces take up the whole surface.
|
||||
*/
|
||||
public static List<BlockElement> createUnbakedItemElements(int layerIndex, SpriteContents spriteContents, @Nullable ForgeFaceData faceData)
|
||||
public static List<BlockElement> createUnbakedItemElements(int layerIndex, SpriteContents spriteContents)
|
||||
{
|
||||
var elements = ITEM_MODEL_GENERATOR.processFrames(layerIndex, "layer" + layerIndex, spriteContents);
|
||||
if(faceData != null)
|
||||
{
|
||||
elements.forEach(element -> element.setFaceData(faceData));
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #createUnbakedItemMaskElements(int, SpriteContents, ForgeFaceData)
|
||||
*/
|
||||
public static List<BlockElement> createUnbakedItemMaskElements(int layerIndex, SpriteContents spriteContents)
|
||||
{
|
||||
return createUnbakedItemMaskElements(layerIndex, spriteContents, null);
|
||||
return ITEM_MODEL_GENERATOR.processFrames(layerIndex, "layer" + layerIndex, spriteContents);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,9 +135,9 @@ public class UnbakedGeometryHelper
|
||||
* <p>
|
||||
* The {@link Direction#NORTH} and {@link Direction#SOUTH} faces take up only the pixels the texture uses.
|
||||
*/
|
||||
public static List<BlockElement> createUnbakedItemMaskElements(int layerIndex, SpriteContents spriteContents, @Nullable ForgeFaceData faceData)
|
||||
public static List<BlockElement> createUnbakedItemMaskElements(int layerIndex, SpriteContents spriteContents)
|
||||
{
|
||||
var elements = createUnbakedItemElements(layerIndex, spriteContents, faceData);
|
||||
var elements = createUnbakedItemElements(layerIndex, spriteContents);
|
||||
elements.remove(0); // Remove north and south faces
|
||||
|
||||
int width = spriteContents.width(), height = spriteContents.height();
|
||||
@@ -224,17 +203,17 @@ public class UnbakedGeometryHelper
|
||||
/**
|
||||
* Bakes a list of {@linkplain BlockElement block elements} and feeds the baked quads to a {@linkplain IModelBuilder model builder}.
|
||||
*/
|
||||
public static void bakeElements(IModelBuilder<?> builder, List<BlockElement> elements, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ResourceLocation modelLocation)
|
||||
public static void bakeElements(IModelBuilder<?> builder, List<BlockElement> elements, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState)
|
||||
{
|
||||
for (BlockElement element : elements)
|
||||
{
|
||||
element.faces.forEach((side, face) -> {
|
||||
var sprite = spriteGetter.apply(new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation(face.texture)));
|
||||
var quad = bakeElementFace(element, face, sprite, side, modelState, modelLocation);
|
||||
if (face.cullForDirection == null)
|
||||
var sprite = spriteGetter.apply(new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.parse(face.texture())));
|
||||
var quad = bakeElementFace(element, face, sprite, side, modelState);
|
||||
if (face.cullForDirection() == null)
|
||||
builder.addUnculledFace(quad);
|
||||
else
|
||||
builder.addCulledFace(Direction.rotate(modelState.getRotation().getMatrix(), face.cullForDirection), quad);
|
||||
builder.addCulledFace(Direction.rotate(modelState.getRotation().getMatrix(), face.cullForDirection()), quad);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -242,21 +221,21 @@ public class UnbakedGeometryHelper
|
||||
/**
|
||||
* Bakes a list of {@linkplain BlockElement block elements} and returns the list of baked quads.
|
||||
*/
|
||||
public static List<BakedQuad> bakeElements(List<BlockElement> elements, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ResourceLocation modelLocation)
|
||||
public static List<BakedQuad> bakeElements(List<BlockElement> elements, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState)
|
||||
{
|
||||
if (elements.isEmpty())
|
||||
return List.of();
|
||||
var list = new ArrayList<BakedQuad>();
|
||||
bakeElements(IModelBuilder.collecting(list), elements, spriteGetter, modelState, modelLocation);
|
||||
bakeElements(IModelBuilder.collecting(list), elements, spriteGetter, modelState);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a single {@link BlockElementFace} into a {@link BakedQuad}.
|
||||
*/
|
||||
public static BakedQuad bakeElementFace(BlockElement element, BlockElementFace face, TextureAtlasSprite sprite, Direction direction, ModelState state, ResourceLocation modelLocation)
|
||||
public static BakedQuad bakeElementFace(BlockElement element, BlockElementFace face, TextureAtlasSprite sprite, Direction direction, ModelState state)
|
||||
{
|
||||
return FACE_BAKERY.bakeQuad(element.from, element.to, face, sprite, direction, state, element.rotation, element.shade, modelLocation);
|
||||
return FACE_BAKERY.bakeQuad(element.from, element.to, face, sprite, direction, state, element.rotation, element.shade);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,4 +265,4 @@ public class UnbakedGeometryHelper
|
||||
rootTransform = rootTransform.applyOrigin(new Vector3f(-.5F, -.5F, -.5F));
|
||||
return new SimpleModelState(modelState.getRotation().compose(rootTransform), modelState.isUvLocked());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,21 +152,4 @@ public abstract class QuadLighter
|
||||
float yFactor = constantAmbientLight ? 0.9F : ((3.0F + normalY) / 4.0F);
|
||||
return Math.min(normalX * normalX * 0.6F + normalY * normalY * yFactor + normalZ * normalZ * 0.8F, 1.0F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This method is subtly different than {@link net.minecraft.client.renderer.LevelRenderer#getLightColor(BlockAndTintGetter, BlockState, BlockPos)}
|
||||
* as it only uses the state for querying if the state has emissive rendering but instead looks up the state at the given position for checking the
|
||||
* light emission.
|
||||
*/
|
||||
@Deprecated(since = "1.20.1")
|
||||
protected static int getLightColor(BlockAndTintGetter level, BlockPos pos, BlockState state)
|
||||
{
|
||||
if (state.emissiveRendering(level, pos))
|
||||
{
|
||||
return LightTexture.FULL_BRIGHT;
|
||||
}
|
||||
int skyLight = level.getBrightness(LightLayer.SKY, pos);
|
||||
int blockLight = Math.max(level.getBrightness(LightLayer.BLOCK, pos), level.getBlockState(pos).getLightEmission(level, pos));
|
||||
return skyLight << 20 | blockLight << 4;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package net.minecraftforge.client.model.obj;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -58,7 +57,7 @@ public class ObjLoader implements IGeometryLoader<ObjModel>, ResourceManagerRelo
|
||||
boolean emissiveAmbient = GsonHelper.getAsBoolean(jsonObject, "emissive_ambient", true);
|
||||
String mtlOverride = GsonHelper.getAsString(jsonObject, "mtl_override", null);
|
||||
|
||||
return loadModel(new ObjModel.ModelSettings(new ResourceLocation(modelLocation), automaticCulling, shadeQuads, flipV, emissiveAmbient, mtlOverride));
|
||||
return loadModel(new ObjModel.ModelSettings(ResourceLocation.parse(modelLocation), automaticCulling, shadeQuads, flipV, emissiveAmbient, mtlOverride));
|
||||
}
|
||||
|
||||
public ObjModel loadModel(ObjModel.ModelSettings settings)
|
||||
|
||||
@@ -119,9 +119,9 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
|
||||
{
|
||||
String lib = materialLibraryOverrideLocation;
|
||||
if (lib.contains(":"))
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(lib));
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.parse(lib));
|
||||
else
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(modelDomain, modelPath + lib));
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.fromNamespaceAndPath(modelDomain, modelPath + lib));
|
||||
}
|
||||
|
||||
String[] line;
|
||||
@@ -136,9 +136,9 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
|
||||
|
||||
String lib = line[1];
|
||||
if (lib.contains(":"))
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(lib));
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.parse(lib));
|
||||
else
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(new ResourceLocation(modelDomain, modelPath + lib));
|
||||
mtllib = ObjLoader.INSTANCE.loadMaterialLibrary(ResourceLocation.fromNamespaceAndPath(modelDomain, modelPath + lib));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation)
|
||||
protected void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform)
|
||||
{
|
||||
parts.values().stream().filter(part -> owner.isComponentVisible(part.name(), true))
|
||||
.forEach(part -> part.addQuads(owner, modelBuilder, baker, spriteGetter, modelTransform, modelLocation));
|
||||
@@ -421,19 +421,18 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
|
||||
color.y() * colorTint.y(),
|
||||
color.z() * colorTint.z(),
|
||||
color.w() * colorTint.w());
|
||||
quadBaker.vertex(position.x(), position.y(), position.z());
|
||||
quadBaker.color(tintedColor.x(), tintedColor.y(), tintedColor.z(), tintedColor.w());
|
||||
quadBaker.uv(
|
||||
quadBaker.addVertex(position.x(), position.y(), position.z());
|
||||
quadBaker.setColor(tintedColor.x(), tintedColor.y(), tintedColor.z(), tintedColor.w());
|
||||
quadBaker.setUv(
|
||||
texture.getU(texCoord.x),
|
||||
texture.getV((flipV ? 1 - texCoord.y : texCoord.y))
|
||||
);
|
||||
quadBaker.uv2(uv2);
|
||||
quadBaker.normal(normal.x(), normal.y(), normal.z());
|
||||
quadBaker.setUv2(uv2 & 0xFFFF, uv2 >> 16 & 0xFFFF);
|
||||
quadBaker.setNormal(normal.x(), normal.y(), normal.z());
|
||||
if (i == 0)
|
||||
{
|
||||
quadBaker.setDirection(Direction.getNearest(normal.x(), normal.y(), normal.z()));
|
||||
}
|
||||
quadBaker.endVertex();
|
||||
pos[i] = position;
|
||||
norm[i] = normal;
|
||||
}
|
||||
@@ -656,7 +655,7 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
|
||||
}
|
||||
|
||||
ResourceLocation textureLocation = UnbakedGeometryHelper.resolveDirtyMaterial(mat.diffuseColorMap, configuration).texture();
|
||||
ResourceLocation texturePath = new ResourceLocation(textureLocation.getNamespace(), "textures/" + textureLocation.getPath() + ".png");
|
||||
ResourceLocation texturePath = textureLocation.withPath(p -> "textures/" + p + ".png");
|
||||
|
||||
builder.addMesh(texturePath, quads);
|
||||
}
|
||||
|
||||
+12
-19
@@ -52,8 +52,10 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer vertex(double x, double y, double z)
|
||||
public VertexConsumer addVertex(float x, float y, float z)
|
||||
{
|
||||
endVertex();
|
||||
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.POSITION;
|
||||
quadData[offset] = Float.floatToRawIntBits((float) x);
|
||||
quadData[offset + 1] = Float.floatToRawIntBits((float) y);
|
||||
@@ -62,7 +64,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer normal(float x, float y, float z)
|
||||
public VertexConsumer setNormal(float x, float y, float z)
|
||||
{
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.NORMAL;
|
||||
quadData[offset] = ((int) (x * 127.0f) & 0xFF) |
|
||||
@@ -72,7 +74,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer color(int r, int g, int b, int a)
|
||||
public VertexConsumer setColor(int r, int g, int b, int a)
|
||||
{
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.COLOR;
|
||||
quadData[offset] = ((a & 0xFF) << 24) |
|
||||
@@ -83,7 +85,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv(float u, float v)
|
||||
public VertexConsumer setUv(float u, float v)
|
||||
{
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.UV0;
|
||||
quadData[offset] = Float.floatToRawIntBits(u);
|
||||
@@ -92,7 +94,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer overlayCoords(int u, int v)
|
||||
public VertexConsumer setUv1(int u, int v)
|
||||
{
|
||||
if (IQuadTransformer.UV1 >= 0) // Vanilla doesn't support this, but it may be added by a 3rd party
|
||||
{
|
||||
@@ -103,7 +105,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv2(int u, int v)
|
||||
public VertexConsumer setUv2(int u, int v)
|
||||
{
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.UV2;
|
||||
quadData[offset] = (u & 0xFFFF) | ((v & 0xFFFF) << 16);
|
||||
@@ -122,27 +124,18 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVertex()
|
||||
private void endVertex()
|
||||
{
|
||||
if (++vertexIndex != 4)
|
||||
if (vertexIndex != 4) {
|
||||
++vertexIndex;
|
||||
return;
|
||||
}
|
||||
// We have a full quad, pass it to the consumer and reset
|
||||
quadConsumer.accept(new BakedQuad(quadData, tintIndex, direction, sprite, shade, hasAmbientOcclusion));
|
||||
vertexIndex = 0;
|
||||
quadData = new int[QUAD_DATA_SIZE];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultColor(int r, int g, int b, int a)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetDefaultColor()
|
||||
{
|
||||
}
|
||||
|
||||
public void setTintIndex(int tintIndex)
|
||||
{
|
||||
this.tintIndex = tintIndex;
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Vertex pipeline element that remaps incoming data to another format.
|
||||
*/
|
||||
public class RemappingVertexPipeline implements VertexConsumer
|
||||
{
|
||||
private static final Set<VertexFormatElement> KNOWN_ELEMENTS = Set.of(DefaultVertexFormat.ELEMENT_POSITION,
|
||||
DefaultVertexFormat.ELEMENT_COLOR, DefaultVertexFormat.ELEMENT_UV, DefaultVertexFormat.ELEMENT_UV1,
|
||||
DefaultVertexFormat.ELEMENT_UV2, DefaultVertexFormat.ELEMENT_NORMAL, DefaultVertexFormat.ELEMENT_PADDING);
|
||||
private static final int[] EMPTY_INT_ARRAY = new int[0];
|
||||
|
||||
private final VertexConsumer parent;
|
||||
private final VertexFormat targetFormat;
|
||||
|
||||
private final Vector3d position = new Vector3d();
|
||||
private final Vector3f normal = new Vector3f();
|
||||
private final int[] color = new int[] { 255, 255, 255, 255 };
|
||||
private final float[] uv0 = new float[] { 0, 0 };
|
||||
private final int[] uv1 = new int[] { OverlayTexture.NO_WHITE_U, OverlayTexture.WHITE_OVERLAY_V };
|
||||
private final int[] uv2 = new int[] { 0, 0 };
|
||||
|
||||
private final Map<VertexFormatElement, Integer> miscElementIds;
|
||||
private final int[][] misc;
|
||||
|
||||
public RemappingVertexPipeline(VertexConsumer parent, VertexFormat targetFormat)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.targetFormat = targetFormat;
|
||||
|
||||
this.miscElementIds = new IdentityHashMap<>();
|
||||
int i = 0;
|
||||
for (var element : targetFormat.getElements())
|
||||
if (element.getUsage() != VertexFormatElement.Usage.PADDING && !KNOWN_ELEMENTS.contains(element))
|
||||
this.miscElementIds.put(element, i++);
|
||||
this.misc = new int[i][];
|
||||
Arrays.fill(this.misc, EMPTY_INT_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer vertex(double x, double y, double z)
|
||||
{
|
||||
position.set(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer normal(float x, float y, float z)
|
||||
{
|
||||
normal.set(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer color(int r, int g, int b, int a)
|
||||
{
|
||||
color[0] = r;
|
||||
color[1] = g;
|
||||
color[2] = b;
|
||||
color[3] = a;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv(float u, float v)
|
||||
{
|
||||
uv0[0] = u;
|
||||
uv0[1] = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer overlayCoords(int u, int v)
|
||||
{
|
||||
uv1[0] = u;
|
||||
uv1[1] = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv2(int u, int v)
|
||||
{
|
||||
uv2[0] = u;
|
||||
uv2[1] = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer misc(VertexFormatElement element, int... values)
|
||||
{
|
||||
Integer id = miscElementIds.get(element);
|
||||
if (id != null)
|
||||
misc[id] = Arrays.copyOf(values, values.length);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVertex()
|
||||
{
|
||||
for (var element : targetFormat.getElements())
|
||||
{
|
||||
// Ignore padding
|
||||
if (element.getUsage() == VertexFormatElement.Usage.PADDING)
|
||||
continue;
|
||||
|
||||
// Try to match and output any of the supported elements, and if that fails, treat as misc
|
||||
if (element.equals(DefaultVertexFormat.ELEMENT_POSITION))
|
||||
parent.vertex(position.x, position.y, position.z);
|
||||
else if (element.equals(DefaultVertexFormat.ELEMENT_NORMAL))
|
||||
parent.normal(normal.x(), normal.y(), normal.z());
|
||||
else if (element.equals(DefaultVertexFormat.ELEMENT_COLOR))
|
||||
parent.color(color[0], color[1], color[2], color[3]);
|
||||
else if (element.equals(DefaultVertexFormat.ELEMENT_UV0))
|
||||
parent.uv(uv0[0], uv0[1]);
|
||||
else if (element.equals(DefaultVertexFormat.ELEMENT_UV1))
|
||||
parent.overlayCoords(uv1[0], uv1[1]);
|
||||
else if (element.equals(DefaultVertexFormat.ELEMENT_UV2))
|
||||
parent.uv2(uv2[0], uv2[1]);
|
||||
else
|
||||
parent.misc(element, misc[miscElementIds.get(element)]);
|
||||
}
|
||||
parent.endVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultColor(int r, int g, int b, int a)
|
||||
{
|
||||
parent.defaultColor(r, g, b, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetDefaultColor()
|
||||
{
|
||||
parent.unsetDefaultColor();
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -24,21 +24,21 @@ public class TransformingVertexPipeline extends VertexConsumerWrapper
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer vertex(double x, double y, double z)
|
||||
public VertexConsumer addVertex(float x, float y, float z)
|
||||
{
|
||||
var vec = new Vector4f((float) x, (float) y, (float) z, 1);
|
||||
transformation.transformPosition(vec);
|
||||
vec.div(vec.w);
|
||||
return super.vertex(vec.x(), vec.y(), vec.z());
|
||||
return super.addVertex(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer normal(float x, float y, float z)
|
||||
public VertexConsumer setNormal(float x, float y, float z)
|
||||
{
|
||||
var vec = new Vector3f(x, y, z);
|
||||
transformation.transformNormal(vec);
|
||||
vec.normalize();
|
||||
return super.normal(vec.x(), vec.y(), vec.z());
|
||||
return super.setNormal(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,44 +23,44 @@ public abstract class VertexConsumerWrapper implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer vertex(double x, double y, double z)
|
||||
public VertexConsumer addVertex(float x, float y, float z)
|
||||
{
|
||||
parent.vertex(x, y, z);
|
||||
parent.addVertex(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer color(int r, int g, int b, int a)
|
||||
public VertexConsumer setColor(int r, int g, int b, int a)
|
||||
{
|
||||
parent.color(r, g, b, a);
|
||||
parent.setColor(r, g, b, a);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv(float u, float v)
|
||||
public VertexConsumer setUv(float u, float v)
|
||||
{
|
||||
parent.uv(u, v);
|
||||
parent.setUv(u, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer overlayCoords(int u, int v)
|
||||
public VertexConsumer setUv1(int u, int v)
|
||||
{
|
||||
parent.overlayCoords(u, v);
|
||||
parent.setUv1(u, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv2(int u, int v)
|
||||
public VertexConsumer setUv2(int u, int v)
|
||||
{
|
||||
parent.uv2(u, v);
|
||||
parent.setUv2(u, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer normal(float x, float y, float z)
|
||||
public VertexConsumer setNormal(float x, float y, float z)
|
||||
{
|
||||
parent.normal(x, y, z);
|
||||
parent.setNormal(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -70,22 +70,4 @@ public abstract class VertexConsumerWrapper implements VertexConsumer
|
||||
parent.misc(element, values);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVertex()
|
||||
{
|
||||
parent.endVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultColor(int r, int g, int b, int a)
|
||||
{
|
||||
parent.defaultColor(r, g, b, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetDefaultColor()
|
||||
{
|
||||
parent.unsetDefaultColor();
|
||||
}
|
||||
}
|
||||
+11
-20
@@ -10,6 +10,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.RandomSource;
|
||||
@@ -30,42 +31,36 @@ import java.util.Arrays;
|
||||
*
|
||||
* @see Context
|
||||
*/
|
||||
public class BakedModelRenderable implements IRenderable<BakedModelRenderable.Context>
|
||||
{
|
||||
public class BakedModelRenderable implements IRenderable<BakedModelRenderable.Context> {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static BakedModelRenderable of(ResourceLocation model)
|
||||
{
|
||||
public static BakedModelRenderable of(ModelResourceLocation model) {
|
||||
return of(Minecraft.getInstance().getModelManager().getModel(model));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link BakedModelRenderable} from the given baked model.
|
||||
*/
|
||||
public static BakedModelRenderable of(BakedModel model)
|
||||
{
|
||||
public static BakedModelRenderable of(BakedModel model) {
|
||||
return new BakedModelRenderable(model);
|
||||
}
|
||||
|
||||
private final BakedModel model;
|
||||
|
||||
private BakedModelRenderable(BakedModel model)
|
||||
{
|
||||
private BakedModelRenderable(BakedModel model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack poseStack, MultiBufferSource bufferSource, ITextureRenderTypeLookup textureRenderTypeLookup, int lightmap, int overlay, float partialTick, Context context)
|
||||
{
|
||||
public void render(PoseStack poseStack, MultiBufferSource bufferSource, ITextureRenderTypeLookup textureRenderTypeLookup, int lightmap, int overlay, float partialTick, Context context) {
|
||||
var buffer = bufferSource.getBuffer(textureRenderTypeLookup.get(InventoryMenu.BLOCK_ATLAS));
|
||||
var tint = context.tint();
|
||||
var randomSource = context.randomSource();
|
||||
for (Direction direction : context.faces())
|
||||
{
|
||||
for (var direction : context.faces()) {
|
||||
randomSource.setSeed(context.seed());
|
||||
// Given the lack of context, the requested render type has to be null to ensure the model renders all of its geometry
|
||||
for (BakedQuad quad : model.getQuads(context.state(), direction, randomSource, context.data(), null))
|
||||
@@ -73,24 +68,20 @@ public class BakedModelRenderable implements IRenderable<BakedModelRenderable.Co
|
||||
}
|
||||
}
|
||||
|
||||
public IRenderable<Unit> withContext(ModelData modelData)
|
||||
{
|
||||
public IRenderable<Unit> withContext(ModelData modelData) {
|
||||
return withContext(new Context(modelData));
|
||||
}
|
||||
|
||||
public IRenderable<ModelData> withModelDataContext()
|
||||
{
|
||||
public IRenderable<ModelData> withModelDataContext() {
|
||||
return (poseStack, bufferSource, textureRenderTypeLookup, lightmap, overlay, partialTick, context) ->
|
||||
render(poseStack, bufferSource, textureRenderTypeLookup, lightmap, overlay, partialTick, new Context(context));
|
||||
}
|
||||
|
||||
public record Context(@Nullable BlockState state, Direction[] faces, RandomSource randomSource, long seed, ModelData data, Vector4f tint)
|
||||
{
|
||||
public record Context(@Nullable BlockState state, Direction[] faces, RandomSource randomSource, long seed, ModelData data, Vector4f tint) {
|
||||
private static final Direction[] ALL_FACES_AND_NULL = Arrays.copyOf(Direction.values(), Direction.values().length + 1);
|
||||
private static final Vector4f WHITE = new Vector4f(1, 1, 1, 1);
|
||||
|
||||
public Context(ModelData data)
|
||||
{
|
||||
public Context(ModelData data) {
|
||||
this(null, ALL_FACES_AND_NULL, RandomSource.create(), 42, data, WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user