From 5342beacaf0868bcd71b08f8ae4007e5dc4dadb3 Mon Sep 17 00:00:00 2001 From: Colman Davenport Date: Sat, 12 Sep 2020 15:47:27 -0400 Subject: [PATCH] Conditional moving saw operation - Saws are inactive while moving backwards - Vertical moving saws can now damage entities --- .../components/actors/SawMovementBehaviour.java | 12 +++++++++++- .../contraptions/components/saw/SawRenderer.java | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/SawMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/SawMovementBehaviour.java index 7f0e1a778..fea857ff2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/SawMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/SawMovementBehaviour.java @@ -27,7 +27,8 @@ public class SawMovementBehaviour extends BlockBreakingMovementBehaviour { @Override public boolean isActive(MovementContext context) { - return SawBlock.isHorizontal(context.state); + return !VecHelper.isVecPointingTowards(context.relativeMotion, context.state.get(SawBlock.FACING) + .getOpposite()); } @Override @@ -35,6 +36,15 @@ public class SawMovementBehaviour extends BlockBreakingMovementBehaviour { return new Vec3d(context.state.get(SawBlock.FACING).getDirectionVec()).scale(.65f); } + @Override + public void visitNewPosition(MovementContext context, BlockPos pos) { + super.visitNewPosition(context, pos); + if(!SawBlock.isHorizontal(context.state) && context.data.contains("BreakingPos")) { + context.data.remove("BreakingPos"); + context.stall = false; + } + } + @Override public boolean canBreak(World world, BlockPos breakingPos, BlockState state) { return super.canBreak(world, breakingPos, state) && SawTileEntity.isSawable(state); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index e467d3c2e..3d7e5ab7b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -139,10 +139,22 @@ public class SawRenderer extends SafeTileEntityRenderer { SuperByteBuffer superBuffer; Direction facing = state.get(SawBlock.FACING); + boolean horizontal = SawBlock.isHorizontal(state); + boolean backwards = VecHelper.isVecPointingTowards(context.relativeMotion, facing.getOpposite()); + boolean moving = context.getAnimationSpeed() != 0; + boolean shouldAnimate = (context.contraption.stalled && horizontal) + || (!context.contraption.stalled && !backwards && moving); + if(SawBlock.isHorizontal(state)) { - superBuffer = AllBlockPartials.SAW_BLADE_HORIZONTAL_ACTIVE.renderOn(state); + if(shouldAnimate) + superBuffer = AllBlockPartials.SAW_BLADE_HORIZONTAL_ACTIVE.renderOn(state); + else + superBuffer = AllBlockPartials.SAW_BLADE_HORIZONTAL_INACTIVE.renderOn(state); } else { - superBuffer = AllBlockPartials.SAW_BLADE_VERTICAL_INACTIVE.renderOn(state); + if(shouldAnimate) + superBuffer = AllBlockPartials.SAW_BLADE_VERTICAL_ACTIVE.renderOn(state); + else + superBuffer = AllBlockPartials.SAW_BLADE_VERTICAL_INACTIVE.renderOn(state); } for (MatrixStack m : matrixStacks) {