Skip to content

Commit 8238ce8

Browse files
committed
add "total" explosion logger and increase subversion number
1 parent 9034e98 commit 8238ce8

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Mod Properties
1010
mod_id = intricarpet
1111
mod_name = IntriCarpet
12-
mod_version = 2.0.2
12+
mod_version = 2.0.3
1313
maven_group = me.lntricate
1414
archives_base_name = intricarpet
1515

src/main/java/me/lntricate/intricarpet/helpers/ExplosionHelper.java

+7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ public class ExplosionHelper
99
private static int countInTick = 0;
1010
private static long tick = 0;
1111
private static long time = 0;
12+
private static long firstTime = 0;
1213
private static boolean affectBlocks;
1314

1415
public static Vec3 getPos(){return pos;}
1516
public static int getCountInPos(){return countInPos;}
1617
public static int getCountInTick(){return countInTick;}
1718
public static long getTick(){return tick;}
1819
public static long getTime(){return time;}
20+
public static long getFirstTime(){return firstTime;}
1921
public static boolean getAffectBlocks(){return affectBlocks;}
2022

2123
public static boolean isNew(Vec3 pos_, long tick_)
@@ -38,6 +40,11 @@ public static void registerNewPos(Vec3 pos_, long tick_, long time_, boolean aff
3840
affectBlocks = affectBlocks_;
3941
}
4042

43+
public static void registerFirstTime(long time_)
44+
{
45+
firstTime = time_;
46+
}
47+
4148
public static void clear()
4249
{
4350
pos = null;

src/main/java/me/lntricate/intricarpet/logging/LoggerRegistry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class LoggerRegistry
88

99
public static void registerLoggers()
1010
{
11-
carpet.logging.LoggerRegistry.registerLogger("explosions", standardLogger("explosions", "brief", new String[]{"compact", "brief", "full"}, true));
11+
carpet.logging.LoggerRegistry.registerLogger("explosions", standardLogger("explosions", "brief", new String[]{"compact", "brief", "full", "total"}, true));
1212
}
1313

1414
static Logger standardLogger(String logName, String def, String [] options, boolean strictOptions)

src/main/java/me/lntricate/intricarpet/logging/logHelpers/ExplosionLogHelper.java

+30-10
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@
1212

1313
public class ExplosionLogHelper
1414
{
15-
private static BaseComponent log;
15+
private static BaseComponent compactLog;
16+
private static BaseComponent totalLog;
1617

1718
public static void onExplosion(Vec3 pos, long tick, boolean affectBlocks)
1819
{
20+
if(ExplosionHelper.getCountInTick()==0)
21+
ExplosionHelper.registerFirstTime(System.currentTimeMillis());
22+
1923
if(ExplosionHelper.isEmpty() || ExplosionHelper.isNew(pos, tick))
2024
{
21-
long time = System.currentTimeMillis();
22-
logCompact(time, false);
23-
ExplosionHelper.registerNewPos(pos, tick, time, affectBlocks);
25+
long newPosTime = System.currentTimeMillis();
26+
logCompact(newPosTime, false);
27+
ExplosionHelper.registerNewPos(pos, tick, newPosTime, affectBlocks);
2428
}
2529
else
2630
{
27-
log = null;
31+
compactLog = null;
2832
ExplosionHelper.incrementCounts(tick);
2933
}
3034
}
@@ -33,8 +37,13 @@ public static List<BaseComponent> onLog(List<BaseComponent> messages, String opt
3337
{
3438
if(option.equals("compact"))
3539
{
36-
if(log != null)
37-
messages.add(log);
40+
if(compactLog != null)
41+
messages.add(compactLog);
42+
}
43+
if(option.equals("total"))
44+
{
45+
if(totalLog != null)
46+
messages.add(totalLog);
3847
}
3948
return messages;
4049
}
@@ -45,7 +54,7 @@ private static void logCompact(long time, boolean endOfTick)
4554
return;
4655

4756
Vec3 pos = ExplosionHelper.getPos();
48-
log = Messenger.c(
57+
compactLog = Messenger.c(
4958
"d " + ExplosionHelper.getCountInPos() + "x ",
5059
Messenger.dblt("l", pos.x, pos.y, pos.z),
5160
"p [Tp]", String.format(Locale.ENGLISH, "!/tp %.3f %.3f %.3f", pos.x, pos.y, pos.z),
@@ -55,16 +64,27 @@ private static void logCompact(long time, boolean endOfTick)
5564
);
5665
}
5766

67+
private static void logTotal(long lastTime)
68+
{
69+
if(ExplosionHelper.getCountInTick() == 0)
70+
return;
71+
72+
totalLog = Messenger.c("d " + ExplosionHelper.getCountInTick(), "g total", "g (", "d " + (lastTime - ExplosionHelper.getFirstTime()), "g ms)");
73+
}
74+
5875
public static void afterEntities()
5976
{
6077
if(LoggerRegistry.__explosions)
6178
{
62-
logCompact(System.currentTimeMillis(), true);
79+
long time = System.currentTimeMillis();
80+
logCompact(time, true);
81+
logTotal(time);
6382
LoggerRegistry.getLogger("explosions").log((option) ->
6483
{
6584
return onLog(new ArrayList<BaseComponent>(), option).toArray(new BaseComponent[0]);
6685
});
67-
log = null;
86+
compactLog = null;
87+
totalLog = null;
6888
}
6989
ExplosionHelper.clear();
7090
}

0 commit comments

Comments
 (0)