From 5bb1b8d8a8ac4b2e064f65cca2cac218e6ffad42 Mon Sep 17 00:00:00 2001 From: sabotack Date: Tue, 16 May 2023 10:41:38 +0200 Subject: [PATCH] fix: invalid tick crash when onStateReplaced is called repeatedly --- src/main/interpreter/Visitor.java | 4 ++-- src/main/java/minescript/block/custom/TurtleBlock.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/interpreter/Visitor.java b/src/main/interpreter/Visitor.java index f321b9c..81a6d0e 100644 --- a/src/main/interpreter/Visitor.java +++ b/src/main/interpreter/Visitor.java @@ -43,7 +43,7 @@ public Visitor(MinecraftServer server, ServerWorld world, BlockPos pos, SymbolTa this.symbolTable = symbolTable; this.placingBlock = Blocks.AIR; this.shouldBreak = true; - this.turtleDelay = 500; + this.turtleDelay = 200; this.server = server; this.world = world; this.pos = pos; @@ -472,7 +472,7 @@ public MSType visitFuncCall(MineScriptParser.FuncCallContext ctx) { throw new RuntimeException("Cannot set speed to " + n.getValue() + ", must be between 1 and 10"); } - this.turtleDelay = 550 - n.getValue() * 50; + this.turtleDelay = 200 - n.getValue() * 20; } case "GetXPosition" -> { if (actualParams.size() != 0) { diff --git a/src/main/java/minescript/block/custom/TurtleBlock.java b/src/main/java/minescript/block/custom/TurtleBlock.java index 958e7b7..2794356 100644 --- a/src/main/java/minescript/block/custom/TurtleBlock.java +++ b/src/main/java/minescript/block/custom/TurtleBlock.java @@ -65,7 +65,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, @Override public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { - if (!state.isOf(newState.getBlock()) && !moved) { + if (!moved && !state.isOf(newState.getBlock())) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof TurtleBlockEntity entity) { @@ -74,8 +74,8 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt ClientPlayNetworking.send(MineScriptPackets.STOP_INTERPRETER_ID, buf); } - super.onStateReplaced(state, world, pos, newState, moved); } + super.onStateReplaced(state, world, pos, newState, moved); } @Nullable