mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 19:59:42 +00:00
1.21.3 update
This commit is contained in:
806 files changed
+6314
-10501
No files matched your search
@@ -7,8 +7,8 @@ package net.minecraftforge.client.model;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.model.BakedOverrides;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
@@ -31,116 +31,97 @@ import java.util.List;
|
||||
* <p>
|
||||
* Useful for creating wrapper baked models which only override certain properties.
|
||||
*/
|
||||
public abstract class BakedModelWrapper<T extends BakedModel> implements BakedModel
|
||||
{
|
||||
public abstract class BakedModelWrapper<T extends BakedModel> implements BakedModel {
|
||||
protected final T originalModel;
|
||||
|
||||
public BakedModelWrapper(T originalModel)
|
||||
{
|
||||
public BakedModelWrapper(T originalModel) {
|
||||
this.originalModel = originalModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand)
|
||||
{
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand) {
|
||||
return originalModel.getQuads(state, side, rand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion()
|
||||
{
|
||||
public boolean useAmbientOcclusion() {
|
||||
return originalModel.useAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion(BlockState state)
|
||||
{
|
||||
public boolean useAmbientOcclusion(BlockState state) {
|
||||
return originalModel.useAmbientOcclusion(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion(BlockState state, RenderType renderType)
|
||||
{
|
||||
public boolean useAmbientOcclusion(BlockState state, RenderType renderType) {
|
||||
return originalModel.useAmbientOcclusion(state, renderType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
public boolean isGui3d() {
|
||||
return originalModel.isGui3d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesBlockLight()
|
||||
{
|
||||
public boolean usesBlockLight() {
|
||||
return originalModel.usesBlockLight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomRenderer()
|
||||
{
|
||||
public boolean isCustomRenderer() {
|
||||
return originalModel.isCustomRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleIcon()
|
||||
{
|
||||
public TextureAtlasSprite getParticleIcon() {
|
||||
return originalModel.getParticleIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemTransforms getTransforms()
|
||||
{
|
||||
public ItemTransforms getTransforms() {
|
||||
return originalModel.getTransforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrides getOverrides()
|
||||
{
|
||||
return originalModel.getOverrides();
|
||||
public BakedOverrides overrides() {
|
||||
return originalModel.overrides();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel applyTransform(ItemDisplayContext cameraTransformType, PoseStack poseStack, boolean applyLeftHandTransform)
|
||||
{
|
||||
public BakedModel applyTransform(ItemDisplayContext cameraTransformType, PoseStack poseStack, boolean applyLeftHandTransform) {
|
||||
return originalModel.applyTransform(cameraTransformType, poseStack, applyLeftHandTransform);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleIcon(@NotNull ModelData data)
|
||||
{
|
||||
public TextureAtlasSprite getParticleIcon(@NotNull ModelData data) {
|
||||
return originalModel.getParticleIcon(data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull ModelData extraData, @Nullable RenderType renderType)
|
||||
{
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull ModelData extraData, @Nullable RenderType renderType) {
|
||||
return originalModel.getQuads(state, side, rand, extraData, renderType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull ModelData modelData)
|
||||
{
|
||||
public ModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull ModelData modelData) {
|
||||
return originalModel.getModelData(level, pos, state, modelData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull RandomSource rand, @NotNull ModelData data)
|
||||
{
|
||||
public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull RandomSource rand, @NotNull ModelData data) {
|
||||
return originalModel.getRenderTypes(state, rand, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RenderType> getRenderTypes(ItemStack itemStack, boolean fabulous)
|
||||
{
|
||||
public List<RenderType> getRenderTypes(ItemStack itemStack, boolean fabulous) {
|
||||
return originalModel.getRenderTypes(itemStack, fabulous);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedModel> getRenderPasses(ItemStack itemStack, boolean fabulous)
|
||||
{
|
||||
public List<BakedModel> getRenderPasses(ItemStack itemStack, boolean fabulous) {
|
||||
return originalModel.getRenderPasses(itemStack, fabulous);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import java.util.function.Function;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
@@ -33,7 +32,6 @@ import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
@@ -56,20 +54,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
* These respect component visibility as specified in {@link IGeometryBakingContext} and can additionally be provided
|
||||
* with an item-specific render ordering, for multi-pass arrangements.
|
||||
*/
|
||||
public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
{
|
||||
public class CompositeModel implements IUnbakedGeometry<CompositeModel> {
|
||||
private final ImmutableMap<String, BlockModel> children;
|
||||
private final ImmutableList<String> itemPasses;
|
||||
|
||||
public CompositeModel(ImmutableMap<String, BlockModel> children, ImmutableList<String> itemPasses)
|
||||
{
|
||||
public CompositeModel(ImmutableMap<String, BlockModel> children, ImmutableList<String> itemPasses) {
|
||||
this.children = children;
|
||||
this.itemPasses = itemPasses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState) {
|
||||
Material particleLocation = context.getMaterial("particle");
|
||||
TextureAtlasSprite particle = spriteGetter.apply(particleLocation);
|
||||
|
||||
@@ -78,13 +73,12 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
modelState = UnbakedGeometryHelper.composeRootTransformIntoModelState(modelState, rootTransform);
|
||||
|
||||
var bakedPartsBuilder = ImmutableMap.<String, BakedModel>builder();
|
||||
for (var entry : children.entrySet())
|
||||
{
|
||||
for (var entry : children.entrySet()) {
|
||||
var name = entry.getKey();
|
||||
if (!context.isComponentVisible(name, true))
|
||||
continue;
|
||||
var model = entry.getValue();
|
||||
bakedPartsBuilder.put(name, model.bake(baker, model, spriteGetter, modelState, true));
|
||||
bakedPartsBuilder.put(name, model.bake(baker, spriteGetter, modelState));
|
||||
}
|
||||
var bakedParts = bakedPartsBuilder.build();
|
||||
|
||||
@@ -97,53 +91,44 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
itemPassesBuilder.add(model);
|
||||
}
|
||||
|
||||
return new Baked(context.isGui3d(), context.useBlockLight(), context.useAmbientOcclusion(), particle, context.getTransforms(), overrides, bakedParts, itemPassesBuilder.build());
|
||||
return new Baked(context.isGui3d(), context.useBlockLight(), context.useAmbientOcclusion(), particle, context.getTransforms(), bakedParts, itemPassesBuilder.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveParents(Function<ResourceLocation, UnbakedModel> modelGetter, IGeometryBakingContext context)
|
||||
{
|
||||
children.values().forEach(child -> child.resolveParents(modelGetter));
|
||||
public void resolveDependencies(UnbakedModel.Resolver resolver, IGeometryBakingContext context) {
|
||||
children.values().forEach(child -> child.resolveDependencies(resolver));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getConfigurableComponentNames()
|
||||
{
|
||||
public Set<String> getConfigurableComponentNames() {
|
||||
return children.keySet();
|
||||
}
|
||||
|
||||
public static class Baked implements IDynamicBakedModel
|
||||
{
|
||||
public static class Baked implements IDynamicBakedModel {
|
||||
private final boolean isAmbientOcclusion;
|
||||
private final boolean isGui3d;
|
||||
private final boolean isSideLit;
|
||||
private final TextureAtlasSprite particle;
|
||||
private final ItemOverrides overrides;
|
||||
private final ItemTransforms transforms;
|
||||
private final ImmutableMap<String, BakedModel> children;
|
||||
private final ImmutableList<BakedModel> itemPasses;
|
||||
|
||||
public Baked(boolean isGui3d, boolean isSideLit, boolean isAmbientOcclusion, TextureAtlasSprite particle, ItemTransforms transforms, ItemOverrides overrides, ImmutableMap<String, BakedModel> children, ImmutableList<BakedModel> itemPasses)
|
||||
{
|
||||
public Baked(boolean isGui3d, boolean isSideLit, boolean isAmbientOcclusion, TextureAtlasSprite particle, ItemTransforms transforms, ImmutableMap<String, BakedModel> children, ImmutableList<BakedModel> itemPasses) {
|
||||
this.children = children;
|
||||
this.isAmbientOcclusion = isAmbientOcclusion;
|
||||
this.isGui3d = isGui3d;
|
||||
this.isSideLit = isSideLit;
|
||||
this.particle = particle;
|
||||
this.overrides = overrides;
|
||||
this.transforms = transforms;
|
||||
this.itemPasses = itemPasses;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull ModelData data, @Nullable RenderType renderType)
|
||||
{
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull ModelData data, @Nullable RenderType renderType) {
|
||||
List<List<BakedQuad>> quadLists = new ArrayList<>();
|
||||
for (Map.Entry<String, BakedModel> entry : children.entrySet())
|
||||
{
|
||||
if (renderType == null || (state != null && entry.getValue().getRenderTypes(state, rand, data).contains(renderType)))
|
||||
{
|
||||
for (Map.Entry<String, BakedModel> entry : children.entrySet()) {
|
||||
if (renderType == null || (state != null && entry.getValue().getRenderTypes(state, rand, data).contains(renderType))) {
|
||||
quadLists.add(entry.getValue().getQuads(state, side, rand, CompositeModel.Data.resolve(data, entry.getKey()), renderType));
|
||||
}
|
||||
}
|
||||
@@ -151,8 +136,7 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull ModelData modelData)
|
||||
{
|
||||
public @NotNull ModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull ModelData modelData) {
|
||||
var builder = Data.builder();
|
||||
for (var entry : children.entrySet())
|
||||
builder.with(entry.getKey(), entry.getValue().getModelData(level, pos, state, Data.resolve(modelData, entry.getKey())));
|
||||
@@ -160,50 +144,37 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion()
|
||||
{
|
||||
public boolean useAmbientOcclusion() {
|
||||
return isAmbientOcclusion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
public boolean isGui3d() {
|
||||
return isGui3d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesBlockLight()
|
||||
{
|
||||
public boolean usesBlockLight() {
|
||||
return isSideLit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomRenderer()
|
||||
{
|
||||
public boolean isCustomRenderer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleIcon()
|
||||
{
|
||||
public TextureAtlasSprite getParticleIcon() {
|
||||
return particle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrides getOverrides()
|
||||
{
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemTransforms getTransforms()
|
||||
{
|
||||
public ItemTransforms getTransforms() {
|
||||
return transforms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull RandomSource rand, @NotNull ModelData data)
|
||||
{
|
||||
public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull RandomSource rand, @NotNull ModelData data) {
|
||||
var sets = new ArrayList<ChunkRenderTypeSet>();
|
||||
for (Map.Entry<String, BakedModel> entry : children.entrySet())
|
||||
sets.add(entry.getValue().getRenderTypes(state, rand, CompositeModel.Data.resolve(data, entry.getKey())));
|
||||
@@ -211,68 +182,55 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedModel> getRenderPasses(ItemStack itemStack, boolean fabulous)
|
||||
{
|
||||
public List<BakedModel> getRenderPasses(ItemStack itemStack, boolean fabulous) {
|
||||
return itemPasses;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BakedModel getPart(String name)
|
||||
{
|
||||
public BakedModel getPart(String name) {
|
||||
return children.get(name);
|
||||
}
|
||||
|
||||
public static Builder builder(IGeometryBakingContext owner, TextureAtlasSprite particle, ItemOverrides overrides, ItemTransforms cameraTransforms)
|
||||
{
|
||||
return builder(owner.useAmbientOcclusion(), owner.isGui3d(), owner.useBlockLight(), particle, overrides, cameraTransforms);
|
||||
public static Builder builder(IGeometryBakingContext owner, TextureAtlasSprite particle, ItemTransforms cameraTransforms) {
|
||||
return builder(owner.useAmbientOcclusion(), owner.isGui3d(), owner.useBlockLight(), particle, cameraTransforms);
|
||||
}
|
||||
|
||||
public static Builder builder(boolean isAmbientOcclusion, boolean isGui3d, boolean isSideLit, TextureAtlasSprite particle, ItemOverrides overrides, ItemTransforms cameraTransforms)
|
||||
{
|
||||
return new Builder(isAmbientOcclusion, isGui3d, isSideLit, particle, overrides, cameraTransforms);
|
||||
public static Builder builder(boolean isAmbientOcclusion, boolean isGui3d, boolean isSideLit, TextureAtlasSprite particle, ItemTransforms cameraTransforms) {
|
||||
return new Builder(isAmbientOcclusion, isGui3d, isSideLit, particle, cameraTransforms);
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
public static class Builder {
|
||||
private final boolean isAmbientOcclusion;
|
||||
private final boolean isGui3d;
|
||||
private final boolean isSideLit;
|
||||
private final List<BakedModel> children = new ArrayList<>();
|
||||
private final List<BakedQuad> quads = new ArrayList<>();
|
||||
private final ItemOverrides overrides;
|
||||
private final ItemTransforms transforms;
|
||||
private TextureAtlasSprite particle;
|
||||
private RenderTypeGroup lastRenderTypes = RenderTypeGroup.EMPTY;
|
||||
|
||||
private Builder(boolean isAmbientOcclusion, boolean isGui3d, boolean isSideLit, TextureAtlasSprite particle, ItemOverrides overrides, ItemTransforms transforms)
|
||||
{
|
||||
private Builder(boolean isAmbientOcclusion, boolean isGui3d, boolean isSideLit, TextureAtlasSprite particle, ItemTransforms transforms) {
|
||||
this.isAmbientOcclusion = isAmbientOcclusion;
|
||||
this.isGui3d = isGui3d;
|
||||
this.isSideLit = isSideLit;
|
||||
this.particle = particle;
|
||||
this.overrides = overrides;
|
||||
this.transforms = transforms;
|
||||
}
|
||||
|
||||
public void addLayer(BakedModel model)
|
||||
{
|
||||
public void addLayer(BakedModel model) {
|
||||
flushQuads(null);
|
||||
children.add(model);
|
||||
}
|
||||
|
||||
private void addLayer(RenderTypeGroup renderTypes, List<BakedQuad> quads)
|
||||
{
|
||||
var modelBuilder = IModelBuilder.of(isAmbientOcclusion, isSideLit, isGui3d, transforms, overrides, particle, renderTypes);
|
||||
private void addLayer(RenderTypeGroup renderTypes, List<BakedQuad> quads) {
|
||||
var modelBuilder = IModelBuilder.of(isAmbientOcclusion, isSideLit, isGui3d, transforms, particle, renderTypes);
|
||||
quads.forEach(modelBuilder::addUnculledFace);
|
||||
children.add(modelBuilder.build());
|
||||
}
|
||||
|
||||
private void flushQuads(RenderTypeGroup renderTypes)
|
||||
{
|
||||
if (!Objects.equals(renderTypes, lastRenderTypes))
|
||||
{
|
||||
if (!quads.isEmpty())
|
||||
{
|
||||
private void flushQuads(RenderTypeGroup renderTypes) {
|
||||
if (!Objects.equals(renderTypes, lastRenderTypes)) {
|
||||
if (!quads.isEmpty()) {
|
||||
addLayer(lastRenderTypes, quads);
|
||||
quads.clear();
|
||||
}
|
||||
@@ -280,41 +238,35 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
}
|
||||
}
|
||||
|
||||
public Builder setParticle(TextureAtlasSprite particleSprite)
|
||||
{
|
||||
public Builder setParticle(TextureAtlasSprite particleSprite) {
|
||||
this.particle = particleSprite;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addQuads(RenderTypeGroup renderTypes, BakedQuad... quadsToAdd)
|
||||
{
|
||||
public Builder addQuads(RenderTypeGroup renderTypes, BakedQuad... quadsToAdd) {
|
||||
flushQuads(renderTypes);
|
||||
Collections.addAll(quads, quadsToAdd);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addQuads(RenderTypeGroup renderTypes, Collection<BakedQuad> quadsToAdd)
|
||||
{
|
||||
public Builder addQuads(RenderTypeGroup renderTypes, Collection<BakedQuad> quadsToAdd) {
|
||||
flushQuads(renderTypes);
|
||||
quads.addAll(quadsToAdd);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BakedModel build()
|
||||
{
|
||||
if (!quads.isEmpty())
|
||||
{
|
||||
public BakedModel build() {
|
||||
if (!quads.isEmpty()) {
|
||||
addLayer(lastRenderTypes, quads);
|
||||
}
|
||||
var childrenBuilder = ImmutableMap.<String, BakedModel>builder();
|
||||
var itemPassesBuilder = ImmutableList.<BakedModel>builder();
|
||||
int i = 0;
|
||||
for (var model : this.children)
|
||||
{
|
||||
for (var model : this.children) {
|
||||
childrenBuilder.put("model_" + (i++), model);
|
||||
itemPassesBuilder.add(model);
|
||||
}
|
||||
return new Baked(isGui3d, isSideLit, isAmbientOcclusion, particle, transforms, overrides, childrenBuilder.build(), itemPassesBuilder.build());
|
||||
return new Baked(isGui3d, isSideLit, isAmbientOcclusion, particle, transforms, childrenBuilder.build(), itemPassesBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,20 +275,17 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
/**
|
||||
* A model data container which stores data for child components.
|
||||
*/
|
||||
public static class Data
|
||||
{
|
||||
public static class Data {
|
||||
public static final ModelProperty<Data> PROPERTY = new ModelProperty<>();
|
||||
|
||||
private final Map<String, ModelData> partData;
|
||||
|
||||
private Data(Map<String, ModelData> partData)
|
||||
{
|
||||
private Data(Map<String, ModelData> partData) {
|
||||
this.partData = partData;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ModelData get(String name)
|
||||
{
|
||||
public ModelData get(String name) {
|
||||
return partData.get(name);
|
||||
}
|
||||
|
||||
@@ -347,8 +296,7 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
* @param name The name of the part to get data for
|
||||
* @return The data for the part, or the one passed in if not found
|
||||
*/
|
||||
public static ModelData resolve(ModelData modelData, String name)
|
||||
{
|
||||
public static ModelData resolve(ModelData modelData, String name) {
|
||||
var compositeData = modelData.get(PROPERTY);
|
||||
if (compositeData == null)
|
||||
return modelData;
|
||||
@@ -356,39 +304,31 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
return partData != null ? partData : modelData;
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
{
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static final class Builder
|
||||
{
|
||||
public static final class Builder {
|
||||
private final Map<String, ModelData> partData = new IdentityHashMap<>();
|
||||
|
||||
public Builder with(String name, ModelData data)
|
||||
{
|
||||
public Builder with(String name, ModelData data) {
|
||||
partData.put(name, data);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Data build()
|
||||
{
|
||||
public Data build() {
|
||||
return new Data(partData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Loader implements IGeometryLoader<CompositeModel>
|
||||
{
|
||||
public static final class Loader implements IGeometryLoader<CompositeModel> {
|
||||
public static final Loader INSTANCE = new Loader();
|
||||
|
||||
private Loader()
|
||||
{
|
||||
}
|
||||
private Loader() { }
|
||||
|
||||
@Override
|
||||
public CompositeModel read(JsonObject jsonObject, JsonDeserializationContext deserializationContext)
|
||||
{
|
||||
public CompositeModel read(JsonObject jsonObject, JsonDeserializationContext deserializationContext) {
|
||||
List<String> itemPasses = new ArrayList<>();
|
||||
ImmutableMap.Builder<String, BlockModel> childrenBuilder = ImmutableMap.builder();
|
||||
readChildren(jsonObject, "children", deserializationContext, childrenBuilder, itemPasses);
|
||||
@@ -397,8 +337,7 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
if (children.isEmpty())
|
||||
throw new JsonParseException("Composite model requires a \"children\" element with at least one element.");
|
||||
|
||||
if (jsonObject.has("item_render_order"))
|
||||
{
|
||||
if (jsonObject.has("item_render_order")) {
|
||||
itemPasses.clear();
|
||||
for (var element : jsonObject.getAsJsonArray("item_render_order"))
|
||||
{
|
||||
@@ -412,13 +351,11 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
|
||||
return new CompositeModel(children, ImmutableList.copyOf(itemPasses));
|
||||
}
|
||||
|
||||
private void readChildren(JsonObject jsonObject, String name, JsonDeserializationContext deserializationContext, ImmutableMap.Builder<String, BlockModel> children, List<String> itemPasses)
|
||||
{
|
||||
private void readChildren(JsonObject jsonObject, String name, JsonDeserializationContext deserializationContext, ImmutableMap.Builder<String, BlockModel> children, List<String> itemPasses) {
|
||||
if (!jsonObject.has(name))
|
||||
return;
|
||||
var childrenJsonObject = jsonObject.getAsJsonObject(name);
|
||||
for (Map.Entry<String, JsonElement> entry : childrenJsonObject.entrySet())
|
||||
{
|
||||
for (Map.Entry<String, JsonElement> entry : childrenJsonObject.entrySet()) {
|
||||
children.put(entry.getKey(), deserializationContext.deserialize(entry.getValue(), BlockModel.class));
|
||||
itemPasses.add(entry.getKey()); // We can do this because GSON preserves ordering during deserialization
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.mojang.math.Transformation;
|
||||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.BakedOverrides;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||
@@ -56,8 +56,7 @@ import static net.minecraftforge.client.model.geometry.StandaloneGeometryBakingC
|
||||
*
|
||||
* @see Colors
|
||||
*/
|
||||
public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluidContainerModel>
|
||||
{
|
||||
public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluidContainerModel> {
|
||||
// Depth offsets to prevent Z-fighting
|
||||
private static final Transformation FLUID_TRANSFORM = new Transformation(new Vector3f(), new Quaternionf(), new Vector3f(1, 1, 1.002f), new Quaternionf());
|
||||
private static final Transformation COVER_TRANSFORM = new Transformation(new Vector3f(), new Quaternionf(), new Vector3f(1, 1, 1.004f), new Quaternionf());
|
||||
@@ -67,16 +66,14 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
private final boolean coverIsMask;
|
||||
private final boolean applyFluidLuminosity;
|
||||
|
||||
private DynamicFluidContainerModel(Fluid fluid, boolean flipGas, boolean coverIsMask, boolean applyFluidLuminosity)
|
||||
{
|
||||
private DynamicFluidContainerModel(Fluid fluid, boolean flipGas, boolean coverIsMask, boolean applyFluidLuminosity) {
|
||||
this.fluid = fluid;
|
||||
this.flipGas = flipGas;
|
||||
this.coverIsMask = coverIsMask;
|
||||
this.applyFluidLuminosity = applyFluidLuminosity;
|
||||
}
|
||||
|
||||
public static RenderTypeGroup getLayerRenderTypes(boolean unlit)
|
||||
{
|
||||
public static RenderTypeGroup getLayerRenderTypes(boolean unlit) {
|
||||
return new RenderTypeGroup(RenderType.translucent(), unlit ? ForgeRenderTypes.ITEM_UNSORTED_UNLIT_TRANSLUCENT.get() : ForgeRenderTypes.ITEM_UNSORTED_TRANSLUCENT.get());
|
||||
}
|
||||
|
||||
@@ -84,14 +81,12 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
* Returns a new ModelDynBucket representing the given fluid, but with the same
|
||||
* other properties (flipGas, tint, coverIsMask).
|
||||
*/
|
||||
public DynamicFluidContainerModel withFluid(Fluid newFluid)
|
||||
{
|
||||
public DynamicFluidContainerModel withFluid(Fluid newFluid) {
|
||||
return new DynamicFluidContainerModel(newFluid, flipGas, coverIsMask, applyFluidLuminosity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState) {
|
||||
Material particleLocation = context.hasMaterial("particle") ? context.getMaterial("particle") : null;
|
||||
Material baseLocation = context.hasMaterial("base") ? context.getMaterial("base") : null;
|
||||
Material fluidMaskLocation = context.hasMaterial("fluid") ? context.getMaterial("fluid") : null;
|
||||
@@ -108,8 +103,7 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
if (particleSprite == null && !coverIsMask) particleSprite = coverSprite;
|
||||
|
||||
// If the fluid is lighter than air, rotate 180deg to turn it upside down
|
||||
if (flipGas && fluid != Fluids.EMPTY && fluid.getFluidType().isLighterThanAir())
|
||||
{
|
||||
if (flipGas && fluid != Fluids.EMPTY && fluid.getFluidType().isLighterThanAir()) {
|
||||
modelState = new SimpleModelState(
|
||||
modelState.getRotation().compose(
|
||||
new Transformation(null, new Quaternionf(0, 0, 1, 0), null, null)));
|
||||
@@ -117,23 +111,20 @@ 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(LOCATION);
|
||||
var modelBuilder = CompositeModel.Baked.builder(itemContext, particleSprite, new ContainedFluidOverrideHandler(overrides, baker, itemContext, this), context.getTransforms());
|
||||
var modelBuilder = CompositeModel.Baked.builder(itemContext, particleSprite, /*new ContainedFluidOverrideHandler(baker, itemContext, this),*/ context.getTransforms());
|
||||
|
||||
var normalRenderTypes = getLayerRenderTypes(false);
|
||||
|
||||
if (baseLocation != null && baseSprite != null)
|
||||
{
|
||||
if (baseLocation != null && baseSprite != null) {
|
||||
// Base texture
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemElements(0, baseSprite.contents());
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> baseSprite, modelState);
|
||||
modelBuilder.addQuads(normalRenderTypes, quads);
|
||||
}
|
||||
|
||||
if (fluidMaskLocation != null && fluidSprite != null)
|
||||
{
|
||||
if (fluidMaskLocation != null && fluidSprite != null) {
|
||||
TextureAtlasSprite templateSprite = spriteGetter.apply(fluidMaskLocation);
|
||||
if (templateSprite != null)
|
||||
{
|
||||
if (templateSprite != null) {
|
||||
// Fluid layer
|
||||
var transformedState = new SimpleModelState(modelState.getRotation().compose(FLUID_TRANSFORM), modelState.isUvLocked());
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemMaskElements(1, templateSprite.contents()); // Use template as mask
|
||||
@@ -147,11 +138,9 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
}
|
||||
}
|
||||
|
||||
if (coverSprite != null)
|
||||
{
|
||||
if (coverSprite != null) {
|
||||
var sprite = coverIsMask ? baseSprite : coverSprite;
|
||||
if (sprite != null)
|
||||
{
|
||||
if (sprite != null) {
|
||||
// Cover/overlay
|
||||
var transformedState = new SimpleModelState(modelState.getRotation().compose(COVER_TRANSFORM), modelState.isUvLocked());
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemMaskElements(2, coverSprite.contents()); // Use cover as mask
|
||||
@@ -192,16 +181,14 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ContainedFluidOverrideHandler extends ItemOverrides
|
||||
{
|
||||
private static final class ContainedFluidOverrideHandler extends BakedOverrides {
|
||||
private final Map<String, BakedModel> cache = Maps.newHashMap(); // contains all the baked models since they'll never change
|
||||
private final ItemOverrides nested;
|
||||
private final BakedOverrides nested;
|
||||
private final ModelBaker baker;
|
||||
private final IGeometryBakingContext owner;
|
||||
private final DynamicFluidContainerModel parent;
|
||||
|
||||
private ContainedFluidOverrideHandler(ItemOverrides nested, ModelBaker baker, IGeometryBakingContext owner, DynamicFluidContainerModel parent)
|
||||
{
|
||||
private ContainedFluidOverrideHandler(BakedOverrides nested, ModelBaker baker, IGeometryBakingContext owner, DynamicFluidContainerModel parent) {
|
||||
this.nested = nested;
|
||||
this.baker = baker;
|
||||
this.owner = owner;
|
||||
@@ -209,35 +196,32 @@ public class DynamicFluidContainerModel implements IUnbakedGeometry<DynamicFluid
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel resolve(BakedModel originalModel, ItemStack stack, @Nullable ClientLevel level, @Nullable LivingEntity entity, int seed)
|
||||
{
|
||||
BakedModel overridden = nested.resolve(originalModel, stack, level, entity, seed);
|
||||
if (overridden != originalModel) return overridden;
|
||||
return FluidUtil.getFluidContained(stack)
|
||||
.map(fluidStack -> {
|
||||
Fluid fluid = fluidStack.getFluid();
|
||||
String name = ForgeRegistries.FLUIDS.getKey(fluid).toString();
|
||||
public BakedModel findOverride(ItemStack stack, @Nullable ClientLevel level, @Nullable LivingEntity entity, int seed) {
|
||||
BakedModel overridden = nested.findOverride(stack, level, entity, seed);
|
||||
if (overridden != null)
|
||||
return overridden;
|
||||
|
||||
if (!cache.containsKey(name))
|
||||
{
|
||||
DynamicFluidContainerModel unbaked = this.parent.withFluid(fluid);
|
||||
BakedModel bakedModel = unbaked.bake(owner, baker, Material::sprite, BlockModelRotation.X0_Y0, originalModel.getOverrides());
|
||||
cache.put(name, bakedModel);
|
||||
return bakedModel;
|
||||
}
|
||||
var fluidStack = FluidUtil.getFluidContained(stack).orElse(null);
|
||||
if (fluidStack == null)
|
||||
return null;
|
||||
|
||||
return cache.get(name);
|
||||
})
|
||||
// not a fluid item apparently
|
||||
.orElse(originalModel); // empty bucket
|
||||
Fluid fluid = fluidStack.getFluid();
|
||||
String name = ForgeRegistries.FLUIDS.getKey(fluid).toString();
|
||||
|
||||
if (!cache.containsKey(name)) {
|
||||
DynamicFluidContainerModel unbaked = this.parent.withFluid(fluid);
|
||||
BakedModel bakedModel = unbaked.bake(owner, baker, Material::sprite, BlockModelRotation.X0_Y0);//, nested);
|
||||
cache.put(name, bakedModel);
|
||||
return bakedModel;
|
||||
}
|
||||
|
||||
return cache.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Colors implements ItemColor
|
||||
{
|
||||
public static class Colors implements ItemColor {
|
||||
@Override
|
||||
public int getColor(@NotNull ItemStack stack, int tintIndex)
|
||||
{
|
||||
public int getColor(@NotNull ItemStack stack, int tintIndex) {
|
||||
if (tintIndex != 1) return 0xFFFFFFFF;
|
||||
return FluidUtil.getFluidContained(stack)
|
||||
.map(fluidStack -> IClientFluidTypeExtensions.of(fluidStack.getFluid()).getTintColor(fluidStack))
|
||||
|
||||
@@ -5,24 +5,18 @@
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBaker;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.SimpleBakedModel;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraftforge.client.RenderTypeGroup;
|
||||
import net.minecraftforge.client.model.geometry.IGeometryBakingContext;
|
||||
import net.minecraftforge.client.model.geometry.IGeometryLoader;
|
||||
@@ -35,40 +29,32 @@ import net.minecraftforge.client.textures.UnitTextureAtlasSprite;
|
||||
* <p>
|
||||
* You can access it as a {@link BakedModel}, an {@link IUnbakedGeometry} or an {@link IGeometryLoader}.
|
||||
*/
|
||||
public class EmptyModel extends SimpleUnbakedGeometry<EmptyModel>
|
||||
{
|
||||
public class EmptyModel extends SimpleUnbakedGeometry<EmptyModel> {
|
||||
public static final BakedModel BAKED = new Baked();
|
||||
public static final EmptyModel INSTANCE = new EmptyModel();
|
||||
public static final IGeometryLoader<EmptyModel> LOADER = (json, ctx) -> INSTANCE;
|
||||
|
||||
private EmptyModel()
|
||||
{
|
||||
}
|
||||
private EmptyModel() { }
|
||||
|
||||
@Override
|
||||
protected void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform)
|
||||
{
|
||||
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)
|
||||
{
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState) {
|
||||
return BAKED;
|
||||
}
|
||||
|
||||
private static class Baked extends SimpleBakedModel
|
||||
{
|
||||
private static final Material MISSING_TEXTURE = new Material(TextureAtlas.LOCATION_BLOCKS, MissingTextureAtlasSprite.getLocation());
|
||||
private static class Baked extends SimpleBakedModel {
|
||||
private static final Material MISSING_TEXTURE = new Material(InventoryMenu.BLOCK_ATLAS, MissingTextureAtlasSprite.getLocation());
|
||||
|
||||
public Baked()
|
||||
{
|
||||
super(List.of(), Map.of(), false, false, false, UnitTextureAtlasSprite.INSTANCE, ItemTransforms.NO_TRANSFORMS, ItemOverrides.EMPTY, RenderTypeGroup.EMPTY);
|
||||
public Baked() {
|
||||
super(List.of(), Map.of(), false, false, false, UnitTextureAtlasSprite.INSTANCE, ItemTransforms.NO_TRANSFORMS, RenderTypeGroup.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleIcon()
|
||||
{
|
||||
public TextureAtlasSprite getParticleIcon() {
|
||||
return MISSING_TEXTURE.sprite();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.client.renderer.ItemModelShaper;
|
||||
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.core.Holder;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Wrapper around {@link ItemModelShaper} that cleans up the internal maps to respect ID remapping.
|
||||
*/
|
||||
public class ForgeItemModelShaper extends ItemModelShaper {
|
||||
private final Map<Holder.Reference<Item>, ModelResourceLocation> locations = Maps.newHashMap();
|
||||
private final Map<Holder.Reference<Item>, BakedModel> models = Maps.newHashMap();
|
||||
|
||||
public ForgeItemModelShaper(ModelManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public BakedModel getItemModel(Item item) {
|
||||
return models.get(ForgeRegistries.ITEMS.getDelegateOrThrow(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Item item, ModelResourceLocation location) {
|
||||
Holder.Reference<Item> key = ForgeRegistries.ITEMS.getDelegateOrThrow(item);
|
||||
locations.put(key, location);
|
||||
models.put(key, getModelManager().getModel(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebuildCache() {
|
||||
final ModelManager manager = this.getModelManager();
|
||||
for (Map.Entry<Holder.Reference<Item>, ModelResourceLocation> e : locations.entrySet()) {
|
||||
models.put(e.getKey(), manager.getModel(e.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
public ModelResourceLocation getLocation(@NotNull ItemStack stack) {
|
||||
ModelResourceLocation location = locations.get(ForgeRegistries.ITEMS.getDelegateOrThrow(stack.getItem()));
|
||||
return location == null ? ModelBakery.MISSING_MODEL_VARIANT : location;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
@@ -22,24 +21,22 @@ import java.util.List;
|
||||
* Provides a generic base implementation via {@link #of(boolean, boolean, boolean, ItemTransforms, ItemOverrides, TextureAtlasSprite, RenderTypeGroup)}
|
||||
* and a quad-collecting alternative via {@link #collecting(List)}.
|
||||
*/
|
||||
public interface IModelBuilder<T extends IModelBuilder<T>>
|
||||
{
|
||||
public interface IModelBuilder<T extends IModelBuilder<T>> {
|
||||
/**
|
||||
* Creates a new model builder that uses the provided attributes in the final baked model.
|
||||
*/
|
||||
static IModelBuilder<?> of(boolean hasAmbientOcclusion, boolean usesBlockLight, boolean isGui3d,
|
||||
ItemTransforms transforms, ItemOverrides overrides, TextureAtlasSprite particle,
|
||||
RenderTypeGroup renderTypes)
|
||||
{
|
||||
return new Simple(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, overrides, particle, renderTypes);
|
||||
ItemTransforms transforms, TextureAtlasSprite particle,
|
||||
RenderTypeGroup renderTypes
|
||||
){
|
||||
return new Simple(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, renderTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new model builder that collects quads to the provided list, returning
|
||||
* {@linkplain EmptyModel#BAKED an empty model} if you call {@link #build()}.
|
||||
*/
|
||||
static IModelBuilder<?> collecting(List<BakedQuad> quads)
|
||||
{
|
||||
static IModelBuilder<?> collecting(List<BakedQuad> quads) {
|
||||
return new Collecting(quads);
|
||||
}
|
||||
|
||||
@@ -49,69 +46,58 @@ public interface IModelBuilder<T extends IModelBuilder<T>>
|
||||
|
||||
BakedModel build();
|
||||
|
||||
class Simple implements IModelBuilder<Simple>
|
||||
{
|
||||
class Simple implements IModelBuilder<Simple> {
|
||||
private final SimpleBakedModel.Builder builder;
|
||||
private final RenderTypeGroup renderTypes;
|
||||
|
||||
private Simple(boolean hasAmbientOcclusion, boolean usesBlockLight, boolean isGui3d,
|
||||
ItemTransforms transforms, ItemOverrides overrides, TextureAtlasSprite particle,
|
||||
RenderTypeGroup renderTypes)
|
||||
{
|
||||
this.builder = new SimpleBakedModel.Builder(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, overrides).particle(particle);
|
||||
ItemTransforms transforms, TextureAtlasSprite particle, RenderTypeGroup renderTypes
|
||||
) {
|
||||
this.builder = new SimpleBakedModel.Builder(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms).particle(particle);
|
||||
this.renderTypes = renderTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Simple addCulledFace(Direction facing, BakedQuad quad)
|
||||
{
|
||||
public Simple addCulledFace(Direction facing, BakedQuad quad) {
|
||||
builder.addCulledFace(facing, quad);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Simple addUnculledFace(BakedQuad quad)
|
||||
{
|
||||
public Simple addUnculledFace(BakedQuad quad) {
|
||||
builder.addUnculledFace(quad);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public BakedModel build()
|
||||
{
|
||||
public BakedModel build() {
|
||||
return builder.renderTypes(renderTypes).build();
|
||||
}
|
||||
}
|
||||
|
||||
class Collecting implements IModelBuilder<Collecting>
|
||||
{
|
||||
class Collecting implements IModelBuilder<Collecting> {
|
||||
private final List<BakedQuad> quads;
|
||||
|
||||
private Collecting(List<BakedQuad> quads)
|
||||
{
|
||||
private Collecting(List<BakedQuad> quads) {
|
||||
this.quads = quads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collecting addCulledFace(Direction facing, BakedQuad quad)
|
||||
{
|
||||
public Collecting addCulledFace(Direction facing, BakedQuad quad) {
|
||||
quads.add(quad);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collecting addUnculledFace(BakedQuad quad)
|
||||
{
|
||||
public Collecting addUnculledFace(BakedQuad quad) {
|
||||
quads.add(quad);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel build()
|
||||
{
|
||||
public BakedModel build() {
|
||||
return EmptyModel.BAKED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public interface IQuadTransformer {
|
||||
|
||||
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());
|
||||
return new BakedQuad(Arrays.copyOf(vertices, vertices.length), quad.getTintIndex(), quad.getDirection(), quad.getSprite(), quad.isShade(), quad.getLightEmission(), quad.hasAmbientOcclusion());
|
||||
}
|
||||
|
||||
private static int findOffset(VertexFormatElement element) {
|
||||
|
||||
@@ -7,14 +7,12 @@ package net.minecraftforge.client.model;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.model.ItemModelGenerator;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
@@ -29,7 +27,6 @@ import net.minecraftforge.client.model.geometry.IUnbakedGeometry;
|
||||
import net.minecraftforge.client.model.geometry.UnbakedGeometryHelper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@@ -38,43 +35,36 @@ import java.util.function.Function;
|
||||
* - Not limited to an arbitrary number of layers (5)
|
||||
* - Support for per-layer render types
|
||||
*/
|
||||
public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel>
|
||||
{
|
||||
public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel> {
|
||||
@Nullable
|
||||
private ImmutableList<Material> textures;
|
||||
private final Int2ObjectMap<ResourceLocation> renderTypeNames;
|
||||
|
||||
private ItemLayerModel(@Nullable ImmutableList<Material> textures, Int2ObjectMap<ResourceLocation> renderTypeNames)
|
||||
{
|
||||
private ItemLayerModel(@Nullable ImmutableList<Material> textures, Int2ObjectMap<ResourceLocation> renderTypeNames) {
|
||||
this.textures = textures;
|
||||
this.renderTypeNames = renderTypeNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
if (textures == null)
|
||||
{
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState) {
|
||||
if (textures == null) {
|
||||
ImmutableList.Builder<Material> builder = ImmutableList.builder();
|
||||
for (int i = 0; context.hasMaterial("layer" + i); i++)
|
||||
{
|
||||
builder.add(context.getMaterial("layer" + i));
|
||||
}
|
||||
textures = builder.build();
|
||||
}
|
||||
|
||||
TextureAtlasSprite particle = spriteGetter.apply(
|
||||
context.hasMaterial("particle") ? context.getMaterial("particle") : textures.get(0)
|
||||
context.hasMaterial("particle") ? context.getMaterial("particle") : textures.get(0)
|
||||
);
|
||||
var rootTransform = context.getRootTransform();
|
||||
if (!rootTransform.isIdentity())
|
||||
modelState = UnbakedGeometryHelper.composeRootTransformIntoModelState(modelState, rootTransform);
|
||||
|
||||
var normalRenderTypes = new RenderTypeGroup(RenderType.translucent(), ForgeRenderTypes.ITEM_UNSORTED_TRANSLUCENT.get());
|
||||
CompositeModel.Baked.Builder builder = CompositeModel.Baked.builder(context, particle, overrides, context.getTransforms());
|
||||
for (int i = 0; i < textures.size(); i++)
|
||||
{
|
||||
TextureAtlasSprite sprite = spriteGetter.apply(textures.get(i));
|
||||
var builder = CompositeModel.Baked.builder(context, particle, context.getTransforms());
|
||||
for (int i = 0; i < textures.size(); i++) {
|
||||
var sprite = spriteGetter.apply(textures.get(i));
|
||||
var unbaked = UnbakedGeometryHelper.createUnbakedItemElements(i, sprite.contents());
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> sprite, modelState);
|
||||
var renderTypeName = renderTypeNames.get(i);
|
||||
@@ -85,19 +75,15 @@ public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel>
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static final class Loader implements IGeometryLoader<ItemLayerModel>
|
||||
{
|
||||
public static final class Loader implements IGeometryLoader<ItemLayerModel> {
|
||||
public static final Loader INSTANCE = new Loader();
|
||||
|
||||
@Override
|
||||
public ItemLayerModel read(JsonObject jsonObject, JsonDeserializationContext deserializationContext)
|
||||
{
|
||||
public ItemLayerModel read(JsonObject jsonObject, JsonDeserializationContext deserializationContext) {
|
||||
var renderTypeNames = new Int2ObjectOpenHashMap<ResourceLocation>();
|
||||
if (jsonObject.has("render_types"))
|
||||
{
|
||||
if (jsonObject.has("render_types")) {
|
||||
var renderTypes = jsonObject.getAsJsonObject("render_types");
|
||||
for (Map.Entry<String, JsonElement> entry : renderTypes.entrySet())
|
||||
{
|
||||
for (var entry : renderTypes.entrySet()) {
|
||||
var renderType = ResourceLocation.parse(entry.getKey());
|
||||
for (var layer : entry.getValue().getAsJsonArray())
|
||||
if (renderTypeNames.put(layer.getAsInt(), renderType) != null)
|
||||
@@ -108,15 +94,12 @@ public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel>
|
||||
return new ItemLayerModel(null, renderTypeNames);
|
||||
}
|
||||
|
||||
protected void readLayerData(JsonObject jsonObject, String name, Int2ObjectOpenHashMap<ResourceLocation> renderTypeNames, Int2ObjectMap<ForgeFaceData> layerData, boolean logWarning)
|
||||
{
|
||||
protected void readLayerData(JsonObject jsonObject, String name, Int2ObjectOpenHashMap<ResourceLocation> renderTypeNames, Int2ObjectMap<ForgeFaceData> layerData, boolean logWarning) {
|
||||
if (!jsonObject.has(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var fullbrightLayers = jsonObject.getAsJsonObject(name);
|
||||
for (var entry : fullbrightLayers.entrySet())
|
||||
{
|
||||
for (var entry : fullbrightLayers.entrySet()) {
|
||||
int layer = Integer.parseInt(entry.getKey());
|
||||
var data = ForgeFaceData.read(entry.getValue(), ForgeFaceData.DEFAULT);
|
||||
layerData.put(layer, data);
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.util.function.Function;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
@@ -26,7 +25,6 @@ import net.minecraft.client.resources.model.ModelBaker;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
@@ -42,112 +40,91 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* A model composed of multiple sub-models which are picked based on the {@link ItemDisplayContext} being used.
|
||||
*/
|
||||
public class SeparateTransformsModel implements IUnbakedGeometry<SeparateTransformsModel>
|
||||
{
|
||||
public class SeparateTransformsModel implements IUnbakedGeometry<SeparateTransformsModel> {
|
||||
private final BlockModel baseModel;
|
||||
private final ImmutableMap<ItemDisplayContext, BlockModel> perspectives;
|
||||
|
||||
public SeparateTransformsModel(BlockModel baseModel, ImmutableMap<ItemDisplayContext, BlockModel> perspectives)
|
||||
{
|
||||
public SeparateTransformsModel(BlockModel baseModel, ImmutableMap<ItemDisplayContext, BlockModel> perspectives) {
|
||||
this.baseModel = baseModel;
|
||||
this.perspectives = perspectives;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides)
|
||||
{
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState) {
|
||||
return new Baked(
|
||||
context.useAmbientOcclusion(), context.isGui3d(), context.useBlockLight(),
|
||||
spriteGetter.apply(context.getMaterial("particle")), overrides,
|
||||
baseModel.bake(baker, baseModel, spriteGetter, modelState, context.useBlockLight()),
|
||||
ImmutableMap.copyOf(Maps.transformValues(perspectives, value -> {
|
||||
return value.bake(baker, value, spriteGetter, modelState, context.useBlockLight());
|
||||
}))
|
||||
context.useAmbientOcclusion(),
|
||||
context.isGui3d(),
|
||||
context.useBlockLight(),
|
||||
spriteGetter.apply(context.getMaterial("particle")),
|
||||
baseModel.bake(spriteGetter, modelState, context.useBlockLight()),
|
||||
ImmutableMap.copyOf(Maps.transformValues(perspectives, value -> {
|
||||
return value.bake(spriteGetter, modelState, context.useBlockLight());
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveParents(Function<ResourceLocation, UnbakedModel> modelGetter, IGeometryBakingContext context)
|
||||
{
|
||||
baseModel.resolveParents(modelGetter);
|
||||
perspectives.values().forEach(model -> model.resolveParents(modelGetter));
|
||||
public void resolveDependencies(UnbakedModel.Resolver resolver, IGeometryBakingContext context) {
|
||||
baseModel.resolveDependencies(resolver);
|
||||
perspectives.values().forEach(model -> model.resolveDependencies(resolver));
|
||||
}
|
||||
|
||||
public static class Baked implements IDynamicBakedModel
|
||||
{
|
||||
public static class Baked implements IDynamicBakedModel {
|
||||
private final boolean isAmbientOcclusion;
|
||||
private final boolean isGui3d;
|
||||
private final boolean isSideLit;
|
||||
private final TextureAtlasSprite particle;
|
||||
private final ItemOverrides overrides;
|
||||
private final BakedModel baseModel;
|
||||
private final ImmutableMap<ItemDisplayContext, BakedModel> perspectives;
|
||||
|
||||
public Baked(boolean isAmbientOcclusion, boolean isGui3d, boolean isSideLit, TextureAtlasSprite particle, ItemOverrides overrides, BakedModel baseModel, ImmutableMap<ItemDisplayContext, BakedModel> perspectives)
|
||||
{
|
||||
public Baked(boolean isAmbientOcclusion, boolean isGui3d, boolean isSideLit, TextureAtlasSprite particle, BakedModel baseModel, ImmutableMap<ItemDisplayContext, BakedModel> perspectives) {
|
||||
this.isAmbientOcclusion = isAmbientOcclusion;
|
||||
this.isGui3d = isGui3d;
|
||||
this.isSideLit = isSideLit;
|
||||
this.particle = particle;
|
||||
this.overrides = overrides;
|
||||
this.baseModel = baseModel;
|
||||
this.perspectives = perspectives;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull ModelData data, @Nullable RenderType renderType)
|
||||
{
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull ModelData data, @Nullable RenderType renderType) {
|
||||
return baseModel.getQuads(state, side, rand, data, renderType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion()
|
||||
{
|
||||
public boolean useAmbientOcclusion() {
|
||||
return isAmbientOcclusion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
public boolean isGui3d() {
|
||||
return isGui3d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesBlockLight()
|
||||
{
|
||||
public boolean usesBlockLight() {
|
||||
return isSideLit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomRenderer()
|
||||
{
|
||||
public boolean isCustomRenderer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleIcon()
|
||||
{
|
||||
public TextureAtlasSprite getParticleIcon() {
|
||||
return particle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrides getOverrides()
|
||||
{
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemTransforms getTransforms()
|
||||
{
|
||||
public ItemTransforms getTransforms() {
|
||||
return ItemTransforms.NO_TRANSFORMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel applyTransform(ItemDisplayContext cameraTransformType, PoseStack poseStack, boolean applyLeftHandTransform)
|
||||
{
|
||||
if (perspectives.containsKey(cameraTransformType))
|
||||
{
|
||||
public BakedModel applyTransform(ItemDisplayContext cameraTransformType, PoseStack poseStack, boolean applyLeftHandTransform) {
|
||||
if (perspectives.containsKey(cameraTransformType)) {
|
||||
BakedModel p = perspectives.get(cameraTransformType);
|
||||
return p.applyTransform(cameraTransformType, poseStack, applyLeftHandTransform);
|
||||
}
|
||||
@@ -155,32 +132,25 @@ public class SeparateTransformsModel implements IUnbakedGeometry<SeparateTransfo
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull RandomSource rand, @NotNull ModelData data)
|
||||
{
|
||||
public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull RandomSource rand, @NotNull ModelData data) {
|
||||
return baseModel.getRenderTypes(state, rand, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Loader implements IGeometryLoader<SeparateTransformsModel>
|
||||
{
|
||||
public static final class Loader implements IGeometryLoader<SeparateTransformsModel> {
|
||||
public static final Loader INSTANCE = new Loader();
|
||||
|
||||
private Loader()
|
||||
{
|
||||
}
|
||||
private Loader() { }
|
||||
|
||||
@Override
|
||||
public SeparateTransformsModel read(JsonObject jsonObject, JsonDeserializationContext deserializationContext)
|
||||
{
|
||||
public SeparateTransformsModel read(JsonObject jsonObject, JsonDeserializationContext deserializationContext) {
|
||||
BlockModel baseModel = deserializationContext.deserialize(GsonHelper.getAsJsonObject(jsonObject, "base"), BlockModel.class);
|
||||
|
||||
JsonObject perspectiveData = GsonHelper.getAsJsonObject(jsonObject, "perspectives");
|
||||
|
||||
Map<ItemDisplayContext, BlockModel> perspectives = new HashMap<>();
|
||||
for (ItemDisplayContext transform : ItemDisplayContext.values())
|
||||
{
|
||||
if (perspectiveData.has(transform.getSerializedName()))
|
||||
{
|
||||
for (ItemDisplayContext transform : ItemDisplayContext.values()) {
|
||||
if (perspectiveData.has(transform.getSerializedName())) {
|
||||
BlockModel perspectiveModel = deserializationContext.deserialize(GsonHelper.getAsJsonObject(perspectiveData, transform.getSerializedName()), BlockModel.class);
|
||||
perspectives.put(transform, perspectiveModel);
|
||||
}
|
||||
|
||||
@@ -33,19 +33,16 @@ import java.util.Set;
|
||||
* @see BakedModel#getQuads(BlockState, Direction, RandomSource, ModelData, RenderType)
|
||||
* @see BakedModel#getModelData(BlockAndTintGetter, BlockPos, BlockState, ModelData)
|
||||
*/
|
||||
public final class ModelData
|
||||
{
|
||||
public final class ModelData {
|
||||
public static final ModelData EMPTY = ModelData.builder().build();
|
||||
|
||||
private final Map<ModelProperty<?>, Object> properties;
|
||||
|
||||
private ModelData(Map<ModelProperty<?>, Object> properties)
|
||||
{
|
||||
private ModelData(Map<ModelProperty<?>, Object> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public Set<ModelProperty<?>> getProperties()
|
||||
{
|
||||
public Set<ModelProperty<?>> getProperties() {
|
||||
return properties.keySet();
|
||||
}
|
||||
|
||||
@@ -54,45 +51,37 @@ public final class ModelData
|
||||
return properties.containsKey(property);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public <T> T get(ModelProperty<T> property)
|
||||
{
|
||||
return (T) properties.get(property);
|
||||
public <T> T get(ModelProperty<T> property) {
|
||||
return (T)properties.get(property);
|
||||
}
|
||||
|
||||
public Builder derive()
|
||||
{
|
||||
public Builder derive() {
|
||||
return new Builder(this);
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
{
|
||||
public static Builder builder() {
|
||||
return new Builder(null);
|
||||
}
|
||||
|
||||
public static final class Builder
|
||||
{
|
||||
public static final class Builder {
|
||||
private final Map<ModelProperty<?>, Object> properties = new IdentityHashMap<>();
|
||||
|
||||
private Builder(@Nullable ModelData parent)
|
||||
{
|
||||
private Builder(@Nullable ModelData parent) {
|
||||
if (parent != null)
|
||||
{
|
||||
properties.putAll(parent.properties);
|
||||
}
|
||||
}
|
||||
|
||||
@Contract("_, _ -> this")
|
||||
public <T> Builder with(ModelProperty<T> property, T value)
|
||||
{
|
||||
public <T> Builder with(ModelProperty<T> property, T value) {
|
||||
Preconditions.checkState(property.test(value), "The provided value is invalid for this property.");
|
||||
properties.put(property, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Contract("-> new")
|
||||
public ModelData build()
|
||||
{
|
||||
public ModelData build() {
|
||||
return new ModelData(Collections.unmodifiableMap(properties));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,11 @@ public class ModelDataManager {
|
||||
return getAt(new ChunkPos(pos)).get(pos);
|
||||
}
|
||||
|
||||
public ModelData getAtOrEmpty(BlockPos pos) {
|
||||
var ret = getAt(pos);
|
||||
return ret == null ? ModelData.EMPTY : ret;
|
||||
}
|
||||
|
||||
public Map<BlockPos, ModelData> getAt(SectionPos pos) {
|
||||
return getAt(pos.chunk());
|
||||
}
|
||||
|
||||
@@ -380,6 +380,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
private RotationBuilder rotation;
|
||||
private boolean shade = true;
|
||||
private ForgeFaceData data = ForgeFaceData.DEFAULT;
|
||||
private int emission = 0;
|
||||
|
||||
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);
|
||||
@@ -559,14 +560,23 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementBuilder emission(int value) {
|
||||
this.emission = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
private BiConsumer<Direction, FaceBuilder> addTexture(String texture) {
|
||||
return ($, f) -> f.texture(texture);
|
||||
}
|
||||
|
||||
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);
|
||||
var faces = new LinkedHashMap<Direction, BlockElementFace>();
|
||||
for (var entry : this.faces.entrySet()) {
|
||||
if (faces.containsKey(entry.getKey()))
|
||||
throw new IllegalArgumentException("Multiple faces defined for Direction: " + entry.getKey().getName());
|
||||
faces.put(entry.getKey(), entry.getValue().build());
|
||||
}
|
||||
return new BlockElement(from, to, faces, rotation == null ? null : rotation.build(), shade, emission);
|
||||
}
|
||||
|
||||
public T end() { return self(); }
|
||||
|
||||
+28
-46
@@ -21,9 +21,7 @@ import com.google.gson.JsonObject;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
|
||||
public final class MultiPartBlockStateBuilder implements IGeneratedBlockState
|
||||
{
|
||||
|
||||
public final class MultiPartBlockStateBuilder implements IGeneratedBlockState {
|
||||
private final List<PartBuilder> parts = new ArrayList<>();
|
||||
private final Block owner;
|
||||
|
||||
@@ -35,7 +33,7 @@ public final class MultiPartBlockStateBuilder implements IGeneratedBlockState
|
||||
* Creates a builder for models to assign to a {@link PartBuilder}, which when
|
||||
* completed via {@link ConfiguredModel.Builder#addModel()} will assign the
|
||||
* resultant set of models to the part and return it for further processing.
|
||||
*
|
||||
*
|
||||
* @return the model builder
|
||||
* @see ConfiguredModel.Builder
|
||||
*/
|
||||
@@ -80,7 +78,7 @@ public final class MultiPartBlockStateBuilder implements IGeneratedBlockState
|
||||
/**
|
||||
* Set a condition for this part, which consists of a property and a set of
|
||||
* valid values. Can be called multiple times for multiple different properties.
|
||||
*
|
||||
*
|
||||
* @param <T> the type of the property value
|
||||
* @param prop the property
|
||||
* @param values a set of valid values
|
||||
@@ -109,8 +107,7 @@ public final class MultiPartBlockStateBuilder implements IGeneratedBlockState
|
||||
* Allows having nested groups of conditions if there are not any normal conditions.
|
||||
* @throws IllegalStateException if {@code !conditions.isEmpty()}
|
||||
*/
|
||||
public final ConditionGroup nestedGroup()
|
||||
{
|
||||
public final ConditionGroup nestedGroup() {
|
||||
Preconditions.checkState(conditions.isEmpty(), "Can't have nested condition groups if there are already normal conditions");
|
||||
ConditionGroup group = new ConditionGroup();
|
||||
this.nestedConditionGroups.add(group);
|
||||
@@ -123,9 +120,7 @@ public final class MultiPartBlockStateBuilder implements IGeneratedBlockState
|
||||
JsonObject out = new JsonObject();
|
||||
if (!conditions.isEmpty()) {
|
||||
out.add("when", MultiPartBlockStateBuilder.toJson(this.conditions, this.useOr));
|
||||
}
|
||||
else if (!nestedConditionGroups.isEmpty())
|
||||
{
|
||||
} else if (!nestedConditionGroups.isEmpty()) {
|
||||
out.add("when", MultiPartBlockStateBuilder.toJson(this.nestedConditionGroups, this.useOr));
|
||||
}
|
||||
out.add("apply", models.toJSON());
|
||||
@@ -136,8 +131,7 @@ public final class MultiPartBlockStateBuilder implements IGeneratedBlockState
|
||||
return b.getStateDefinition().getProperties().containsAll(conditions.keySet());
|
||||
}
|
||||
|
||||
public class ConditionGroup
|
||||
{
|
||||
public class ConditionGroup {
|
||||
public final Multimap<Property<?>, Comparable<?>> conditions = MultimapBuilder.linkedHashKeys().arrayListValues().build();
|
||||
public final List<ConditionGroup> nestedConditionGroups = new ArrayList<>();
|
||||
private ConditionGroup parent = null;
|
||||
@@ -160,8 +154,7 @@ public final class MultiPartBlockStateBuilder implements IGeneratedBlockState
|
||||
* @throws IllegalStateException if {@code !nestedConditionGroups.isEmpty()}
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final <T extends Comparable<T>> ConditionGroup condition(Property<T> prop, T... values)
|
||||
{
|
||||
public final <T extends Comparable<T>> ConditionGroup condition(Property<T> prop, T... values) {
|
||||
Preconditions.checkNotNull(prop, "Property must not be null");
|
||||
Preconditions.checkNotNull(values, "Value list must not be null");
|
||||
Preconditions.checkArgument(values.length > 0, "Value list must not be empty");
|
||||
@@ -176,8 +169,7 @@ public final class MultiPartBlockStateBuilder implements IGeneratedBlockState
|
||||
* Allows having nested groups of conditions if there are not any normal conditions.
|
||||
* @throws IllegalStateException if {@code !conditions.isEmpty()}
|
||||
*/
|
||||
public ConditionGroup nestedGroup()
|
||||
{
|
||||
public ConditionGroup nestedGroup() {
|
||||
Preconditions.checkState(conditions.isEmpty(), "Can't have nested condition groups if there are already normal conditions");
|
||||
ConditionGroup group = new ConditionGroup();
|
||||
group.parent = this;
|
||||
@@ -187,23 +179,21 @@ public final class MultiPartBlockStateBuilder implements IGeneratedBlockState
|
||||
|
||||
/**
|
||||
* Ends this nested condition group and returns the parent condition group
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException If this is not a nested condition group
|
||||
*/
|
||||
public ConditionGroup endNestedGroup()
|
||||
{
|
||||
public ConditionGroup endNestedGroup() {
|
||||
if (parent == null)
|
||||
throw new IllegalStateException("This condition group is not nested, use end() instead");
|
||||
throw new IllegalStateException("This condition group is not nested, use end() instead");
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends this condition group and returns the part builder
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException If this is a nested condition group
|
||||
*/
|
||||
public MultiPartBlockStateBuilder.PartBuilder end()
|
||||
{
|
||||
public MultiPartBlockStateBuilder.PartBuilder end() {
|
||||
if (this.parent != null)
|
||||
throw new IllegalStateException("This is a nested condition group, use endNestedGroup() instead");
|
||||
return MultiPartBlockStateBuilder.PartBuilder.this;
|
||||
@@ -212,58 +202,45 @@ public final class MultiPartBlockStateBuilder implements IGeneratedBlockState
|
||||
/**
|
||||
* Makes this part get applied if any of the conditions/condition groups are true, instead of all of them needing to be true.
|
||||
*/
|
||||
public ConditionGroup useOr()
|
||||
{
|
||||
public ConditionGroup useOr() {
|
||||
this.useOr = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
JsonObject toJson()
|
||||
{
|
||||
JsonObject toJson() {
|
||||
if (!this.conditions.isEmpty())
|
||||
{
|
||||
return MultiPartBlockStateBuilder.toJson(this.conditions, this.useOr);
|
||||
}
|
||||
else if (!this.nestedConditionGroups.isEmpty())
|
||||
{
|
||||
return MultiPartBlockStateBuilder.toJson(this.nestedConditionGroups, this.useOr);
|
||||
}
|
||||
return new JsonObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static JsonObject toJson(List<PartBuilder.ConditionGroup> conditions, boolean useOr)
|
||||
{
|
||||
private static JsonObject toJson(List<PartBuilder.ConditionGroup> conditions, boolean useOr) {
|
||||
JsonObject groupJson = new JsonObject();
|
||||
JsonArray innerGroupJson = new JsonArray();
|
||||
groupJson.add(useOr ? "OR" : "AND", innerGroupJson);
|
||||
for (PartBuilder.ConditionGroup group : conditions)
|
||||
{
|
||||
innerGroupJson.add(group.toJson());
|
||||
}
|
||||
return groupJson;
|
||||
}
|
||||
|
||||
private static JsonObject toJson(Multimap<Property<?>, Comparable<?>> conditions, boolean useOr)
|
||||
{
|
||||
private static JsonObject toJson(Multimap<Property<?>, Comparable<?>> conditions, boolean useOr) {
|
||||
JsonObject groupJson = new JsonObject();
|
||||
for (Entry<Property<?>, Collection<Comparable<?>>> e : conditions.asMap().entrySet())
|
||||
{
|
||||
for (Entry<Property<?>, Collection<Comparable<?>>> e : conditions.asMap().entrySet()) {
|
||||
StringBuilder activeString = new StringBuilder();
|
||||
for (Comparable<?> val : e.getValue())
|
||||
{
|
||||
for (Comparable<?> val : e.getValue()) {
|
||||
if (!activeString.isEmpty())
|
||||
activeString.append("|");
|
||||
activeString.append(((Property) e.getKey()).getName(val));
|
||||
activeString.append(getName(e.getKey(), val));
|
||||
}
|
||||
groupJson.addProperty(e.getKey().getName(), activeString.toString());
|
||||
}
|
||||
if (useOr)
|
||||
{
|
||||
|
||||
if (useOr) {
|
||||
JsonArray innerWhen = new JsonArray();
|
||||
for (Entry<String, JsonElement> entry : groupJson.entrySet())
|
||||
{
|
||||
for (Entry<String, JsonElement> entry : groupJson.entrySet()) {
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.add(entry.getKey(), entry.getValue());
|
||||
innerWhen.add(obj);
|
||||
@@ -273,4 +250,9 @@ public final class MultiPartBlockStateBuilder implements IGeneratedBlockState
|
||||
}
|
||||
return groupJson;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private static <T> String getName(Property<?> key, Comparable<?> value) {
|
||||
return ((Property)key).getName((Comparable)value);
|
||||
}
|
||||
}
|
||||
+26
-57
@@ -5,23 +5,17 @@
|
||||
|
||||
package net.minecraftforge.client.model.geometry;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.math.Transformation;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBaker;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -31,8 +25,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <p>
|
||||
* Users should not be instantiating this themselves.
|
||||
*/
|
||||
public class BlockGeometryBakingContext implements IGeometryBakingContext
|
||||
{
|
||||
public class BlockGeometryBakingContext implements IGeometryBakingContext {
|
||||
public final BlockModel owner;
|
||||
public final VisibilityData visibilityData = new VisibilityData();
|
||||
@Nullable
|
||||
@@ -44,111 +37,93 @@ public class BlockGeometryBakingContext implements IGeometryBakingContext
|
||||
private boolean gui3d = true;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public BlockGeometryBakingContext(BlockModel owner)
|
||||
{
|
||||
public BlockGeometryBakingContext(BlockModel owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName()
|
||||
{
|
||||
public String getModelName() {
|
||||
return owner.name;
|
||||
}
|
||||
|
||||
public boolean hasCustomGeometry()
|
||||
{
|
||||
public boolean hasCustomGeometry() {
|
||||
return getCustomGeometry() != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IUnbakedGeometry<?> getCustomGeometry()
|
||||
{
|
||||
public IUnbakedGeometry<?> getCustomGeometry() {
|
||||
return owner.parent != null && customGeometry == null ? owner.parent.customData.getCustomGeometry() : customGeometry;
|
||||
}
|
||||
|
||||
public void setCustomGeometry(IUnbakedGeometry<?> geometry)
|
||||
{
|
||||
public void setCustomGeometry(IUnbakedGeometry<?> geometry) {
|
||||
this.customGeometry = geometry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComponentVisible(String part, boolean fallback)
|
||||
{
|
||||
public boolean isComponentVisible(String part, boolean fallback) {
|
||||
return owner.parent != null && !visibilityData.hasCustomVisibility(part) ?
|
||||
owner.parent.customData.isComponentVisible(part, fallback) :
|
||||
visibilityData.isVisible(part, fallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMaterial(String name)
|
||||
{
|
||||
public boolean hasMaterial(String name) {
|
||||
return owner.hasTexture(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getMaterial(String name)
|
||||
{
|
||||
public Material getMaterial(String name) {
|
||||
return owner.getMaterial(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
public boolean isGui3d() {
|
||||
return gui3d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useBlockLight()
|
||||
{
|
||||
public boolean useBlockLight() {
|
||||
return owner.getGuiLight().lightLikeBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion()
|
||||
{
|
||||
public boolean useAmbientOcclusion() {
|
||||
return owner.hasAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemTransforms getTransforms()
|
||||
{
|
||||
public ItemTransforms getTransforms() {
|
||||
return owner.getTransforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transformation getRootTransform()
|
||||
{
|
||||
public Transformation getRootTransform() {
|
||||
if (rootTransform != null)
|
||||
return rootTransform;
|
||||
return owner.parent != null ? owner.parent.customData.getRootTransform() : Transformation.identity();
|
||||
}
|
||||
|
||||
public void setRootTransform(Transformation rootTransform)
|
||||
{
|
||||
public void setRootTransform(Transformation rootTransform) {
|
||||
this.rootTransform = rootTransform;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getRenderTypeHint()
|
||||
{
|
||||
public ResourceLocation getRenderTypeHint() {
|
||||
if (renderTypeHint != null)
|
||||
return renderTypeHint;
|
||||
return owner.parent != null ? owner.parent.customData.getRenderTypeHint() : null;
|
||||
}
|
||||
|
||||
public void setRenderTypeHint(ResourceLocation renderTypeHint)
|
||||
{
|
||||
public void setRenderTypeHint(ResourceLocation renderTypeHint) {
|
||||
this.renderTypeHint = renderTypeHint;
|
||||
}
|
||||
|
||||
public void setGui3d(boolean gui3d)
|
||||
{
|
||||
public void setGui3d(boolean gui3d) {
|
||||
this.gui3d = gui3d;
|
||||
}
|
||||
|
||||
public void copyFrom(BlockGeometryBakingContext other)
|
||||
{
|
||||
public void copyFrom(BlockGeometryBakingContext other) {
|
||||
this.customGeometry = other.customGeometry;
|
||||
this.rootTransform = other.rootTransform;
|
||||
this.visibilityData.copyFrom(other.visibilityData);
|
||||
@@ -156,35 +131,29 @@ public class BlockGeometryBakingContext implements IGeometryBakingContext
|
||||
this.gui3d = other.gui3d;
|
||||
}
|
||||
|
||||
public BakedModel bake(ModelBaker baker, Function<Material, TextureAtlasSprite> bakedTextureGetter, ModelState modelTransform, ItemOverrides overrides)
|
||||
{
|
||||
public BakedModel bake(ModelBaker baker, Function<Material, TextureAtlasSprite> bakedTextureGetter, ModelState modelTransform) {
|
||||
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);
|
||||
return geometry.bake(this, baker, bakedTextureGetter, modelTransform);
|
||||
}
|
||||
|
||||
public static class VisibilityData
|
||||
{
|
||||
public static class VisibilityData {
|
||||
private final Map<String, Boolean> data = new HashMap<>();
|
||||
|
||||
public boolean hasCustomVisibility(String part)
|
||||
{
|
||||
public boolean hasCustomVisibility(String part) {
|
||||
return data.containsKey(part);
|
||||
}
|
||||
|
||||
public boolean isVisible(String part, boolean fallback)
|
||||
{
|
||||
public boolean isVisible(String part, boolean fallback) {
|
||||
return data.getOrDefault(part, fallback);
|
||||
}
|
||||
|
||||
public void setVisibilityState(String partName, boolean type)
|
||||
{
|
||||
public void setVisibilityState(String partName, boolean type) {
|
||||
data.put(partName, type);
|
||||
}
|
||||
|
||||
public void copyFrom(VisibilityData visibilityData)
|
||||
{
|
||||
public void copyFrom(VisibilityData visibilityData) {
|
||||
data.clear();
|
||||
data.putAll(visibilityData.data);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ package net.minecraftforge.client.model.geometry;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.event.ModelEvent;
|
||||
import net.minecraftforge.client.model.ElementsModel;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -21,8 +20,7 @@ import java.util.stream.Collectors;
|
||||
* <p>
|
||||
* Provides a lookup.
|
||||
*/
|
||||
public final class GeometryLoaderManager
|
||||
{
|
||||
public final class GeometryLoaderManager {
|
||||
private static ImmutableMap<ResourceLocation, IGeometryLoader<?>> LOADERS;
|
||||
private static String LOADER_LIST;
|
||||
|
||||
@@ -30,22 +28,19 @@ public final class GeometryLoaderManager
|
||||
* Finds the {@link IGeometryLoader} for a given name, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public static IGeometryLoader<?> get(ResourceLocation name)
|
||||
{
|
||||
public static IGeometryLoader<?> get(ResourceLocation name) {
|
||||
return LOADERS.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a comma-separated list of all active loaders, for use in error messages.
|
||||
*/
|
||||
public static String getLoaderList()
|
||||
{
|
||||
public static String getLoaderList() {
|
||||
return LOADER_LIST;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void init()
|
||||
{
|
||||
public static void init() {
|
||||
var loaders = new HashMap<ResourceLocation, IGeometryLoader<?>>();
|
||||
var event = new ModelEvent.RegisterGeometryLoaders(loaders);
|
||||
ModLoader.get().postEventWrapContainerInModOrder(event);
|
||||
@@ -53,7 +48,5 @@ public final class GeometryLoaderManager
|
||||
LOADER_LIST = loaders.keySet().stream().map(ResourceLocation::toString).collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
private GeometryLoaderManager()
|
||||
{
|
||||
}
|
||||
private GeometryLoaderManager() { }
|
||||
}
|
||||
@@ -21,8 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
* @see StandaloneGeometryBakingContext
|
||||
* @see BlockGeometryBakingContext
|
||||
*/
|
||||
public interface IGeometryBakingContext
|
||||
{
|
||||
public interface IGeometryBakingContext {
|
||||
/**
|
||||
* {@return the name of the model being baked for logging and caching purposes.}
|
||||
*/
|
||||
@@ -87,8 +86,7 @@ public interface IGeometryBakingContext
|
||||
/**
|
||||
* {@return a {@link RenderTypeGroup} with the given name, or the empty group if not found.}
|
||||
*/
|
||||
default RenderTypeGroup getRenderType(ResourceLocation name)
|
||||
{
|
||||
default RenderTypeGroup getRenderType(ResourceLocation name) {
|
||||
return NamedRenderTypeManager.get(name);
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
|
||||
* @see RegisterGeometryLoaders
|
||||
* @see RegisterClientReloadListenersEvent
|
||||
*/
|
||||
public interface IGeometryLoader<T extends IUnbakedGeometry<T>>
|
||||
{
|
||||
public interface IGeometryLoader<T extends IUnbakedGeometry<T>> {
|
||||
T read(JsonObject jsonObject, JsonDeserializationContext deserializationContext) throws JsonParseException;
|
||||
}
|
||||
@@ -9,14 +9,12 @@ import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBaker;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
/**
|
||||
* General interface for any model that can be baked, superset of vanilla {@link UnbakedModel}.
|
||||
@@ -27,14 +25,14 @@ import net.minecraft.resources.ResourceLocation;
|
||||
* @see IGeometryBakingContext
|
||||
*/
|
||||
public interface IUnbakedGeometry<T extends IUnbakedGeometry<T>> {
|
||||
BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides);
|
||||
BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState);
|
||||
|
||||
/**
|
||||
* Resolve parents of nested {@link BlockModel}s which are later used in
|
||||
* {@link IUnbakedGeometry#bake(IGeometryBakingContext, ModelBaker, Function, ModelState, ItemOverrides)}
|
||||
* {@link IUnbakedGeometry#bake(IGeometryBakingContext, ModelBaker, Function, ModelState)}
|
||||
* via {@link BlockModel#resolveParents(Function)}
|
||||
*/
|
||||
default void resolveParents(Function<ResourceLocation, UnbakedModel> modelGetter, IGeometryBakingContext context) { }
|
||||
default void resolveDependencies(UnbakedModel.Resolver resolver, IGeometryBakingContext context) { }
|
||||
|
||||
/**
|
||||
* {@return a set of all the components whose visibility may be configured via {@link IGeometryBakingContext}}
|
||||
|
||||
@@ -7,7 +7,6 @@ package net.minecraftforge.client.model.geometry;
|
||||
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
@@ -21,17 +20,15 @@ import net.minecraftforge.client.model.IModelBuilder;
|
||||
* Base class for implementations of {@link IUnbakedGeometry} which do not wish to handle model creation themselves,
|
||||
* instead supplying {@linkplain BakedQuad baked quads} through a builder.
|
||||
*/
|
||||
public abstract class SimpleUnbakedGeometry<T extends SimpleUnbakedGeometry<T>> implements IUnbakedGeometry<T>
|
||||
{
|
||||
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)
|
||||
{
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState) {
|
||||
TextureAtlasSprite particle = spriteGetter.apply(context.getMaterial("particle"));
|
||||
|
||||
var renderTypeHint = context.getRenderTypeHint();
|
||||
var renderTypes = renderTypeHint != null ? context.getRenderType(renderTypeHint) : RenderTypeGroup.EMPTY;
|
||||
IModelBuilder<?> builder = IModelBuilder.of(context.useAmbientOcclusion(), context.useBlockLight(), context.isGui3d(),
|
||||
context.getTransforms(), overrides, particle, renderTypes);
|
||||
context.getTransforms(), particle, renderTypes);
|
||||
|
||||
addQuads(context, builder, baker, spriteGetter, modelState);
|
||||
|
||||
|
||||
+43
-71
@@ -10,9 +10,10 @@ import com.mojang.math.Transformation;
|
||||
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -23,24 +24,20 @@ import java.util.function.Predicate;
|
||||
/**
|
||||
* A {@linkplain IGeometryBakingContext geometry baking context} that is not bound to block/item model loading.
|
||||
*/
|
||||
public class StandaloneGeometryBakingContext implements IGeometryBakingContext
|
||||
{
|
||||
public class StandaloneGeometryBakingContext implements IGeometryBakingContext {
|
||||
public static final ResourceLocation LOCATION = ResourceLocation.fromNamespaceAndPath("forge", "standalone");
|
||||
|
||||
public static final StandaloneGeometryBakingContext INSTANCE = create(LOCATION);
|
||||
|
||||
public static StandaloneGeometryBakingContext create(ResourceLocation modelName)
|
||||
{
|
||||
public static StandaloneGeometryBakingContext create(ResourceLocation modelName) {
|
||||
return builder().build(modelName);
|
||||
}
|
||||
|
||||
public static StandaloneGeometryBakingContext create(Map<String, ResourceLocation> textures)
|
||||
{
|
||||
public static StandaloneGeometryBakingContext create(Map<String, ResourceLocation> textures) {
|
||||
return create(LOCATION, textures);
|
||||
}
|
||||
|
||||
public static StandaloneGeometryBakingContext create(ResourceLocation modelName, Map<String, ResourceLocation> textures)
|
||||
{
|
||||
public static StandaloneGeometryBakingContext create(ResourceLocation modelName, Map<String, ResourceLocation> textures) {
|
||||
return builder().withTextures(textures, MissingTextureAtlasSprite.getLocation()).build(modelName);
|
||||
}
|
||||
|
||||
@@ -56,13 +53,14 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext
|
||||
private final ResourceLocation renderTypeHint;
|
||||
private final BiPredicate<String, Boolean> visibilityTest;
|
||||
|
||||
private StandaloneGeometryBakingContext(ResourceLocation modelName, Predicate<String> materialCheck,
|
||||
Function<String, Material> materialLookup, boolean isGui3d,
|
||||
boolean useBlockLight, boolean useAmbientOcclusion,
|
||||
ItemTransforms transforms, Transformation rootTransform,
|
||||
@Nullable ResourceLocation renderTypeHint,
|
||||
BiPredicate<String, Boolean> visibilityTest)
|
||||
{
|
||||
private StandaloneGeometryBakingContext(
|
||||
ResourceLocation modelName, Predicate<String> materialCheck,
|
||||
Function<String, Material> materialLookup, boolean isGui3d,
|
||||
boolean useBlockLight, boolean useAmbientOcclusion,
|
||||
ItemTransforms transforms, Transformation rootTransform,
|
||||
@Nullable ResourceLocation renderTypeHint,
|
||||
BiPredicate<String, Boolean> visibilityTest
|
||||
) {
|
||||
this.modelName = modelName;
|
||||
this.materialCheck = materialCheck;
|
||||
this.materialLookup = materialLookup;
|
||||
@@ -76,79 +74,66 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName()
|
||||
{
|
||||
public String getModelName() {
|
||||
return modelName.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMaterial(String name)
|
||||
{
|
||||
public boolean hasMaterial(String name) {
|
||||
return materialCheck.test(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getMaterial(String name)
|
||||
{
|
||||
public Material getMaterial(String name) {
|
||||
return materialLookup.apply(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
public boolean isGui3d() {
|
||||
return isGui3d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useBlockLight()
|
||||
{
|
||||
public boolean useBlockLight() {
|
||||
return useBlockLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion()
|
||||
{
|
||||
public boolean useAmbientOcclusion() {
|
||||
return useAmbientOcclusion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemTransforms getTransforms()
|
||||
{
|
||||
public ItemTransforms getTransforms() {
|
||||
return transforms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transformation getRootTransform()
|
||||
{
|
||||
public Transformation getRootTransform() {
|
||||
return rootTransform;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getRenderTypeHint()
|
||||
{
|
||||
public ResourceLocation getRenderTypeHint() {
|
||||
return renderTypeHint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComponentVisible(String component, boolean fallback)
|
||||
{
|
||||
public boolean isComponentVisible(String component, boolean fallback) {
|
||||
return visibilityTest.test(component, fallback);
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
{
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static Builder builder(IGeometryBakingContext parent)
|
||||
{
|
||||
public static Builder builder(IGeometryBakingContext parent) {
|
||||
return new Builder(parent);
|
||||
}
|
||||
|
||||
public static final class Builder
|
||||
{
|
||||
private static final Material NO_MATERIAL = new Material(TextureAtlas.LOCATION_BLOCKS, MissingTextureAtlasSprite.getLocation());
|
||||
public static final class Builder {
|
||||
private static final Material NO_MATERIAL = new Material(InventoryMenu.BLOCK_ATLAS, MissingTextureAtlasSprite.getLocation());
|
||||
private Predicate<String> materialCheck = Predicates.alwaysFalse();
|
||||
private Function<String, Material> materialLookup = $ -> NO_MATERIAL;
|
||||
private boolean isGui3d = true;
|
||||
@@ -160,12 +145,9 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext
|
||||
private ResourceLocation renderTypeHint;
|
||||
private BiPredicate<String, Boolean> visibilityTest = (c, def) -> def;
|
||||
|
||||
private Builder()
|
||||
{
|
||||
}
|
||||
private Builder() { }
|
||||
|
||||
private Builder(IGeometryBakingContext parent)
|
||||
{
|
||||
private Builder(IGeometryBakingContext parent) {
|
||||
this.materialCheck = parent::hasMaterial;
|
||||
this.materialLookup = parent::getMaterial;
|
||||
this.isGui3d = parent.isGui3d();
|
||||
@@ -177,69 +159,59 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext
|
||||
this.visibilityTest = parent::isComponentVisible;
|
||||
}
|
||||
|
||||
public Builder withTextures(Map<String, ResourceLocation> textures, ResourceLocation defaultTexture)
|
||||
{
|
||||
return withTextures(TextureAtlas.LOCATION_BLOCKS, textures, defaultTexture);
|
||||
public Builder withTextures(Map<String, ResourceLocation> textures, ResourceLocation defaultTexture) {
|
||||
return withTextures(InventoryMenu.BLOCK_ATLAS, textures, defaultTexture);
|
||||
}
|
||||
|
||||
public Builder withTextures(ResourceLocation atlasLocation, Map<String, ResourceLocation> textures, ResourceLocation defaultTexture)
|
||||
{
|
||||
public Builder withTextures(ResourceLocation atlasLocation, Map<String, ResourceLocation> textures, ResourceLocation defaultTexture) {
|
||||
this.materialCheck = textures::containsKey;
|
||||
this.materialLookup = name -> new Material(atlasLocation, textures.getOrDefault(name, defaultTexture));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withMaterials(Map<String, Material> materials, Material defaultMaterial)
|
||||
{
|
||||
public Builder withMaterials(Map<String, Material> materials, Material defaultMaterial) {
|
||||
this.materialCheck = materials::containsKey;
|
||||
this.materialLookup = name -> materials.getOrDefault(name, defaultMaterial);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withGui3d(boolean isGui3d)
|
||||
{
|
||||
public Builder withGui3d(boolean isGui3d) {
|
||||
this.isGui3d = isGui3d;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withUseBlockLight(boolean useBlockLight)
|
||||
{
|
||||
public Builder withUseBlockLight(boolean useBlockLight) {
|
||||
this.useBlockLight = useBlockLight;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withUseAmbientOcclusion(boolean useAmbientOcclusion)
|
||||
{
|
||||
public Builder withUseAmbientOcclusion(boolean useAmbientOcclusion) {
|
||||
this.useAmbientOcclusion = useAmbientOcclusion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTransforms(ItemTransforms transforms)
|
||||
{
|
||||
public Builder withTransforms(ItemTransforms transforms) {
|
||||
this.transforms = transforms;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withRootTransform(Transformation rootTransform)
|
||||
{
|
||||
public Builder withRootTransform(Transformation rootTransform) {
|
||||
this.rootTransform = rootTransform;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withRenderTypeHint(ResourceLocation renderTypeHint)
|
||||
{
|
||||
public Builder withRenderTypeHint(ResourceLocation renderTypeHint) {
|
||||
this.renderTypeHint = renderTypeHint;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withVisibleComponents(Object2BooleanMap<String> parts)
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
public Builder withVisibleComponents(Object2BooleanMap<String> parts) {
|
||||
this.visibilityTest = parts::getOrDefault;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StandaloneGeometryBakingContext build(ResourceLocation modelName)
|
||||
{
|
||||
public StandaloneGeometryBakingContext build(ResourceLocation modelName) {
|
||||
return new StandaloneGeometryBakingContext(modelName, materialCheck, materialLookup, isGui3d, useBlockLight, useAmbientOcclusion, transforms, rootTransform, renderTypeHint, visibilityTest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,8 @@ import net.minecraft.client.renderer.block.model.BlockElementFace;
|
||||
import net.minecraft.client.renderer.block.model.BlockFaceUV;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.renderer.block.model.FaceBakery;
|
||||
import net.minecraft.client.renderer.block.model.ItemModelGenerator;
|
||||
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.SpriteContents;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.BuiltInModel;
|
||||
@@ -24,10 +22,11 @@ import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBaker;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.SpecialModels;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraftforge.client.model.ElementsModel;
|
||||
import net.minecraftforge.client.model.ForgeFaceData;
|
||||
import net.minecraftforge.client.model.IModelBuilder;
|
||||
import net.minecraftforge.client.model.IQuadTransformer;
|
||||
import net.minecraftforge.client.model.QuadTransformers;
|
||||
@@ -47,9 +46,7 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* Helper for dealing with unbaked models and geometries.
|
||||
*/
|
||||
public class UnbakedGeometryHelper
|
||||
{
|
||||
private static final ItemModelGenerator ITEM_MODEL_GENERATOR = new ItemModelGenerator();
|
||||
public class UnbakedGeometryHelper {
|
||||
private static final FaceBakery FACE_BAKERY = new FaceBakery();
|
||||
|
||||
/**
|
||||
@@ -72,51 +69,51 @@ public class UnbakedGeometryHelper
|
||||
/**
|
||||
* Resolves a material that may have been defined with a filesystem path instead of a proper {@link ResourceLocation}.
|
||||
* <p>
|
||||
* The target atlas will always be {@link TextureAtlas#LOCATION_BLOCKS}.
|
||||
* The target atlas will always be {@link InventoryMenu#BLOCK_ATLAS}.
|
||||
*/
|
||||
public static Material resolveDirtyMaterial(@Nullable String tex, IGeometryBakingContext owner)
|
||||
{
|
||||
public static Material resolveDirtyMaterial(@Nullable String tex, IGeometryBakingContext owner) {
|
||||
if (tex == null)
|
||||
return new Material(TextureAtlas.LOCATION_BLOCKS, MissingTextureAtlasSprite.getLocation());
|
||||
return new Material(InventoryMenu.BLOCK_ATLAS, MissingTextureAtlasSprite.getLocation());
|
||||
if (tex.startsWith("#"))
|
||||
return owner.getMaterial(tex);
|
||||
|
||||
// Attempt to convert a common (windows/linux/mac) filesystem path to a ResourceLocation.
|
||||
// This makes no promises, if it doesn't work, too bad, fix your mtl file.
|
||||
Matcher match = FILESYSTEM_PATH_TO_RESLOC.matcher(tex);
|
||||
if (match.matches())
|
||||
{
|
||||
if (match.matches()) {
|
||||
String namespace = match.group("namespace");
|
||||
String path = match.group("path").replace("\\", "/");
|
||||
tex = namespace != null ? namespace + ":" + path : path;
|
||||
}
|
||||
|
||||
return new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.parse(tex));
|
||||
return new Material(InventoryMenu.BLOCK_ATLAS, 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, 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));
|
||||
return customModel.bake(blockModel.customData, modelBaker, spriteGetter, modelState);
|
||||
|
||||
// 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, guiLight3d);
|
||||
if (blockModel.getRootModel() == SpecialModels.GENERATED_MARKER)
|
||||
return ModelBakery.ITEM_MODEL_GENERATOR.generateBlockModel(spriteGetter, blockModel).bake(modelBaker, blockModel, spriteGetter, modelState, guiLight3d);
|
||||
|
||||
if (blockModel.getRootModel() == ModelBakery.BLOCK_ENTITY_MARKER)
|
||||
{
|
||||
if (blockModel.getRootModel() == SpecialModels.BLOCK_ENTITY_MARKER) {
|
||||
var particleSprite = spriteGetter.apply(blockModel.getMaterial("particle"));
|
||||
return new BuiltInModel(blockModel.getTransforms(), blockModel.getOverrides(modelBaker, owner, spriteGetter), particleSprite, blockModel.getGuiLight().lightLikeBlock());
|
||||
return new BuiltInModel(blockModel.getTransforms(), particleSprite, blockModel.getGuiLight().lightLikeBlock());
|
||||
}
|
||||
|
||||
var elementsModel = new ElementsModel(blockModel.getElements());
|
||||
return elementsModel.bake(blockModel.customData, modelBaker, spriteGetter, modelState, blockModel.getOverrides(modelBaker, owner, spriteGetter));
|
||||
@SuppressWarnings("deprecation")
|
||||
var elements = blockModel.getElements();
|
||||
var elementsModel = new ElementsModel(elements);
|
||||
return elementsModel.bake(blockModel.customData, modelBaker, spriteGetter, modelState);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a list of {@linkplain BlockElement block elements} in the shape of the specified sprite contents.
|
||||
@@ -124,9 +121,8 @@ 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)
|
||||
{
|
||||
return ITEM_MODEL_GENERATOR.processFrames(layerIndex, "layer" + layerIndex, spriteContents);
|
||||
public static List<BlockElement> createUnbakedItemElements(int layerIndex, SpriteContents spriteContents) {
|
||||
return ModelBakery.ITEM_MODEL_GENERATOR.processFrames(layerIndex, "layer" + layerIndex, spriteContents);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,8 +131,7 @@ 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)
|
||||
{
|
||||
public static List<BlockElement> createUnbakedItemMaskElements(int layerIndex, SpriteContents spriteContents) {
|
||||
var elements = createUnbakedItemElements(layerIndex, spriteContents);
|
||||
elements.remove(0); // Remove north and south faces
|
||||
|
||||
@@ -152,16 +147,12 @@ public class UnbakedGeometryHelper
|
||||
});
|
||||
|
||||
// Scan in search of opaque pixels
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int y = 0; y < height; y++) {
|
||||
int xStart = -1;
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int x = 0; x < width; x++) {
|
||||
var opaque = bits.get(x + y * width);
|
||||
if (opaque == (xStart == -1)) // (opaque && -1) || (!opaque && !-1)
|
||||
{
|
||||
if (xStart == -1)
|
||||
{
|
||||
if (opaque == (xStart == -1)) { // (opaque && -1) || (!opaque && !-1)
|
||||
if (xStart == -1) {
|
||||
// We have found the start of a new segment, continue
|
||||
xStart = x;
|
||||
continue;
|
||||
@@ -187,9 +178,7 @@ public class UnbakedGeometryHelper
|
||||
Util.make(new HashMap<>(), map -> {
|
||||
for (Direction direction : Direction.values())
|
||||
map.put(direction, new BlockElementFace(null, layerIndex, "layer" + layerIndex, new BlockFaceUV(null, 0)));
|
||||
}),
|
||||
null,
|
||||
true
|
||||
})
|
||||
));
|
||||
|
||||
// Reset xStart
|
||||
@@ -203,13 +192,11 @@ 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)
|
||||
{
|
||||
for (BlockElement element : elements)
|
||||
{
|
||||
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, ResourceLocation.parse(face.texture())));
|
||||
var quad = bakeElementFace(element, face, sprite, side, modelState);
|
||||
var sprite = spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, ResourceLocation.parse(face.texture())));
|
||||
var quad = bakeElementFace(element, face, sprite, side, modelState, element.lightEmission);
|
||||
if (face.cullForDirection() == null)
|
||||
builder.addUnculledFace(quad);
|
||||
else
|
||||
@@ -221,8 +208,7 @@ 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)
|
||||
{
|
||||
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>();
|
||||
@@ -233,9 +219,8 @@ public class UnbakedGeometryHelper
|
||||
/**
|
||||
* Turns a single {@link BlockElementFace} into a {@link BakedQuad}.
|
||||
*/
|
||||
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);
|
||||
public static BakedQuad bakeElementFace(BlockElement element, BlockElementFace face, TextureAtlasSprite sprite, Direction direction, ModelState state, int lightEmission) {
|
||||
return FACE_BAKERY.bakeQuad(element.from, element.to, face, sprite, direction, state, element.rotation, element.shade, lightEmission);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,8 +231,7 @@ public class UnbakedGeometryHelper
|
||||
* @return an {@code IQuadTransformer} that applies the root transform to a baked quad that already has the
|
||||
* transformation of the given {@code ModelState} applied to it
|
||||
*/
|
||||
public static IQuadTransformer applyRootTransform(ModelState modelState, Transformation rootTransform)
|
||||
{
|
||||
public static IQuadTransformer applyRootTransform(ModelState modelState, Transformation rootTransform) {
|
||||
// Move the origin of the ModelState transform and its inverse from the negative corner to the block center
|
||||
// to replicate the way the ModelState transform is applied in the FaceBakery by moving the vertices such that
|
||||
// the negative corner acts as the block center
|
||||
@@ -258,8 +242,7 @@ public class UnbakedGeometryHelper
|
||||
/**
|
||||
* {@return a {@link ModelState} that combines the existing model state and the {@linkplain Transformation root transform}}
|
||||
*/
|
||||
public static ModelState composeRootTransformIntoModelState(ModelState modelState, Transformation rootTransform)
|
||||
{
|
||||
public static ModelState composeRootTransformIntoModelState(ModelState modelState, Transformation rootTransform) {
|
||||
// Move the origin of the root transform as if the negative corner were the block center to match the way the
|
||||
// ModelState transform is applied in the FaceBakery by moving the vertices to be centered on that corner
|
||||
rootTransform = rootTransform.applyOrigin(new Vector3f(-.5F, -.5F, -.5F));
|
||||
|
||||
+23
-47
@@ -27,47 +27,34 @@ import java.util.List;
|
||||
/**
|
||||
* Wrapper around {@link ModelBlockRenderer} to allow rendering blocks via Forge's lighting pipeline.
|
||||
*/
|
||||
public class ForgeModelBlockRenderer extends ModelBlockRenderer
|
||||
{
|
||||
public class ForgeModelBlockRenderer extends ModelBlockRenderer {
|
||||
private static final Direction[] SIDES = Direction.values();
|
||||
|
||||
private final ThreadLocal<QuadLighter> flatLighter, smoothLighter;
|
||||
|
||||
public ForgeModelBlockRenderer(BlockColors colors)
|
||||
{
|
||||
public ForgeModelBlockRenderer(BlockColors colors) {
|
||||
super(colors);
|
||||
this.flatLighter = ThreadLocal.withInitial(() -> new FlatQuadLighter(colors));
|
||||
this.smoothLighter = ThreadLocal.withInitial(() -> new SmoothQuadLighter(colors));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tesselateWithoutAO(BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer vertexConsumer, boolean checkSides, RandomSource rand, long seed, int packedOverlay, ModelData modelData, RenderType renderType)
|
||||
{
|
||||
public void tesselateWithoutAO(BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer vertexConsumer, boolean checkSides, RandomSource rand, long seed, int packedOverlay, ModelData modelData, RenderType renderType) {
|
||||
if (ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.get())
|
||||
{
|
||||
render(vertexConsumer, flatLighter.get(), level, model, state, pos, poseStack, checkSides, rand, seed, packedOverlay, modelData, renderType);
|
||||
}
|
||||
else
|
||||
{
|
||||
super.tesselateWithoutAO(level, model, state, pos, poseStack, vertexConsumer, checkSides, rand, seed, packedOverlay, modelData, renderType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tesselateWithAO(BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer vertexConsumer, boolean checkSides, RandomSource rand, long seed, int packedOverlay, ModelData modelData, RenderType renderType)
|
||||
{
|
||||
public void tesselateWithAO(BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer vertexConsumer, boolean checkSides, RandomSource rand, long seed, int packedOverlay, ModelData modelData, RenderType renderType) {
|
||||
if (ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.get())
|
||||
{
|
||||
render(vertexConsumer, smoothLighter.get(), level, model, state, pos, poseStack, checkSides, rand, seed, packedOverlay, modelData, renderType);
|
||||
}
|
||||
else
|
||||
{
|
||||
super.tesselateWithAO(level, model, state, pos, poseStack, vertexConsumer, checkSides, rand, seed, packedOverlay, modelData, renderType);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean render(VertexConsumer vertexConsumer, QuadLighter lighter, BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, boolean checkSides, RandomSource rand, long seed, int packedOverlay, ModelData modelData, RenderType renderType)
|
||||
{
|
||||
public static boolean render(VertexConsumer vertexConsumer, QuadLighter lighter, BlockAndTintGetter level, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, boolean checkSides, RandomSource rand, long seed, int packedOverlay, ModelData modelData, RenderType renderType) {
|
||||
ForgeModelBlockRenderer renderer = (ForgeModelBlockRenderer)Minecraft.getInstance().getBlockRenderer().getModelRenderer();
|
||||
var pose = poseStack.last();
|
||||
var empty = true;
|
||||
@@ -76,64 +63,53 @@ public class ForgeModelBlockRenderer extends ModelBlockRenderer
|
||||
|
||||
rand.setSeed(seed);
|
||||
List<BakedQuad> quads = model.getQuads(state, null, rand, modelData, renderType);
|
||||
if (!quads.isEmpty())
|
||||
{
|
||||
if (!quads.isEmpty()) {
|
||||
empty = false;
|
||||
lighter.setup(level, pos, state);
|
||||
for (BakedQuad quad : quads)
|
||||
{
|
||||
if (smoothLighter && !quad.hasAmbientOcclusion())
|
||||
{
|
||||
if (flatLighter == null)
|
||||
{
|
||||
for (BakedQuad quad : quads) {
|
||||
if (smoothLighter && !quad.hasAmbientOcclusion()) {
|
||||
if (flatLighter == null) {
|
||||
flatLighter = renderer.flatLighter.get();
|
||||
flatLighter.setup(level, pos, state);
|
||||
}
|
||||
flatLighter.process(vertexConsumer, pose, quad, packedOverlay);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lighter.process(vertexConsumer, pose, quad, packedOverlay);
|
||||
}
|
||||
}
|
||||
}
|
||||
var mutable = pos.mutable();
|
||||
|
||||
for (Direction side : SIDES)
|
||||
{
|
||||
if (checkSides && !Block.shouldRenderFace(state, level, pos, side, pos.relative(side)))
|
||||
{
|
||||
for (Direction side : SIDES) {
|
||||
mutable.setWithOffset(pos, side);
|
||||
if (checkSides && !Block.shouldRenderFace(level, pos, state, level.getBlockState(mutable), side))
|
||||
continue;
|
||||
}
|
||||
rand.setSeed(seed);
|
||||
quads = model.getQuads(state, side, rand, modelData, renderType);
|
||||
if (!quads.isEmpty())
|
||||
{
|
||||
if (empty)
|
||||
{
|
||||
if (!quads.isEmpty()) {
|
||||
if (empty) {
|
||||
empty = false;
|
||||
lighter.setup(level, pos, state);
|
||||
}
|
||||
for (BakedQuad quad : quads)
|
||||
{
|
||||
if (smoothLighter && !quad.hasAmbientOcclusion())
|
||||
{
|
||||
if (flatLighter == null)
|
||||
{
|
||||
|
||||
for (BakedQuad quad : quads) {
|
||||
if (smoothLighter && !quad.hasAmbientOcclusion()) {
|
||||
if (flatLighter == null) {
|
||||
flatLighter = renderer.flatLighter.get();
|
||||
flatLighter.setup(level, pos, state);
|
||||
}
|
||||
flatLighter.process(vertexConsumer, pose, quad, packedOverlay);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lighter.process(vertexConsumer, pose, quad, packedOverlay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lighter.reset();
|
||||
if (flatLighter != null)
|
||||
flatLighter.reset();
|
||||
|
||||
return !empty;
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,7 @@ import net.minecraft.world.phys.shapes.Shapes;
|
||||
* Implementation of {@link QuadLighter} that lights {@link BakedQuad baked quads} using ambient occlusion and
|
||||
* light interpolation.
|
||||
*/
|
||||
public class SmoothQuadLighter extends QuadLighter
|
||||
{
|
||||
public class SmoothQuadLighter extends QuadLighter {
|
||||
private static final Direction[] SIDES = Direction.values();
|
||||
|
||||
private final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
|
||||
@@ -33,23 +32,18 @@ public class SmoothQuadLighter extends QuadLighter
|
||||
private final float[][][][] blockLight = new float[3][2][2][2];
|
||||
private final float[][][] ao = new float[3][3][3];
|
||||
|
||||
public SmoothQuadLighter(BlockColors colors)
|
||||
{
|
||||
public SmoothQuadLighter(BlockColors colors) {
|
||||
super(colors);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void computeLightingAt(BlockAndTintGetter level, BlockPos origin, BlockState state)
|
||||
{
|
||||
for (int x = 0; x <= 2; x++)
|
||||
{
|
||||
for (int y = 0; y <= 2; y++)
|
||||
{
|
||||
for (int z = 0; z <= 2; z++)
|
||||
{
|
||||
protected void computeLightingAt(BlockAndTintGetter level, BlockPos origin, BlockState state) {
|
||||
for (int x = 0; x <= 2; x++) {
|
||||
for (int y = 0; y <= 2; y++) {
|
||||
for (int z = 0; z <= 2; z++) {
|
||||
pos.setWithOffset(origin, x - 1, y - 1, z - 1);
|
||||
BlockState neighborState = level.getBlockState(pos);
|
||||
t[x][y][z] = neighborState.getLightBlock(level, pos) < 15;
|
||||
t[x][y][z] = neighborState.getLightBlock() < 15;
|
||||
int brightness = LevelRenderer.getLightColor(level, neighborState, pos);
|
||||
s[x][y][z] = LightTexture.sky(brightness);
|
||||
b[x][y][z] = LightTexture.block(brightness);
|
||||
@@ -57,16 +51,20 @@ public class SmoothQuadLighter extends QuadLighter
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Direction side : SIDES)
|
||||
{
|
||||
|
||||
for (Direction side : SIDES) {
|
||||
pos.setWithOffset(origin, side);
|
||||
BlockState neighborState = level.getBlockState(pos);
|
||||
|
||||
BlockState thisStateShape = state.canOcclude() && state.useShapeForLightOcclusion() ? state : Blocks.AIR.defaultBlockState();
|
||||
BlockState otherStateShape = neighborState.canOcclude() && neighborState.useShapeForLightOcclusion() ? neighborState : Blocks.AIR.defaultBlockState();
|
||||
|
||||
if (neighborState.getLightBlock(level, pos) == 15 || Shapes.faceShapeOccludes(thisStateShape.getFaceOcclusionShape(level, origin, side), otherStateShape.getFaceOcclusionShape(level, pos, side.getOpposite())))
|
||||
{
|
||||
if (neighborState.getLightBlock() == 15 ||
|
||||
Shapes.faceShapeOccludes(
|
||||
thisStateShape.getFaceOcclusionShape(side),
|
||||
otherStateShape.getFaceOcclusionShape(side.getOpposite())
|
||||
)
|
||||
) {
|
||||
int x = side.getStepX() + 1;
|
||||
int y = side.getStepY() + 1;
|
||||
int z = side.getStepZ() + 1;
|
||||
@@ -74,12 +72,10 @@ public class SmoothQuadLighter extends QuadLighter
|
||||
b[x][y][z] = Math.max(b[1][1][1] - 1, b[x][y][z]);
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < 2; x++)
|
||||
{
|
||||
for (int y = 0; y < 2; y++)
|
||||
{
|
||||
for (int z = 0; z < 2; z++)
|
||||
{
|
||||
|
||||
for (int x = 0; x < 2; x++) {
|
||||
for (int y = 0; y < 2; y++) {
|
||||
for (int z = 0; z < 2; z++) {
|
||||
int x1 = x * 2;
|
||||
int y1 = y * 2;
|
||||
int z1 = z * 2;
|
||||
@@ -116,8 +112,7 @@ public class SmoothQuadLighter extends QuadLighter
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float calculateBrightness(float[] position)
|
||||
{
|
||||
protected float calculateBrightness(float[] position) {
|
||||
float x = position[0], y = position[1], z = position[2];
|
||||
int sx = x < 0 ? 1 : 2;
|
||||
int sy = y < 0 ? 1 : 2;
|
||||
@@ -142,15 +137,13 @@ public class SmoothQuadLighter extends QuadLighter
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int calculateLightmap(float[] position, byte[] normal)
|
||||
{
|
||||
protected int calculateLightmap(float[] position, byte[] normal) {
|
||||
var block = (int) (calcLightmap(blockLight, position[0], position[1], position[2]) * 0xF0);
|
||||
var sky = (int) (calcLightmap(skyLight, position[0], position[1], position[2]) * 0xF0);
|
||||
return block | (sky << 16);
|
||||
}
|
||||
|
||||
private float combine(int c, int s1, int s2, int s3, boolean t0, boolean t1, boolean t2, boolean t3)
|
||||
{
|
||||
private float combine(int c, int s1, int s2, int s3, boolean t0, boolean t1, boolean t2, boolean t3) {
|
||||
if (c == 0 && !t0) c = Math.max(0, Math.max(s1, s2) - 1);
|
||||
if (s1 == 0 && !t1) s1 = Math.max(0, c - 1);
|
||||
if (s2 == 0 && !t2) s2 = Math.max(0, c - 1);
|
||||
@@ -158,14 +151,12 @@ public class SmoothQuadLighter extends QuadLighter
|
||||
return (c + s1 + s2 + s3) / (0xF * 4f);
|
||||
}
|
||||
|
||||
protected float calcLightmap(float[][][][] light, float x, float y, float z)
|
||||
{
|
||||
protected float calcLightmap(float[][][][] light, float x, float y, float z) {
|
||||
x *= 2;
|
||||
y *= 2;
|
||||
z *= 2;
|
||||
float l2 = x * x + y * y + z * z;
|
||||
if (l2 > 6 - 2e-2f)
|
||||
{
|
||||
if (l2 > 6 - 2e-2f) {
|
||||
float s = (float) Math.sqrt((6 - 2e-2f) / l2);
|
||||
x *= s;
|
||||
y *= s;
|
||||
@@ -176,40 +167,27 @@ public class SmoothQuadLighter extends QuadLighter
|
||||
float az = z > 0 ? z : -z;
|
||||
float e1 = 1 + 1e-4f;
|
||||
if (ax > 2 - 1e-4f && ay <= e1 && az <= e1)
|
||||
{
|
||||
x = x < 0 ? -2 + 1e-4f : 2 - 1e-4f;
|
||||
}
|
||||
else if (ay > 2 - 1e-4f && az <= e1 && ax <= e1)
|
||||
{
|
||||
y = y < 0 ? -2 + 1e-4f : 2 - 1e-4f;
|
||||
}
|
||||
else if (az > 2 - 1e-4f && ax <= e1 && ay <= e1)
|
||||
{
|
||||
z = z < 0 ? -2 + 1e-4f : 2 - 1e-4f;
|
||||
}
|
||||
ax = x > 0 ? x : -x;
|
||||
ay = y > 0 ? y : -y;
|
||||
az = z > 0 ? z : -z;
|
||||
if (ax <= e1 && ay + az > 3f - 1e-4f)
|
||||
{
|
||||
if (ax <= e1 && ay + az > 3f - 1e-4f) {
|
||||
float s = (3f - 1e-4f) / (ay + az);
|
||||
y *= s;
|
||||
z *= s;
|
||||
}
|
||||
else if (ay <= e1 && az + ax > 3f - 1e-4f)
|
||||
{
|
||||
} else if (ay <= e1 && az + ax > 3f - 1e-4f) {
|
||||
float s = (3f - 1e-4f) / (az + ax);
|
||||
z *= s;
|
||||
x *= s;
|
||||
}
|
||||
else if (az <= e1 && ax + ay > 3f - 1e-4f)
|
||||
{
|
||||
} else if (az <= e1 && ax + ay > 3f - 1e-4f) {
|
||||
float s = (3f - 1e-4f) / (ax + ay);
|
||||
x *= s;
|
||||
y *= s;
|
||||
}
|
||||
else if (ax + ay + az > 4 - 1e-4f)
|
||||
{
|
||||
} else if (ax + ay + az > 4 - 1e-4f) {
|
||||
float s = (4 - 1e-4f) / (ax + ay + az);
|
||||
x *= s;
|
||||
y *= s;
|
||||
@@ -219,12 +197,9 @@ public class SmoothQuadLighter extends QuadLighter
|
||||
float l = 0;
|
||||
float s = 0;
|
||||
|
||||
for (int ix = 0; ix <= 1; ix++)
|
||||
{
|
||||
for (int iy = 0; iy <= 1; iy++)
|
||||
{
|
||||
for (int iz = 0; iz <= 1; iz++)
|
||||
{
|
||||
for (int ix = 0; ix <= 1; ix++) {
|
||||
for (int iy = 0; iy <= 1; iy++) {
|
||||
for (int iz = 0; iz <= 1; iz++) {
|
||||
float vx = x * (1 - ix * 2);
|
||||
float vy = y * (1 - iy * 2);
|
||||
float vz = z * (1 - iz * 2);
|
||||
|
||||
@@ -431,7 +431,7 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
|
||||
quadBaker.setNormal(normal.x(), normal.y(), normal.z());
|
||||
if (i == 0)
|
||||
{
|
||||
quadBaker.setDirection(Direction.getNearest(normal.x(), normal.y(), normal.z()));
|
||||
quadBaker.setDirection(Direction.getApproximateNearest(normal.x(), normal.y(), normal.z()));
|
||||
}
|
||||
pos[i] = position;
|
||||
norm[i] = normal;
|
||||
|
||||
+27
-43
@@ -26,8 +26,7 @@ import java.util.function.Consumer;
|
||||
* This consumer accepts data in {@link com.mojang.blaze3d.vertex.DefaultVertexFormat#BLOCK} and is not picky about
|
||||
* ordering or missing elements, but will not automatically populate missing data (color will be black, for example).
|
||||
*/
|
||||
public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
{
|
||||
public class QuadBakingVertexConsumer implements VertexConsumer {
|
||||
private final Map<VertexFormatElement, Integer> ELEMENT_OFFSETS = Util.make(new IdentityHashMap<>(), map -> {
|
||||
int i = 0;
|
||||
for (var element : DefaultVertexFormat.BLOCK.getElements())
|
||||
@@ -46,15 +45,14 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
private TextureAtlasSprite sprite = UnitTextureAtlasSprite.INSTANCE;
|
||||
private boolean shade;
|
||||
private boolean hasAmbientOcclusion;
|
||||
private int lightEmission;
|
||||
|
||||
public QuadBakingVertexConsumer(Consumer<BakedQuad> quadConsumer)
|
||||
{
|
||||
public QuadBakingVertexConsumer(Consumer<BakedQuad> quadConsumer) {
|
||||
this.quadConsumer = quadConsumer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer addVertex(float x, float y, float z)
|
||||
{
|
||||
public VertexConsumer addVertex(float x, float y, float z) {
|
||||
if (vertexIndex++ == MAX_VERTICES)
|
||||
build();
|
||||
|
||||
@@ -66,8 +64,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer setNormal(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) |
|
||||
(((int) (y * 127.0f) & 0xFF) << 8) |
|
||||
@@ -76,8 +73,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer setColor(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) |
|
||||
((b & 0xFF) << 16) |
|
||||
@@ -87,8 +83,7 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer setUv(float u, float v)
|
||||
{
|
||||
public VertexConsumer setUv(float u, float v) {
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.UV0;
|
||||
quadData[offset] = Float.floatToRawIntBits(u);
|
||||
quadData[offset + 1] = Float.floatToRawIntBits(v);
|
||||
@@ -96,10 +91,8 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
{
|
||||
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
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + IQuadTransformer.UV1;
|
||||
quadData[offset] = (u & 0xFFFF) | ((v & 0xFFFF) << 16);
|
||||
}
|
||||
@@ -107,28 +100,24 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer setUv2(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);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer misc(VertexFormatElement element, int... rawData)
|
||||
{
|
||||
public VertexConsumer misc(VertexFormatElement element, int... rawData) {
|
||||
Integer baseOffset = ELEMENT_OFFSETS.get(element);
|
||||
if (baseOffset != null)
|
||||
{
|
||||
if (baseOffset != null) {
|
||||
int offset = vertexIndex * IQuadTransformer.STRIDE + baseOffset;
|
||||
System.arraycopy(rawData, 0, quadData, offset, rawData.length);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public BakedQuad build()
|
||||
{
|
||||
BakedQuad quad = new BakedQuad(quadData, tintIndex, direction, sprite, shade, hasAmbientOcclusion);
|
||||
public BakedQuad build() {
|
||||
BakedQuad quad = new BakedQuad(quadData, tintIndex, direction, sprite, shade, lightEmission, hasAmbientOcclusion);
|
||||
// We have a full quad, pass it to the consumer and reset
|
||||
quadConsumer.accept(quad);
|
||||
vertexIndex = 0;
|
||||
@@ -136,48 +125,43 @@ public class QuadBakingVertexConsumer implements VertexConsumer
|
||||
return quad;
|
||||
}
|
||||
|
||||
public void setTintIndex(int tintIndex)
|
||||
{
|
||||
public void setTintIndex(int tintIndex) {
|
||||
this.tintIndex = tintIndex;
|
||||
}
|
||||
|
||||
public void setDirection(Direction direction)
|
||||
{
|
||||
public void setDirection(Direction direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public void setSprite(TextureAtlasSprite sprite)
|
||||
{
|
||||
public void setSprite(TextureAtlasSprite sprite) {
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public void setShade(boolean shade)
|
||||
{
|
||||
public void setShade(boolean shade) {
|
||||
this.shade = shade;
|
||||
}
|
||||
|
||||
public void setHasAmbientOcclusion(boolean hasAmbientOcclusion)
|
||||
{
|
||||
public void setHasAmbientOcclusion(boolean hasAmbientOcclusion) {
|
||||
this.hasAmbientOcclusion = hasAmbientOcclusion;
|
||||
}
|
||||
|
||||
public static class Buffered extends QuadBakingVertexConsumer
|
||||
{
|
||||
public void setLightEmission(int value) {
|
||||
this.lightEmission = value;
|
||||
}
|
||||
|
||||
public static class Buffered extends QuadBakingVertexConsumer {
|
||||
private final BakedQuad[] output;
|
||||
|
||||
public Buffered()
|
||||
{
|
||||
public Buffered() {
|
||||
this(new BakedQuad[1]);
|
||||
}
|
||||
|
||||
private Buffered(BakedQuad[] output)
|
||||
{
|
||||
private Buffered(BakedQuad[] output) {
|
||||
super(q -> output[0] = q);
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public BakedQuad getQuad()
|
||||
{
|
||||
public BakedQuad getQuad() {
|
||||
var quad = Preconditions.checkNotNull(output[0], "No quad has been emitted. Vertices in buffer: " + vertexIndex);
|
||||
output[0] = null;
|
||||
return quad;
|
||||
|
||||
Reference in new issue
Block a user