SteamWar/BauSystem2.0
Archiviert
12
0

Trace Refactor #233

Zusammengeführt
YoyoNow hat 121 Commits von TracerGUI nach master 2024-04-21 16:03:26 +02:00 zusammengeführt
Nur Änderungen aus Commit fccdcb2519 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -67,8 +67,22 @@ public class Recorder implements Listener {
*/
private final Set<Region> autoTraceRegions = new HashSet<>();
/**
* Counters for how long no tnt was seen in an active auto trace region
*/
private final Map<Region, Integer> 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);
}