Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "total" explosion logger #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
# Mod Properties
mod_id = intricarpet
mod_name = IntriCarpet
mod_version = 2.0.2
mod_version = 2.0.3
maven_group = me.lntricate
archives_base_name = intricarpet

Original file line number Diff line number Diff line change
@@ -9,13 +9,15 @@ public class ExplosionHelper
private static int countInTick = 0;
private static long tick = 0;
private static long time = 0;
private static long firstTime = 0;
private static boolean affectBlocks;

public static Vec3 getPos(){return pos;}
public static int getCountInPos(){return countInPos;}
public static int getCountInTick(){return countInTick;}
public static long getTick(){return tick;}
public static long getTime(){return time;}
public static long getFirstTime(){return firstTime;}
public static boolean getAffectBlocks(){return affectBlocks;}

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

public static void registerFirstTime(long time_)
{
firstTime = time_;
}

public static void clear()
{
pos = null;
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ public class LoggerRegistry

public static void registerLoggers()
{
carpet.logging.LoggerRegistry.registerLogger("explosions", standardLogger("explosions", "brief", new String[]{"compact", "brief", "full"}, true));
carpet.logging.LoggerRegistry.registerLogger("explosions", standardLogger("explosions", "brief", new String[]{"compact", "brief", "full", "total"}, true));
}

static Logger standardLogger(String logName, String def, String [] options, boolean strictOptions)
Original file line number Diff line number Diff line change
@@ -12,19 +12,23 @@

public class ExplosionLogHelper
{
private static BaseComponent log;
private static BaseComponent compactLog;
private static BaseComponent totalLog;

public static void onExplosion(Vec3 pos, long tick, boolean affectBlocks)
{
if(ExplosionHelper.getCountInTick()==0)
ExplosionHelper.registerFirstTime(System.currentTimeMillis());

if(ExplosionHelper.isEmpty() || ExplosionHelper.isNew(pos, tick))
{
long time = System.currentTimeMillis();
logCompact(time, false);
ExplosionHelper.registerNewPos(pos, tick, time, affectBlocks);
long newPosTime = System.currentTimeMillis();
logCompact(newPosTime, false);
ExplosionHelper.registerNewPos(pos, tick, newPosTime, affectBlocks);
}
else
{
log = null;
compactLog = null;
ExplosionHelper.incrementCounts(tick);
}
}
@@ -33,8 +37,13 @@ public static List<BaseComponent> onLog(List<BaseComponent> messages, String opt
{
if(option.equals("compact"))
{
if(log != null)
messages.add(log);
if(compactLog != null)
messages.add(compactLog);
}
if(option.equals("total"))
{
if(totalLog != null)
messages.add(totalLog);
}
return messages;
}
@@ -45,7 +54,7 @@ private static void logCompact(long time, boolean endOfTick)
return;

Vec3 pos = ExplosionHelper.getPos();
log = Messenger.c(
compactLog = Messenger.c(
"d " + ExplosionHelper.getCountInPos() + "x ",
Messenger.dblt("l", pos.x, pos.y, pos.z),
"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)
);
}

private static void logTotal(long lastTime)
{
if(ExplosionHelper.getCountInTick() == 0)
return;

totalLog = Messenger.c("d " + ExplosionHelper.getCountInTick(), "g total", "g (", "d " + (lastTime - ExplosionHelper.getFirstTime()), "g ms)");
}

public static void afterEntities()
{
if(LoggerRegistry.__explosions)
{
logCompact(System.currentTimeMillis(), true);
long time = System.currentTimeMillis();
logCompact(time, true);
logTotal(time);
LoggerRegistry.getLogger("explosions").log((option) ->
{
return onLog(new ArrayList<BaseComponent>(), option).toArray(new BaseComponent[0]);
});
log = null;
compactLog = null;
totalLog = null;
}
ExplosionHelper.clear();
}