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 dfd20f03b6 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -67,19 +67,8 @@ public class Recorder implements Listener {
*/ */
private final Set<Region> autoTraceRegions = new HashSet<>(); 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(){ public Recorder(){
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> { BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
noTntRecordedCounter.replaceAll((region, counter) -> counter + 1);
record(); record();
checkForAutoTraceFinish(); checkForAutoTraceFinish();
}, 0, 1); }, 0, 1);
@ -100,10 +89,10 @@ public class Recorder implements Listener {
* *
*/ */
public void checkForAutoTraceFinish(){ public void checkForAutoTraceFinish(){
for(Region region: autoTraceRegions) for(Region region: autoTraceRegions) {
if(autoTraceRegions.contains(region) && noTntRecordedCounter.get(region) != null && noTntRecordedCounter.get(region) > AUTO_TRACE_STOP_TRESHHOLD){ if (autoTraceRegions.contains(region) && trackedTNT.getOrDefault(region, Collections.emptyList()).size() == 0) {
stopRecording(region); stopRecording(region);
autoTraceRegions.remove(region); }
} }
} }
@ -113,7 +102,6 @@ public class Recorder implements Listener {
*/ */
public int startRecording(Region region){ public int startRecording(Region region){
if(activeTraces.containsKey(region)) return -1; if(activeTraces.containsKey(region)) return -1;
if(autoTraceRegions.contains(region)) noTntRecordedCounter.put(region, 0);
Trace trace = new Trace(region); Trace trace = new Trace(region);
activeTraces.put(region, trace); activeTraces.put(region, trace);
return manager.add(trace); return manager.add(trace);
@ -141,8 +129,6 @@ public class Recorder implements Listener {
private void record(){ private void record(){
for(Region region : activeTraces.keySet()){ for(Region region : activeTraces.keySet()){
Trace trace = activeTraces.get(region); 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())){ for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())){
record(tnt, trace); record(tnt, trace);