From cb909eeb59d32cbf651fe6da1954286c73b137be Mon Sep 17 00:00:00 2001 From: RainWarrior Date: Sat, 5 Mar 2016 05:02:34 +0300 Subject: [PATCH] Fixed B3D loader, fixed some obvious errors in ModelLoader. --- .../client/model/ModelLoader.java | 54 ++--- .../client/model/b3d/B3DLoader.java | 217 +++++++++--------- 2 files changed, 131 insertions(+), 140 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/model/ModelLoader.java b/src/main/java/net/minecraftforge/client/model/ModelLoader.java index 2b327cc79b..eb7731776c 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelLoader.java +++ b/src/main/java/net/minecraftforge/client/model/ModelLoader.java @@ -32,8 +32,8 @@ import net.minecraft.client.renderer.block.model.ItemModelGenerator; import net.minecraft.client.renderer.block.model.ModelBlock; import net.minecraft.client.renderer.block.model.ModelBlockDefinition; import net.minecraft.client.renderer.block.model.ModelBlockDefinition.MissingVariantException; -import net.minecraft.client.renderer.block.model.ModelBlockDefinition.Variant; -import net.minecraft.client.renderer.block.model.ModelBlockDefinition.Variants; +import net.minecraft.client.renderer.block.model.Variant; +import net.minecraft.client.renderer.block.model.VariantList; import net.minecraft.client.renderer.block.statemap.IStateMapper; import net.minecraft.client.renderer.texture.IIconCreator; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -53,7 +53,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.launchwrapper.Launch; import net.minecraft.util.EnumFacing; -import net.minecraft.util.IRegistry; +import net.minecraft.util.registry.IRegistry; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.animation.Animation; import net.minecraftforge.client.model.animation.IAnimatedModel; @@ -78,7 +78,6 @@ import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Throwables; -@SuppressWarnings("ALL") public class ModelLoader extends ModelBakery { private final Map stateModels = Maps.newHashMap(); @@ -132,7 +131,7 @@ public class ModelLoader extends ModelBakery } } }); - IFlexibleBakedModel missingBaked = missingModel.bake(missingModel.getDefaultState(), DefaultVertexFormats.ITEM, DefaultTextureGetter.instance); + IBakedModel missingBaked = missingModel.bake(missingModel.getDefaultState(), DefaultVertexFormats.ITEM, DefaultTextureGetter.instance); for (Entry e : stateModels.entrySet()) { if(e.getValue() == getMissingModel()) @@ -172,7 +171,7 @@ public class ModelLoader extends ModelBakery @Override protected void registerVariant(ModelBlockDefinition definition, ModelResourceLocation location) { - Variants variants = null; + VariantList variants = null; try { variants = definition.getVariants(location.getVariant()); @@ -480,7 +479,7 @@ public class ModelLoader extends ModelBakery { builder.add(loc); } - // mojang hardcode + /*// mojang hardcode if(model.getRootModel() == MODEL_COMPASS && !loc.equals(TextureMap.LOCATION_MISSING_TEXTURE)) { TextureAtlasSprite.setLocationNameCompass(loc.toString()); @@ -488,7 +487,7 @@ public class ModelLoader extends ModelBakery else if(model.getRootModel() == MODEL_CLOCK && !loc.equals(TextureMap.LOCATION_MISSING_TEXTURE)) { TextureAtlasSprite.setLocationNameClock(loc.toString()); - } + }*/ } } for(String s : model.textures.values()) @@ -501,7 +500,7 @@ public class ModelLoader extends ModelBakery return builder.build(); } - public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function bakedTextureGetter) + public IBakedModel bake(IModelState state, VertexFormat format, Function bakedTextureGetter) { if(!Attributes.moreSpecific(format, Attributes.DEFAULT_BAKED_FORMAT)) { @@ -533,11 +532,11 @@ public class ModelLoader extends ModelBakery { return new ItemLayerModel(model).bake(perState, format, bakedTextureGetter); } - if(isCustomRenderer(model)) return new IFlexibleBakedModel.Wrapper(new BuiltInModel(transforms), format); + if(isCustomRenderer(model)) return new BuiltInModel(transforms); return bakeNormal(model, perState, state.apply(Optional.absent()).or(TRSRTransformation.identity()), newTransforms, format, bakedTextureGetter, uvlock); } - private IFlexibleBakedModel bakeNormal(ModelBlock model, IModelState perState, final TRSRTransformation modelState, List newTransforms, VertexFormat format, final Function bakedTextureGetter, boolean uvLocked) + private IBakedModel bakeNormal(ModelBlock model, IModelState perState, final TRSRTransformation modelState, List newTransforms, VertexFormat format, final Function bakedTextureGetter, boolean uvLocked) { TextureAtlasSprite particle = bakedTextureGetter.apply(new ResourceLocation(model.resolveTextureName("particle"))); SimpleBakedModel.Builder builder = (new SimpleBakedModel.Builder(model)).setTexture(particle); @@ -567,7 +566,8 @@ public class ModelLoader extends ModelBakery } } - return new ISmartBlockModel.PerspectiveWrapper(new IPerspectiveAwareModel.MapWrapper(new IFlexibleBakedModel.Wrapper(builder.makeBakedModel(), format), perState)) + // FIXME + return new ISmartBlockModel.PerspectiveWrapper(new IPerspectiveAwareModel.MapWrapper(builder.makeBakedModel(), perState)) { public IBakedModel handleBlockState(IBlockState state) { @@ -576,7 +576,7 @@ public class ModelLoader extends ModelBakery }; } - private IBakedModel handleBlockState(IFlexibleBakedModel model, Function bakedTextureGetter, TRSRTransformation modelState, IBlockState state) + private IBakedModel handleBlockState(IBakedModel model, Function bakedTextureGetter, TRSRTransformation modelState, IBlockState state) { if(state instanceof IExtendedBlockState) { @@ -594,7 +594,7 @@ public class ModelLoader extends ModelBakery } @Override - public IModel retexture(ImmutableMap textures) + public VanillaModelWrapper retexture(ImmutableMap textures) { if (textures.isEmpty()) return this; @@ -724,11 +724,11 @@ public class ModelLoader extends ModelBakery private final List models = new ArrayList(); private final IModelState defaultState; - public WeightedRandomModel(ModelResourceLocation parent, Variants variants) + public WeightedRandomModel(ModelResourceLocation parent, VariantList variants) { - this.variants = variants.getVariants(); + this.variants = variants.func_188114_a(); ImmutableList.Builder> builder = ImmutableList.builder(); - for (Variant v : variants.getVariants()) + for (Variant v : this.variants) { ResourceLocation loc = v.getModelLocation(); locations.add(loc); @@ -793,7 +793,7 @@ public class ModelLoader extends ModelBakery return state; } - public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function bakedTextureGetter) + public IBakedModel bake(IModelState state, VertexFormat format, Function bakedTextureGetter) { if(!Attributes.moreSpecific(format, Attributes.DEFAULT_BAKED_FORMAT)) { @@ -812,7 +812,7 @@ public class ModelLoader extends ModelBakery Variant v = variants.get(i); builder.add(model.bake(addUV(v.isUvLocked(), MultiModelState.getPartState(state, model, i)), format, bakedTextureGetter), variants.get(i).getWeight()); } - return new FlexibleWeightedBakedModel(builder.build(), Attributes.DEFAULT_BAKED_FORMAT); + return builder.build(); } public IModelState getDefaultState() @@ -821,22 +821,6 @@ public class ModelLoader extends ModelBakery } } - private static class FlexibleWeightedBakedModel extends WeightedBakedModel implements IFlexibleBakedModel - { - private final VertexFormat format; - - public FlexibleWeightedBakedModel(WeightedBakedModel parent, VertexFormat format) - { - super(parent.models); - this.format = format; - } - - public VertexFormat getFormat() - { - return format; - } - } - public IModel getMissingModel() { if (missingModel == null) diff --git a/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java b/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java index eb60e170fe..271ee94185 100644 --- a/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java +++ b/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java @@ -19,11 +19,11 @@ import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType; +import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResourceManager; -import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.MathHelper; import net.minecraft.util.ResourceLocation; @@ -68,7 +68,6 @@ import com.google.gson.JsonParser; * To enable for your mod call instance.addDomain(modid). * If you need more control over accepted resources - extend the class, and register a new instance with ModelLoaderRegistry. */ -@SuppressWarnings("deprecation") public class B3DLoader implements ICustomModelLoader { public static final B3DLoader instance = new B3DLoader(); @@ -487,7 +486,7 @@ public class B3DLoader implements ICustomModelLoader } @Override - public IModel retexture(ImmutableMap textures) + public ModelWrapper retexture(ImmutableMap textures) { ImmutableMap.Builder builder = ImmutableMap.builder(); for(Map.Entry e : this.textures.entrySet()) @@ -509,7 +508,7 @@ public class B3DLoader implements ICustomModelLoader } @Override - public IModel process(ImmutableMap data) + public ModelWrapper process(ImmutableMap data) { if(data.containsKey("mesh")) { @@ -601,7 +600,7 @@ public class B3DLoader implements ICustomModelLoader private final VertexFormat format; private final ImmutableSet meshes; private final ImmutableMap textures; - private final LoadingCache cache; + private final LoadingCache cache; private ImmutableList quads; @@ -610,9 +609,9 @@ public class B3DLoader implements ICustomModelLoader this(node, state, smooth, gui3d, format, meshes, textures, CacheBuilder.newBuilder() .maximumSize(128) .expireAfterAccess(2, TimeUnit.MINUTES) - .build(new CacheLoader() + .build(new CacheLoader() { - public BakedWrapper load(Integer frame) throws Exception + public B3DState load(Integer frame) throws Exception { IModelState parent = state; Animation newAnimation = node.getAnimation(); @@ -621,12 +620,12 @@ public class B3DLoader implements ICustomModelLoader B3DState ps = (B3DState)parent; parent = ps.getParent(); } - return new BakedWrapper(node, new B3DState(newAnimation, frame, frame, 0, parent), smooth, gui3d, format, meshes, textures); + return new B3DState(newAnimation, frame, frame, 0, parent); } })); } - public BakedWrapper(Node node, IModelState state, boolean smooth, boolean gui3d, VertexFormat format, ImmutableSet meshes, ImmutableMap textures, LoadingCache cache) + public BakedWrapper(Node node, IModelState state, boolean smooth, boolean gui3d, VertexFormat format, ImmutableSet meshes, ImmutableMap textures, LoadingCache cache) { this.node = node; this.state = state; @@ -638,61 +637,113 @@ public class B3DLoader implements ICustomModelLoader this.cache = cache; } - // FIXME merge with handleBlockState @Override - public List getGeneralQuads() + public List func_188616_a(IBlockState state, EnumFacing side, long rand) { + if(side != null) return ImmutableList.of(); + IModelState modelState = this.state; + if(state instanceof IExtendedBlockState) + { + IExtendedBlockState exState = (IExtendedBlockState)state; + if(exState.getUnlistedNames().contains(B3DFrameProperty.instance)) + { + B3DState s = exState.getValue(B3DFrameProperty.instance); + if(s != null) + { + //return getCachedModel(s.getFrame()); + IModelState parent = this.state; + Animation newAnimation = s.getAnimation(); + if(parent instanceof B3DState) + { + B3DState ps = (B3DState)parent; + parent = ps.getParent(); + } + if(newAnimation == null) + { + newAnimation = node.getAnimation(); + } + if(s.getFrame() == s.getNextFrame()) + { + modelState = cache.getUnchecked(s.getFrame()); + } + else + { + modelState = new B3DState(newAnimation, s.getFrame(), s.getNextFrame(), s.getProgress(), parent); + } + } + } + else if(exState.getUnlistedNames().contains(Properties.AnimationProperty)) + { + // FIXME: should animation state handle the parent state, or should it remain here? + IModelState parent = this.state; + if(parent instanceof B3DState) + { + B3DState ps = (B3DState)parent; + parent = ps.getParent(); + } + IModelState newState = exState.getValue(Properties.AnimationProperty); + if(newState != null) + { + modelState = new ModelStateComposition(parent, newState); + } + } + } if(quads == null) { ImmutableList.Builder builder = ImmutableList.builder(); - for(Node child : node.getNodes().values()) - { - builder.addAll(new BakedWrapper(child, state, smooth, gui3d, format, meshes, textures).getGeneralQuads()); - } - if(node.getKind() instanceof Mesh && meshes.contains(node.getName())) - { - Mesh mesh = (Mesh)node.getKind(); - Collection faces = mesh.bake(new Function, Matrix4f>() - { - private final TRSRTransformation global = state.apply(Optional.absent()).or(TRSRTransformation.identity()); - private final LoadingCache, TRSRTransformation> localCache = CacheBuilder.newBuilder() - .maximumSize(32) - .build(new CacheLoader, TRSRTransformation>() - { - public TRSRTransformation load(Node node) throws Exception - { - return state.apply(Optional.of(new NodeJoint(node))).or(TRSRTransformation.identity()); - } - }); - - public Matrix4f apply(Node node) - { - return global.compose(localCache.getUnchecked(node)).getMatrix(); - } - }); - for(Face f : faces) - { - UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(format); - quadBuilder.setQuadOrientation(EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z)); - quadBuilder.setQuadColored(); - List textures = null; - if(f.getBrush() != null) textures = f.getBrush().getTextures(); - TextureAtlasSprite sprite; - if(textures == null || textures.isEmpty()) sprite = this.textures.get("missingno"); - else if(textures.get(0) == B3DModel.Texture.White) sprite = ModelLoader.White.instance; - else sprite = this.textures.get(textures.get(0).getPath()); - putVertexData(quadBuilder, f.getV1(), f.getNormal(), sprite); - putVertexData(quadBuilder, f.getV2(), f.getNormal(), sprite); - putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite); - putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite); - builder.add(quadBuilder.build()); - } - } + generateQuads(builder, node, modelState); quads = builder.build(); } return quads; } + protected void generateQuads(ImmutableList.Builder builder, Node node, final IModelState state) + { + for(Node child : node.getNodes().values()) + { + generateQuads(builder, child, state); + } + if(node.getKind() instanceof Mesh && meshes.contains(node.getName())) + { + Mesh mesh = (Mesh)node.getKind(); + Collection faces = mesh.bake(new Function, Matrix4f>() + { + private final TRSRTransformation global = state.apply(Optional.absent()).or(TRSRTransformation.identity()); + private final LoadingCache, TRSRTransformation> localCache = CacheBuilder.newBuilder() + .maximumSize(32) + .build(new CacheLoader, TRSRTransformation>() + { + public TRSRTransformation load(Node node) throws Exception + { + return state.apply(Optional.of(new NodeJoint(node))).or(TRSRTransformation.identity()); + } + }); + + public Matrix4f apply(Node node) + { + return global.compose(localCache.getUnchecked(node)).getMatrix(); + } + }); + for(Face f : faces) + { + UnpackedBakedQuad.Builder quadBuilder = new UnpackedBakedQuad.Builder(format); + quadBuilder.setQuadOrientation(EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z)); + quadBuilder.setQuadColored(); + List textures = null; + if(f.getBrush() != null) textures = f.getBrush().getTextures(); + TextureAtlasSprite sprite; + if(textures == null || textures.isEmpty()) sprite = this.textures.get("missingno"); + else if(textures.get(0) == B3DModel.Texture.White) sprite = ModelLoader.White.instance; + else sprite = this.textures.get(textures.get(0).getPath()); + putVertexData(quadBuilder, f.getV1(), f.getNormal(), sprite); + putVertexData(quadBuilder, f.getV2(), f.getNormal(), sprite); + putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite); + putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite); + builder.add(quadBuilder.build()); + } + } + } + private final void putVertexData(UnpackedBakedQuad.Builder builder, Vertex v, Vector3f faceNormal, TextureAtlasSprite sprite) { // TODO handle everything not handled (texture transformations, bones, transformations, normals, e.t.c) @@ -772,60 +823,16 @@ public class B3DLoader implements ICustomModelLoader return ItemCameraTransforms.DEFAULT; } - // FIXME merge with getQuads - @Override - public BakedWrapper handleBlockState(IBlockState state) - { - if(state instanceof IExtendedBlockState) - { - IExtendedBlockState exState = (IExtendedBlockState)state; - if(exState.getUnlistedNames().contains(B3DFrameProperty.instance)) - { - B3DState s = exState.getValue(B3DFrameProperty.instance); - if(s != null) - { - //return getCachedModel(s.getFrame()); - IModelState parent = this.state; - Animation newAnimation = s.getAnimation(); - if(parent instanceof B3DState) - { - B3DState ps = (B3DState)parent; - parent = ps.getParent(); - } - if(newAnimation == null) - { - newAnimation = node.getAnimation(); - } - if(s.getFrame() == s.getNextFrame()) - { - return cache.getUnchecked(s.getFrame()); - } - B3DState newState = new B3DState(newAnimation, s.getFrame(), s.getNextFrame(), s.getProgress(), parent); - return new BakedWrapper(node, newState, smooth, gui3d, format, meshes, textures); - } - } - else if(exState.getUnlistedNames().contains(Properties.AnimationProperty)) - { - // FIXME: should animation state handle the parent state, or should it remain here? - IModelState parent = this.state; - if(parent instanceof B3DState) - { - B3DState ps = (B3DState)parent; - parent = ps.getParent(); - } - IModelState newState = exState.getValue(Properties.AnimationProperty); - if(newState != null) - { - return new BakedWrapper(node, new ModelStateComposition(parent, newState), smooth, gui3d, format, meshes, textures); - } - } - } - return this; - } - public Pair handlePerspective(TransformType cameraTransformType) { return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, state, cameraTransformType); } + + @Override + public ItemOverrideList func_188617_f() + { + // TODO handle items + return ItemOverrideList.field_188022_a; + } } }