Files
fabric-carpet/src/main/java/carpet/logging/logHelpers/TNTLogHelper.java
T
Fx Morin 286dbead14 Logger Improvements (#1399)
* Null checks & using getOptions

* Removed useless variable, and made HashMap's final

* This list & Map should not be modified.
Plus small changes

* Small things

* Fix #1398

* Apply suggestions from code review

* Remove Dead call

* Handle options being null

* Remove redundant field explainers

Those were there for when they were intermediary fields, they now have a proper name
2022-06-27 14:04:11 +02:00

52 lines
1.8 KiB
Java

package carpet.logging.logHelpers;
import carpet.logging.LoggerRegistry;
import carpet.utils.Messenger;
import net.minecraft.network.chat.Component;
import net.minecraft.world.phys.Vec3;
public class TNTLogHelper
{
public boolean initialized;
private double primedX, primedY, primedZ;
private static long lastGametime = 0;
private static int tntCount = 0;
private Vec3 primedAngle;
/**
* Runs when the TNT is primed. Expects the position and motion angle of the TNT.
*/
public void onPrimed(double x, double y, double z, Vec3 motion)
{
primedX = x;
primedY = y;
primedZ = z;
primedAngle = motion;
initialized = true;
}
/**
* Runs when the TNT explodes. Expects the position of the TNT.
*/
public void onExploded(double x, double y, double z, long gametime)
{
if (!(lastGametime == gametime)){
tntCount = 0;
lastGametime = gametime;
}
tntCount++;
LoggerRegistry.getLogger("tnt").log( (option) -> switch (option) {
case "brief" -> new Component[]{Messenger.c(
"l P ", Messenger.dblt("l", primedX, primedY, primedZ),
"w ", Messenger.dblt("l", primedAngle.x, primedAngle.y, primedAngle.z),
"r E ", Messenger.dblt("r", x, y, z))};
case "full" -> new Component[]{Messenger.c(
"r #" + tntCount,
"m @" + gametime,
"g : ",
"l P ", Messenger.dblf("l", primedX, primedY, primedZ),
"w ", Messenger.dblf("l", primedAngle.x, primedAngle.y, primedAngle.z),
"r E ", Messenger.dblf("r", x, y, z))};
default -> null;
});
}
}