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
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);

View file

@ -139,10 +139,22 @@ public class SawRenderer extends SafeTileEntityRenderer<SawTileEntity> {
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) {