From 8ef7bafa224e1a43c111fe01e7721a2cfc2d4665 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Jun 2023 17:58:52 +0200 Subject: [PATCH] Fix MicroMotion detector in Trace Signed-off-by: yoyosource --- .../features/tracer/show/Record.java | 26 ++++++++++++++----- .../tracer/show/ShowModeParameterType.java | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java index 08bc6561..82844113 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java @@ -48,7 +48,7 @@ public class Record { } public TNTRecord spawn(long offset) { - TNTRecord record = new TNTRecord(offset, region); + TNTRecord record = new TNTRecord(this, offset, region); tnt.add(record); return record; } @@ -57,11 +57,26 @@ public class Record { tnt.clear(); } + private void checkMicroMotion() { + for (TNTRecord tntRecord : tnt) { + List positions = tntRecord.positions; + if (positions.isEmpty()) continue; + TNTPosition position = positions.get(positions.size() - 1); + + Vector velocity = position.getVelocity(); + if (velocity.getY() == 0 && (velocity.getX() != 0 || velocity.getZ() != 0) && (Math.abs(velocity.getX()) < 0.001 || Math.abs(velocity.getZ()) < 0.001)) { + tntRecord.hasMicroMotion = true; + } + } + } + public static class TNTRecord { @Getter private final UUID id = UUID.randomUUID(); + private Record record; + @Getter private final long offset; @@ -78,7 +93,8 @@ public class Record { @Getter private boolean hasMicroMotion = false; - public TNTRecord(long offset, Region region) { + public TNTRecord(Record record, long offset, Region region) { + this.record = record; this.offset = offset; this.region = region; } @@ -93,11 +109,7 @@ public class Record { public void explode(TNTPrimed tntPrimed) { add(tntPrimed, false, true); - Vector velocity = tntPrimed.getVelocity(); - if (velocity.getY() != 0) return; - if (velocity.getX() > 0.001 || velocity.getZ() > 0.001) return; - if (velocity.getX() == 0 && velocity.getZ() == 0) return; - hasMicroMotion = true; + record.checkMicroMotion(); } private void add(TNTPrimed tntPrimed, boolean source, boolean exploded) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java index 897fcff6..a4f83958 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java @@ -42,7 +42,7 @@ public enum ShowModeParameterType { COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "TICKS", "TICKS_SINCE_START"), BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"), TICKS_SINCE_START(ShowModeParameter::enableTicksSinceStart, Arrays.asList("-tickssincestart", "-tss"), "TICKS", "COUNT"), - MICROMOTION(ShowModeParameter::enableMicroMotion, Arrays.asList("-micromotion", "-micro", "-m"), "COUNT"), + MICROMOTION(ShowModeParameter::enableMicroMotion, Arrays.asList("-micromotion", "-micro", "-m")), ; @Getter