From fccdcb2519cb033d39f0ccef892f681deb894c66 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Sat, 2 Mar 2024 21:19:52 +0100 Subject: [PATCH] Made auto-traces finish --- .../bausystem/features/tracer/Recorder.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Recorder.java index 2a4d541f..a94109ed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Recorder.java @@ -67,8 +67,22 @@ public class Recorder implements Listener { */ private final Set autoTraceRegions = new HashSet<>(); + /** + * Counters for how long no tnt was seen in an active auto trace region + */ + private final Map noTntRecordedCounter = new HashMap<>(); + + /** + * Amount of ticks, after wich an auto-trace is stopped, if no tnt where seen + */ + private final long AUTO_TRACE_STOP_TRESHHOLD = 120; + public Recorder(){ - BauSystem.runTaskTimer(BauSystem.getInstance(), this::record, 0, 1); + BauSystem.runTaskTimer(BauSystem.getInstance(), () -> { + noTntRecordedCounter.replaceAll((region, counter) -> counter + 1); + record(); + checkForAutoTraceFinish(); + }, 0, 1); } /** Toggles auto trace for the given region @@ -82,13 +96,24 @@ public class Recorder implements Listener { autoTraceRegions.add(region); } + /** Makes checks for whether auto traces finished + * + */ + public void checkForAutoTraceFinish(){ + for(Region region: autoTraceRegions) + if(autoTraceRegions.contains(region) && noTntRecordedCounter.get(region) > AUTO_TRACE_STOP_TRESHHOLD){ + stopRecording(region); + autoTraceRegions.remove(region); + } + } + /** Starts a recording at the given region * * @param region region to be recorded - * @ */ public void startRecording(Region region){ if(activeTraces.containsKey(region)) return; + if(autoTraceRegions.contains(region)) noTntRecordedCounter.put(region, 0); Trace trace = new Trace(region); activeTraces.put(region, trace); } @@ -115,6 +140,9 @@ public class Recorder implements Listener { private void record(){ for(Region region : activeTraces.keySet()){ Trace trace = activeTraces.get(region); + if(trackedTNT.getOrDefault(region, Collections.emptyList()).size() > 0) + noTntRecordedCounter.put(region, 0); + for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())){ record(tnt, trace); }