Fix CompositeModel not respecting "display" transforms.
Remove leftovers from discarded feature.
This commit is contained in:
parent
ecb56054bc
commit
ca031ca33f
5 changed files with 36 additions and 211 deletions
|
@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.gson.JsonDeserializationContext;
|
import com.google.gson.JsonDeserializationContext;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.client.renderer.model.*;
|
import net.minecraft.client.renderer.model.*;
|
||||||
|
@ -51,14 +52,16 @@ public class CompositeModel implements IBakedModel
|
||||||
private final boolean isGui3d;
|
private final boolean isGui3d;
|
||||||
private final TextureAtlasSprite particle;
|
private final TextureAtlasSprite particle;
|
||||||
private final ItemOverrideList overrides;
|
private final ItemOverrideList overrides;
|
||||||
|
private final IModelTransform transforms;
|
||||||
|
|
||||||
public CompositeModel(boolean isGui3d, boolean isAmbientOcclusion, TextureAtlasSprite particle, ImmutableMap<String, IBakedModel> bakedParts, ItemOverrideList overrides)
|
public CompositeModel(boolean isGui3d, boolean isAmbientOcclusion, TextureAtlasSprite particle, ImmutableMap<String, IBakedModel> bakedParts, IModelTransform combinedTransform, ItemOverrideList overrides)
|
||||||
{
|
{
|
||||||
this.bakedParts = bakedParts;
|
this.bakedParts = bakedParts;
|
||||||
this.isAmbientOcclusion = isAmbientOcclusion;
|
this.isAmbientOcclusion = isAmbientOcclusion;
|
||||||
this.isGui3d = isGui3d;
|
this.isGui3d = isGui3d;
|
||||||
this.particle = particle;
|
this.particle = particle;
|
||||||
this.overrides = overrides;
|
this.overrides = overrides;
|
||||||
|
this.transforms = combinedTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -116,6 +119,18 @@ public class CompositeModel implements IBakedModel
|
||||||
return overrides;
|
return overrides;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean doesHandlePerspectives()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBakedModel handlePerspective(ItemCameraTransforms.TransformType cameraTransformType, MatrixStack mat)
|
||||||
|
{
|
||||||
|
return PerspectiveMapWrapper.handlePerspective(this, transforms, cameraTransformType, mat);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public IBakedModel getPart(String name)
|
public IBakedModel getPart(String name)
|
||||||
{
|
{
|
||||||
|
@ -218,7 +233,7 @@ public class CompositeModel implements IBakedModel
|
||||||
continue;
|
continue;
|
||||||
bakedParts.put(part.getKey(), submodel.func_225613_a_(bakery, spriteGetter, modelTransform, modelLocation));
|
bakedParts.put(part.getKey(), submodel.func_225613_a_(bakery, spriteGetter, modelTransform, modelLocation));
|
||||||
}
|
}
|
||||||
return new CompositeModel(owner.isShadedInGui(), owner.useSmoothLighting(), particle, bakedParts.build(), overrides);
|
return new CompositeModel(owner.isShadedInGui(), owner.useSmoothLighting(), particle, bakedParts.build(), owner.getCombinedTransform(), overrides);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -338,46 +338,6 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
return Optional.ofNullable(parts.get(name));
|
return Optional.ofNullable(parts.get(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public VertexFormat calculateBestVertexFormat(@Nullable VertexFormat base)
|
|
||||||
{
|
|
||||||
List<VertexFormatElement> elements = Lists.newArrayList(base.func_227894_c_());
|
|
||||||
|
|
||||||
addElementIfNotPresent(elements, DefaultVertexFormats.POSITION_3F);
|
|
||||||
|
|
||||||
if (texCoords.size() > 0)
|
|
||||||
{
|
|
||||||
addElementIfNotPresent(elements, DefaultVertexFormats.TEX_2F);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (normals.size() > 0)
|
|
||||||
{
|
|
||||||
addElementIfNotPresent(elements, DefaultVertexFormats.NORMAL_3B);
|
|
||||||
addElementIfNotPresent(elements, DefaultVertexFormats.PADDING_1B);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (colors.size() > 0)
|
|
||||||
{
|
|
||||||
addElementIfNotPresent(elements, DefaultVertexFormats.COLOR_4UB);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ambientToFullbright && parts.values().stream().anyMatch(ModelGroup::hasAnyFullBright))
|
|
||||||
{
|
|
||||||
addElementIfNotPresent(elements, DefaultVertexFormats.TEX_2S);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new VertexFormat(ImmutableList.copyOf(elements));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void addElementIfNotPresent(List<VertexFormatElement> fmt, VertexFormatElement element)
|
|
||||||
{
|
|
||||||
for(VertexFormatElement e : fmt)
|
|
||||||
{
|
|
||||||
if (e.getUsage() == element.getUsage() && e.getIndex() == element.getIndex())
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fmt.add(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Pair<BakedQuad,Direction> makeQuad(int[][] indices, int tintIndex, Vector4f colorTint, Vector4f ambientColor, boolean isFullbright, TextureAtlasSprite texture, VertexFormat format, TransformationMatrix transform)
|
private Pair<BakedQuad,Direction> makeQuad(int[][] indices, int tintIndex, Vector4f colorTint, Vector4f ambientColor, boolean isFullbright, TextureAtlasSprite texture, VertexFormat format, TransformationMatrix transform)
|
||||||
{
|
{
|
||||||
boolean needsNormalRecalculation = false;
|
boolean needsNormalRecalculation = false;
|
||||||
|
@ -539,23 +499,6 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public BakedGeometryRenderable<Void> bakeRenderable()
|
|
||||||
{
|
|
||||||
return bakeRenderable(DummyAtlasSprite.GETTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BakedGeometryRenderable<Void> bakeRenderable(Function<ResourceLocation, TextureAtlasSprite> spriteGetter)
|
|
||||||
{
|
|
||||||
return BakedGeometryRenderable.of(GL11.GL_QUADS, calculateBestVertexFormat(null), ((bufferBuilder, fmt) -> {
|
|
||||||
this.addQuads(
|
|
||||||
new StandaloneModelConfiguration("", true, diffuseLighting),
|
|
||||||
new VertexBufferModelBuilder(bufferBuilder),
|
|
||||||
null, spriteGetter, SimpleModelTransform.IDENTITY, fmt);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ModelObject implements IModelGeometryPart
|
public class ModelObject implements IModelGeometryPart
|
||||||
{
|
{
|
||||||
public final String name;
|
public final String name;
|
||||||
|
@ -668,86 +611,4 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
return mat != null && TransformationHelper.epsilonEquals(mat.ambientColor, new Vector4f(1,1,1,1), 1/256f);
|
return mat != null && TransformationHelper.epsilonEquals(mat.ambientColor, new Vector4f(1,1,1,1), 1/256f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
private static class VertexBufferModelBuilder implements IModelBuilder<VertexBufferModelBuilder>
|
|
||||||
{
|
|
||||||
private final BufferBuilder bufferBuilder;
|
|
||||||
|
|
||||||
public VertexBufferModelBuilder(BufferBuilder bufferBuilder)
|
|
||||||
{
|
|
||||||
this.bufferBuilder = bufferBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VertexBufferModelBuilder addFaceQuad(Direction facing, BakedQuad quad)
|
|
||||||
{
|
|
||||||
LightUtil.renderQuadColor(bufferBuilder, quad, -1);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VertexBufferModelBuilder addGeneralQuad(BakedQuad quad)
|
|
||||||
{
|
|
||||||
LightUtil.renderQuadColor(bufferBuilder, quad, -1);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBakedModel build()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class StandaloneModelConfiguration implements IModelConfiguration
|
|
||||||
{
|
|
||||||
private final String modelName;
|
|
||||||
private final boolean diffuseLighting;
|
|
||||||
private final boolean directionalLighting;
|
|
||||||
|
|
||||||
private StandaloneModelConfiguration(String modelName, boolean directionalLighting, boolean diffuseLighting)
|
|
||||||
{
|
|
||||||
this.modelName = modelName;
|
|
||||||
this.directionalLighting = directionalLighting;
|
|
||||||
this.diffuseLighting = diffuseLighting;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getModelName()
|
|
||||||
{
|
|
||||||
return modelName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Material resolveTexture(String name)
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isShadedInGui()
|
|
||||||
{
|
|
||||||
return directionalLighting;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean useSmoothLighting()
|
|
||||||
{
|
|
||||||
return diffuseLighting;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemCameraTransforms getCameraTransforms()
|
|
||||||
{
|
|
||||||
return ItemCameraTransforms.DEFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IModelTransform getCombinedTransform()
|
|
||||||
{
|
|
||||||
return SimpleModelTransform.IDENTITY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,37 +98,5 @@ public class NewModelLoaderTest
|
||||||
|
|
||||||
BLOCKS.register(modEventBus);
|
BLOCKS.register(modEventBus);
|
||||||
ITEMS.register(modEventBus);
|
ITEMS.register(modEventBus);
|
||||||
|
|
||||||
/*DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
|
|
||||||
MinecraftForge.EVENT_BUS.addListener(this::renderGuiOverlay);
|
|
||||||
});*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
private NonNullLazy<IRenderable.Configured<?>> modelRenderer = NonNullLazy.of(() -> {
|
|
||||||
OBJModel model = OBJLoader.INSTANCE.loadModel(new ResourceLocation("new_model_loader_test", "models/item/sugar_glider.obj"), false, false, true, false);
|
|
||||||
return IRenderable.withParameter(model.bakeRenderable(ModelLoader.defaultTextureGetter()), null);
|
|
||||||
});
|
|
||||||
|
|
||||||
private NonNullLazy<BakedModelRenderable> modelRenderer2 = NonNullLazy.of(() -> {
|
|
||||||
return BakedModelRenderable.of(new ItemStack(Items.COAL));
|
|
||||||
});
|
|
||||||
|
|
||||||
public void renderGuiOverlay(RenderGameOverlayEvent.Post event)
|
|
||||||
{
|
|
||||||
if (event.getType() == RenderGameOverlayEvent.ElementType.ALL)
|
|
||||||
{
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
|
||||||
mc.getTextureManager().bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE);
|
|
||||||
RenderSystem.pushMatrix();
|
|
||||||
RenderSystem.translatef(event.getWindow().getScaledWidth() / 2.0f, event.getWindow().getScaledHeight() / 2.0f, 200);
|
|
||||||
RenderSystem.scalef(16,16,16);
|
|
||||||
//mc.getItemRenderer().renderItemAndEffectIntoGUI(new ItemStack(Items.COAL),0,0);
|
|
||||||
modelRenderer.get().render();
|
|
||||||
RenderSystem.translatef(1,1,1);
|
|
||||||
modelRenderer2.get().render(new BakedModelRenderable.Context().withPerspective(ItemCameraTransforms.TransformType.GUI).withStack(new ItemStack(Items.COAL)));
|
|
||||||
RenderSystem.popMatrix();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
{
|
|
||||||
"parent": "forge:item/default",
|
|
||||||
"loader": "forge:composite",
|
|
||||||
"models": [
|
|
||||||
{
|
|
||||||
"loader": "...",
|
|
||||||
"transform": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"loader": "...",
|
|
||||||
"transform": {}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -16,39 +16,34 @@
|
||||||
},
|
},
|
||||||
"display": {
|
"display": {
|
||||||
"gui": {
|
"gui": {
|
||||||
"rotation": [ 30, 45, 0 ],
|
"rotation": [ 30, 225, 0 ],
|
||||||
"translation": [ 0, 3, 0 ],
|
"translation": [ 0, 0, 0],
|
||||||
"scale": [ 1, 1, 1 ]
|
"scale":[ 0.625, 1.625, 0.625 ]
|
||||||
},
|
|
||||||
"fixed": {
|
|
||||||
"rotation": [ 22, 180, 0 ],
|
|
||||||
"translation": [ 0, 4, 0],
|
|
||||||
"scale":[ 1, 1, 1 ]
|
|
||||||
},
|
},
|
||||||
"ground": {
|
"ground": {
|
||||||
"rotation": [ 0, 0, 0 ],
|
"rotation": [ 0, 0, 0 ],
|
||||||
"translation": [ 0, 3, 0 ],
|
"translation": [ 0, 3, 0],
|
||||||
"scale": [ 0.5, 0.5, 0.5 ]
|
"scale":[ 0.25, 0.25, 0.25 ]
|
||||||
},
|
},
|
||||||
"head": {
|
"fixed": {
|
||||||
"rotation": [ 0, 180, 0 ],
|
"rotation": [ 0, 0, 0 ],
|
||||||
"translation": [ 0, 5, 0 ],
|
"translation": [ 0, 0, 0],
|
||||||
"scale":[ 1.5, 1.5, 1.5 ]
|
"scale":[ 0.5, 0.5, 0.5 ]
|
||||||
},
|
},
|
||||||
"thirdperson_righthand": {
|
"thirdperson_righthand": {
|
||||||
"rotation": [ 45, 45, 0 ],
|
"rotation": [ 75, 45, 0 ],
|
||||||
"translation": [ 0, 3, 0 ],
|
"translation": [ 0, 2.5, 0],
|
||||||
"scale": [ 0.5, 0.5, 0.5 ]
|
"scale": [ 0.375, 0.375, 0.375 ]
|
||||||
}
|
},
|
||||||
},
|
|
||||||
"transform": {
|
|
||||||
"firstperson_righthand": {
|
"firstperson_righthand": {
|
||||||
"scale": 2.0,
|
"rotation": [ 0, 45, 0 ],
|
||||||
"translation": [0,0.5,0]
|
"translation": [ 0, 0, 0 ],
|
||||||
|
"scale": [ 0.40, 0.40, 0.40 ]
|
||||||
},
|
},
|
||||||
"firstperson_lefthand": {
|
"firstperson_lefthand": {
|
||||||
"scale": 0.5,
|
"rotation": [ 0, 225, 0 ],
|
||||||
"translation": [0,1.5,1.5]
|
"translation": [ 0, 0, 0 ],
|
||||||
|
"scale": [ 0.40, 0.40, 0.40 ]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"visibility": {
|
"visibility": {
|
||||||
|
|
Loading…
Reference in a new issue