From 877f87afe491a7f4f4c1f40aab5928075ad09b9d Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Sat, 15 Oct 2016 13:12:53 +0200 Subject: [PATCH] Fixes #2414: Sky Compass not respecting placement face. --- .../appeng/block/misc/BlockSkyCompass.java | 2 +- .../block/misc/SkyCompassRendering.java | 2 - .../render/model/AutoRotatingModel.java | 71 +++++++++++++++---- .../client/render/tesr/SkyCompassTESR.java | 17 ++++- 4 files changed, 72 insertions(+), 20 deletions(-) diff --git a/src/main/java/appeng/block/misc/BlockSkyCompass.java b/src/main/java/appeng/block/misc/BlockSkyCompass.java index ee9dfde2..42ab13eb 100644 --- a/src/main/java/appeng/block/misc/BlockSkyCompass.java +++ b/src/main/java/appeng/block/misc/BlockSkyCompass.java @@ -58,7 +58,7 @@ public class BlockSkyCompass extends AEBaseTileBlock implements ICustomCollision @Override protected BlockStateContainer createBlockState() { - return new ExtendedBlockState( this, getAEStates(), new IUnlistedProperty[] { ROTATION } ); + return new ExtendedBlockState( this, getAEStates(), new IUnlistedProperty[] { FORWARD, UP, ROTATION } ); } @Override diff --git a/src/main/java/appeng/block/misc/SkyCompassRendering.java b/src/main/java/appeng/block/misc/SkyCompassRendering.java index ecc9aebb..2bbe1905 100644 --- a/src/main/java/appeng/block/misc/SkyCompassRendering.java +++ b/src/main/java/appeng/block/misc/SkyCompassRendering.java @@ -40,8 +40,6 @@ public class SkyCompassRendering extends BlockRenderingCustomizer public void customize( IBlockRendering rendering, IItemRendering itemRendering ) { rendering.tesr( new SkyCompassTESR() ); - // This disables the default smart-rotating model - rendering.modelCustomizer( ( loc, model ) -> model ); itemRendering.model( ITEM_MODEL ); itemRendering.builtInModel( "models/block/builtin/sky_compass", new SkyCompassModel() ); } diff --git a/src/main/java/appeng/client/render/model/AutoRotatingModel.java b/src/main/java/appeng/client/render/model/AutoRotatingModel.java index 6f604995..6e601c99 100644 --- a/src/main/java/appeng/client/render/model/AutoRotatingModel.java +++ b/src/main/java/appeng/client/render/model/AutoRotatingModel.java @@ -21,7 +21,6 @@ package appeng.client.render.model; import java.util.ArrayList; import java.util.List; - import javax.vecmath.Vector3f; import javax.vecmath.Vector4f; @@ -80,7 +79,15 @@ public class AutoRotatingModel implements IBakedModel VertexRotator rot = new VertexRotator( f2r, quad.getFace() ); rot.setParent( builder ); quad.pipe( rot ); - builder.setQuadOrientation( f2r.rotate( quad.getFace() ) ); + if( quad.getFace() != null ) + { + builder.setQuadOrientation( f2r.rotate( quad.getFace() ) ); + } + else + { + builder.setQuadOrientation( null ); + + } BakedQuad q = builder.build(); rotated.add( q ); } @@ -238,20 +245,56 @@ public class AutoRotatingModel implements IBakedModel private float[] transformNormal( float[] fs ) { - switch( fs.length ) + if( face == null ) { - case 3: - Vec3i vec = f2r.rotate( face ).getDirectionVec(); - return new float[] { vec.getX(), vec.getY(), vec.getZ() - }; - case 4: - Vector4f veccc = new Vector4f( fs[0], fs[1], fs[2], fs[3] ); - Vec3i vecc = f2r.rotate( face ).getDirectionVec(); - return new float[] { vecc.getX(), vecc.getY(), vecc.getZ(), veccc.w - }; + switch( fs.length ) + { + case 3: + Vector3f vec = new Vector3f( fs ); + f2r.getMat().transform( vec ); + return new float[] { + vec.getX(), + vec.getY(), + vec.getZ() + }; + case 4: + Vector4f vec4 = new Vector4f( fs ); + f2r.getMat().transform( vec4 ); + return new float[] { + vec4.getX(), + vec4.getY(), + vec4.getZ(), + 0 + }; - default: - return fs; + default: + return fs; + } + } + else + { + switch( fs.length ) + { + case 3: + Vec3i vec = f2r.rotate( face ).getDirectionVec(); + return new float[] { + vec.getX(), + vec.getY(), + vec.getZ() + }; + case 4: + Vector4f veccc = new Vector4f( fs[0], fs[1], fs[2], fs[3] ); + Vec3i vecc = f2r.rotate( face ).getDirectionVec(); + return new float[] { + vecc.getX(), + vecc.getY(), + vecc.getZ(), + veccc.w + }; + + default: + return fs; + } } } diff --git a/src/main/java/appeng/client/render/tesr/SkyCompassTESR.java b/src/main/java/appeng/client/render/tesr/SkyCompassTESR.java index 00daa280..ce687013 100644 --- a/src/main/java/appeng/client/render/tesr/SkyCompassTESR.java +++ b/src/main/java/appeng/client/render/tesr/SkyCompassTESR.java @@ -34,6 +34,7 @@ import net.minecraftforge.common.property.Properties; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import appeng.block.AEBaseTileBlock; import appeng.block.misc.BlockSkyCompass; import appeng.client.render.model.SkyCompassBakedModel; import appeng.tile.misc.TileSkyCompass; @@ -69,11 +70,21 @@ public class SkyCompassTESR extends FastTESR if( state instanceof IExtendedBlockState ) { - IExtendedBlockState exState = (IExtendedBlockState) state; + IExtendedBlockState exState = (IExtendedBlockState) state.getBlock().getExtendedState( state, world, pos ); IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState( exState.getClean() ); exState = exState.withProperty( BlockSkyCompass.ROTATION, getRotation( te ) ); + // Flip forward/up for rendering, the base model is facing up without any rotation + EnumFacing forward = exState.getValue( AEBaseTileBlock.FORWARD ); + EnumFacing up = exState.getValue( AEBaseTileBlock.UP ); + // This ensures the needle isn't flipped by the model rotator. Since the model is symmetrical, this should not affect the appearance + if ( forward == EnumFacing.UP || forward == EnumFacing.DOWN ) { + up = EnumFacing.NORTH; + } + exState = exState.withProperty( AEBaseTileBlock.FORWARD, up ) + .withProperty( AEBaseTileBlock.UP, forward ); + buffer.setTranslation( x - pos.getX(), y - pos.getY(), z - pos.getZ() ); blockRenderer.getBlockModelRenderer().renderModel( world, model, exState, pos, buffer, false ); @@ -84,7 +95,7 @@ public class SkyCompassTESR extends FastTESR { float rotation; - if( skyCompass.getUp() == EnumFacing.UP || skyCompass.getUp() == EnumFacing.DOWN ) + if( skyCompass.getForward() == EnumFacing.UP || skyCompass.getForward() == EnumFacing.DOWN ) { rotation = SkyCompassBakedModel.getAnimatedRotation( skyCompass.getPos(), false ); } @@ -93,7 +104,7 @@ public class SkyCompassTESR extends FastTESR rotation = SkyCompassBakedModel.getAnimatedRotation( null, false ); } - if( skyCompass.getUp() == EnumFacing.DOWN ) + if( skyCompass.getForward() == EnumFacing.DOWN ) { rotation = flipidiy( rotation ); }