From 9815d729b53a347a389700bc04fa8ac3ca4e1548 Mon Sep 17 00:00:00 2001 From: RainWarrior Date: Mon, 23 Nov 2015 10:12:01 +0300 Subject: [PATCH] Fixed NPE is B3D loader caused by the missing vertex normal; updated the example chest model - it's now has 2 meshes; Updated ModelAnimationDebug - it now uses the new chest model, renders the base with the static world renderer, and only the lid with the TESR. --- .../client/model/b3d/B3DModel.java | 20 +++++++++------ .../debug/ModelAnimationDebug.java | 16 ++++++++---- .../blockstates/test_animation_block.json | 23 ++++++++++++++++-- .../blockstates/CustomModelBlock.json | 5 +++- .../models/block/chest.b3d | Bin 6104 -> 5659 bytes 5 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/model/b3d/B3DModel.java b/src/main/java/net/minecraftforge/client/model/b3d/B3DModel.java index 60af64849..06c297099 100644 --- a/src/main/java/net/minecraftforge/client/model/b3d/B3DModel.java +++ b/src/main/java/net/minecraftforge/client/model/b3d/B3DModel.java @@ -636,13 +636,19 @@ public class B3DModel Vector3f rPos = new Vector3f(newPos.x / newPos.w, newPos.y / newPos.w, newPos.z / newPos.w); // normal - Matrix3f tm = new Matrix3f(); - t.getRotationScale(tm); - tm.invert(); - tm.transpose(); - Vector3f normal = new Vector3f(this.normal), rNormal = new Vector3f(); - tm.transform(normal, rNormal); - rNormal.normalize(); + Vector3f rNormal = null; + + if(this.normal != null) + { + Matrix3f tm = new Matrix3f(); + t.getRotationScale(tm); + tm.invert(); + tm.transpose(); + Vector3f normal = new Vector3f(this.normal); + rNormal = new Vector3f(); + tm.transform(normal, rNormal); + rNormal.normalize(); + } // texCoords TODO return new Vertex(rPos, rNormal, color, texCoords); diff --git a/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java b/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java index 48b8ec2a1..fbdb0e254 100644 --- a/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java +++ b/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java @@ -4,6 +4,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockPistonBase; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -25,6 +26,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.ITickable; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.client.model.ISmartBlockModel; import net.minecraftforge.client.model.ModelLoader; @@ -52,6 +54,7 @@ public class ModelAnimationDebug public static String blockName = "test_animation_block"; public static final PropertyDirection FACING = PropertyDirection.create("facing"); + public static final PropertyBool STATIC = PropertyBool.create("static");; @SidedProxy(serverSide = "net.minecraftforge.debug.ModelAnimationDebug$CommonProxy", clientSide = "net.minecraftforge.debug.ModelAnimationDebug$ClientProxy") public static CommonProxy proxy; @@ -71,12 +74,9 @@ public class ModelAnimationDebug @Override public ExtendedBlockState createBlockState() { - return new ExtendedBlockState(this, new IProperty[]{ FACING }, new IUnlistedProperty[]{ B3DFrameProperty.instance }); + return new ExtendedBlockState(this, new IProperty[]{ FACING, STATIC }, new IUnlistedProperty[]{ B3DFrameProperty.instance }); } - @Override - public int getRenderType() { return -1; } - @Override public boolean isOpaqueCube() { return false; } @@ -109,6 +109,11 @@ public class ModelAnimationDebug return new Chest(state); } + @Override + public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) { + return state.withProperty(STATIC, true); + } + /*@Override public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { TileEntity te = world.getTileEntity(pos); @@ -239,7 +244,8 @@ public class ModelAnimationDebug public void renderTileEntityAt(Chest te, double x, double y, double z, float partialTick, int breakStage) { IBlockState state = te.getWorld().getBlockState(te.getPos()); - IBakedModel model = this.blockRenderer.getModelFromBlockState(state, te.getWorld(), te.getPos()); + state = state.withProperty(STATIC, false); + IBakedModel model = this.blockRenderer.getBlockModelShapes().getModelForState(state); if(state instanceof IExtendedBlockState) { IExtendedBlockState exState = (IExtendedBlockState)state; diff --git a/src/test/resources/assets/forgedebugmodelanimation/blockstates/test_animation_block.json b/src/test/resources/assets/forgedebugmodelanimation/blockstates/test_animation_block.json index b12b0913d..2b46abd6c 100644 --- a/src/test/resources/assets/forgedebugmodelanimation/blockstates/test_animation_block.json +++ b/src/test/resources/assets/forgedebugmodelanimation/blockstates/test_animation_block.json @@ -6,13 +6,20 @@ }, "model": "forgedebugmodelloaderregistry:chest.b3d", "custom": { - "mesh": ["Cube.001"] + "mesh": ["Base", "Lid"] } }, "variants": { "normal": [{}], "inventory": [{ - "transform": "forge:default-block" + "transform": { + "rotation": { "y": 180 }, + "thirdperson": { + "rotation": [ { "z": 170 }, { "y": -45 }, { "z": 20 } ], + "translation": [ 0, 0.09375, -0.171875 ], + "scale": 0.375 + } + } }], "facing": { "down": { "transform": { "rotation": { "x": 90 } } }, @@ -21,6 +28,18 @@ "south": { "transform": "identity" }, "west": { "transform": { "rotation": { "y": 90 } } }, "east": { "transform": { "rotation": { "y": 270 } } } + }, + "static": { + "true": { + "custom": { + "mesh": ["Base"] + } + }, + "false": { + "custom": { + "mesh": ["Lid"] + } + } } } } diff --git a/src/test/resources/assets/forgedebugmodelloaderregistry/blockstates/CustomModelBlock.json b/src/test/resources/assets/forgedebugmodelloaderregistry/blockstates/CustomModelBlock.json index b1926396b..d8e22b4a6 100644 --- a/src/test/resources/assets/forgedebugmodelloaderregistry/blockstates/CustomModelBlock.json +++ b/src/test/resources/assets/forgedebugmodelloaderregistry/blockstates/CustomModelBlock.json @@ -6,7 +6,10 @@ "#chest": "entity/chest/normal" }, "model": "forgedebugmodelloaderregistry:chest.b3d", - "transform": "forge:default-block" + "transform": "forge:default-block", + "custom": { + "mesh": ["Base", "Lid"] + } }, "variants": { "normal": [{}], diff --git a/src/test/resources/assets/forgedebugmodelloaderregistry/models/block/chest.b3d b/src/test/resources/assets/forgedebugmodelloaderregistry/models/block/chest.b3d index b070d7a6fabd24734f4b11657566e347c321499e..5e5b6580809018b0ea5930b80c43926e3228e593 100644 GIT binary patch literal 5659 zcmeH~U5Hgx6vwxEb^7i$I#%}KZANpA1(U_W6G+LJRlJ`hN z6k-ob&4Ul26e;0LF+q9n2$m3pOfQ;3kq==;1O>-QB0McvJ-)tB+Co=rY-6?bZ!dX*5%? zj@8G@yL#{6BZnUo>hJ06{hosgF<{f!*yhL%W46fnbzn>m+d9EGS*!f_WjsSR6yzcu zaLCXd5@ufT)=27tZ}XnB?||s3tYFVaXF}%dR&ke}xy}9-=@hIxlW#}udTF|~c3@kZ zofz4sb~qo5zlZu@AkwY%0kT}`dTIM6bZdO-`z7rxwP$wm=<8Y1yNBb&q;cmj@t-7| z6P_$QC7v@j2urS+%Z0Cq=ZsehUnP9C@HO$A@mk@$@O8qC@tkq0@HAmbb|V!Q%^9y3 zUbJG#a@K-aTk@?)lAn;n6gLmnCi%s&l7%k_kDed2E1#d#DO^6?JX|Suujo1wEx=D` zU5#rY!rNor*Lj3yUv& z%EIC=pR%ydr&V+o*7?0YEWYq5Yh4$=Dmn}6Vq72AC1-tDa>b{tGmz}(BzPoy^xim= zH}AFfEwYd7*d{NLP;L&AIJBQj!mpBKUoA<0s(Co5P55fEXd-BkHGmo%b-X%N9j4Au zL)8eaP7)p>;UN+patZIMp8q5~M8ZQPJVe4nBs@gIL&=0s+K=-li2W4&Lt_7VLfQ>!zIn34c(M>Ve1Bijl^XI)zXDCSbfwSY%eQVcC(@onW-Clg4K6QR^onVK^d3Ho> z3Ku%NRK~efMwbE(*_*=rR~fp<^71@Q7a4hTpJ4p;RHnMRUYJ-a*r}+vLh+shk3L;ogA^LSeV@kjvf(8*dh~Pm44kCCE0fY!5L;xXz z2oXq#U_t~EBA8IJ0di9Jt1suYFCGfRr!1_-Qt??>ip!@gtmcH`v#^>s^cMLM z)q~X>tq03R;!~DwTsS^uVQGL4NI?Ep$FBvu>^xnuF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