Fix Baked Item models with transformations (#5241)

This commit is contained in:
Ben Staddon 2018-11-23 23:28:30 +00:00 committed by tterrag
parent 52890edfac
commit 3920b7aaa3
4 changed files with 23 additions and 12 deletions

View file

@ -45,13 +45,20 @@ public class BakedItemModel implements IBakedModel
protected final ItemOverrideList overrides;
protected final IBakedModel guiModel;
/** @deprecated use {@link #BakedItemModel(ImmutableList, TextureAtlasSprite, ImmutableMap, ItemOverrideList, boolean)} */
@Deprecated // TODO: remove
public BakedItemModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, ImmutableMap<TransformType, TRSRTransformation> transforms, ItemOverrideList overrides)
{
this(quads, particle, transforms, overrides, true);
}
public BakedItemModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, ImmutableMap<TransformType, TRSRTransformation> transforms, ItemOverrideList overrides, boolean untransformed)
{
this.quads = quads;
this.particle = particle;
this.transforms = transforms;
this.overrides = overrides;
this.guiModel = hasGuiIdentity(transforms) ? new BakedGuiItemModel<>(this) : null;
this.guiModel = untransformed && hasGuiIdentity(transforms) ? new BakedGuiItemModel<>(this) : null;
}
private static boolean hasGuiIdentity(ImmutableMap<TransformType, TRSRTransformation> transforms)

View file

@ -120,6 +120,7 @@ public final class ItemLayerModel implements IUnbakedModel
public IBakedModel bake(Function<ResourceLocation, IUnbakedModel> modelGetter, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, IModelState state, boolean uvlock, VertexFormat format) {
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
Optional<TRSRTransformation> transform = state.apply(Optional.empty());
boolean identity = !transform.isPresent() || transform.get().isIdentity();
for(int i = 0; i < textures.size(); i++)
{
TextureAtlasSprite sprite = bakedTextureGetter.apply(textures.get(i));
@ -127,7 +128,7 @@ public final class ItemLayerModel implements IUnbakedModel
}
TextureAtlasSprite particle = bakedTextureGetter.apply(textures.isEmpty() ? new ResourceLocation("missingno") : textures.get(0));
ImmutableMap<TransformType, TRSRTransformation> map = PerspectiveMapWrapper.getTransforms(state);
return new BakedItemModel(builder.build(), particle, map, overrides);
return new BakedItemModel(builder.build(), particle, map, overrides, identity);
}
public static ImmutableList<BakedQuad> getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, Optional<TRSRTransformation> transform)
@ -411,12 +412,14 @@ public final class ItemLayerModel implements IUnbakedModel
private static void putVertex(UnpackedBakedQuad.Builder builder, VertexFormat format, Optional<TRSRTransformation> transform, EnumFacing side, float x, float y, float z, float u, float v)
{
Vector4f vec = new Vector4f();
boolean hasTransform = transform.isPresent() && !transform.get().isIdentity();
for(int e = 0; e < format.getElementCount(); e++)
{
switch(format.getElement(e).getUsage())
{
case POSITION:
if(transform.isPresent())
if(hasTransform)
{
vec.x = x;
vec.y = y;

View file

@ -177,7 +177,7 @@ public final class ModelDynBucket implements IUnbakedModel
}
}
return new BakedDynBucket(this, builder.build(), particleSprite, format, Maps.immutableEnumMap(transformMap), Maps.newHashMap());
return new BakedDynBucket(this, builder.build(), particleSprite, format, Maps.immutableEnumMap(transformMap), Maps.newHashMap(), transform.isIdentity());
}
/**
@ -465,14 +465,15 @@ public final class ModelDynBucket implements IUnbakedModel
private final Map<String, IBakedModel> cache; // contains all the baked models since they'll never change
private final VertexFormat format;
public BakedDynBucket(ModelDynBucket parent,
BakedDynBucket(ModelDynBucket parent,
ImmutableList<BakedQuad> quads,
TextureAtlasSprite particle,
VertexFormat format,
ImmutableMap<TransformType, TRSRTransformation> transforms,
Map<String, IBakedModel> cache)
Map<String, IBakedModel> cache,
boolean untransformed)
{
super(quads, particle, transforms, BakedDynBucketOverrideHandler.INSTANCE);
super(quads, particle, transforms, BakedDynBucketOverrideHandler.INSTANCE, untransformed);
this.format = format;
this.parent = parent;
this.cache = cache;

View file

@ -460,7 +460,7 @@ public final class ModelLoader extends ModelBakery
Map<TransformType, TRSRTransformation> tMap = Maps.newEnumMap(TransformType.class);
tMap.putAll(PerspectiveMapWrapper.getTransforms(transforms));
tMap.putAll(PerspectiveMapWrapper.getTransforms(state));
IModelState perState = new SimpleModelState(ImmutableMap.copyOf(tMap));
IModelState perState = new SimpleModelState(ImmutableMap.copyOf(tMap), state.apply(Optional.empty()));
if(model == ModelBakery.MODEL_GENERATED)
{