Conditional moving saw operation

- Saws are inactive while moving backwards
- Vertical moving saws can now damage entities
This commit is contained in:
Colman Davenport 2020-09-12 15:47:27 -04:00
parent a28b6bbdc3
commit 5342beacaf
2 changed files with 25 additions and 3 deletions

View file

@ -27,7 +27,8 @@ public class SawMovementBehaviour extends BlockBreakingMovementBehaviour {
@Override @Override
public boolean isActive(MovementContext context) { public boolean isActive(MovementContext context) {
return SawBlock.isHorizontal(context.state); return !VecHelper.isVecPointingTowards(context.relativeMotion, context.state.get(SawBlock.FACING)
.getOpposite());
} }
@Override @Override
@ -35,6 +36,15 @@ public class SawMovementBehaviour extends BlockBreakingMovementBehaviour {
return new Vec3d(context.state.get(SawBlock.FACING).getDirectionVec()).scale(.65f); 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 @Override
public boolean canBreak(World world, BlockPos breakingPos, BlockState state) { public boolean canBreak(World world, BlockPos breakingPos, BlockState state) {
return super.canBreak(world, breakingPos, state) && SawTileEntity.isSawable(state); return super.canBreak(world, breakingPos, state) && SawTileEntity.isSawable(state);

View file

@ -139,9 +139,21 @@ public class SawRenderer extends SafeTileEntityRenderer<SawTileEntity> {
SuperByteBuffer superBuffer; SuperByteBuffer superBuffer;
Direction facing = state.get(SawBlock.FACING); 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)) { if(SawBlock.isHorizontal(state)) {
if(shouldAnimate)
superBuffer = AllBlockPartials.SAW_BLADE_HORIZONTAL_ACTIVE.renderOn(state); superBuffer = AllBlockPartials.SAW_BLADE_HORIZONTAL_ACTIVE.renderOn(state);
else
superBuffer = AllBlockPartials.SAW_BLADE_HORIZONTAL_INACTIVE.renderOn(state);
} else { } else {
if(shouldAnimate)
superBuffer = AllBlockPartials.SAW_BLADE_VERTICAL_ACTIVE.renderOn(state);
else
superBuffer = AllBlockPartials.SAW_BLADE_VERTICAL_INACTIVE.renderOn(state); superBuffer = AllBlockPartials.SAW_BLADE_VERTICAL_INACTIVE.renderOn(state);
} }