megabroke
This commit is contained in:
1 parent
ec66779474
commit
a28f7be625
20 files changed
+2242
-3
No files matched your search
@@ -0,0 +1,102 @@
|
||||
package carpet.logging.logHelpers;
|
||||
|
||||
import carpet.logging.LoggerRegistry;
|
||||
import carpet.utils.Messenger;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.MobEffects;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class DamageReporter
|
||||
{
|
||||
private static ITextComponent[] verifyAndProduceMessage(String option, EntityPlayer player, Entity from, Entity to, Supplier<ITextComponent> messageFuture)
|
||||
{
|
||||
if ("all".equalsIgnoreCase(option)
|
||||
|| ("players".equalsIgnoreCase(option) && (from instanceof EntityPlayer || to instanceof EntityPlayer))
|
||||
|| ("me".equalsIgnoreCase(option) && ( (from == player) || ( to == player) ) ))
|
||||
{
|
||||
return new ITextComponent[]{messageFuture.get()};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean register_damage_attacker(Entity target, EntityLivingBase source, float amount)
|
||||
{
|
||||
if (!LoggerRegistry.__damage) return true;
|
||||
LoggerRegistry.getLogger("damage").log( (option, player)->
|
||||
verifyAndProduceMessage(option, player, source, target, () ->
|
||||
Messenger.c(source.getDisplayName(),
|
||||
"g attacking ", target.getDisplayName(),"g for ",
|
||||
String.format("r %.2f",amount), "g points of damage")
|
||||
)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void register_damage(EntityLivingBase target, DamageSource source, float amount)
|
||||
{
|
||||
if (!LoggerRegistry.__damage) return;
|
||||
if (source.isFireDamage() && (target.isImmuneToFire() ||
|
||||
target.isPotionActive(MobEffects.FIRE_RESISTANCE)))
|
||||
return;
|
||||
LoggerRegistry.getLogger("damage").log( (option, player)->
|
||||
verifyAndProduceMessage(option, player, source.getTrueSource(), target, () ->
|
||||
Messenger.c(target.getDisplayName(),
|
||||
"g receiving ",
|
||||
String.format("r %.2f", amount),
|
||||
String.format("g points of damage from %s", source.getDamageType()))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static void register_final_damage(EntityLivingBase target, DamageSource source, float amount)
|
||||
{
|
||||
if (!LoggerRegistry.__damage) return;
|
||||
LoggerRegistry.getLogger("damage").log( (option, player)->
|
||||
verifyAndProduceMessage(option, player, source.getTrueSource(), target, () ->
|
||||
Messenger.c("g - total received ",
|
||||
String.format("r %.2f", amount),
|
||||
"g points of damage")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static void modify_damage(EntityLivingBase target, DamageSource source, float previous_amount, float final_amount, String component)
|
||||
{
|
||||
if (!LoggerRegistry.__damage)
|
||||
return;
|
||||
if (previous_amount == final_amount)
|
||||
return;
|
||||
if (source.isFireDamage() && (target.isImmuneToFire() ||
|
||||
target.isPotionActive(MobEffects.FIRE_RESISTANCE)))
|
||||
return;
|
||||
LoggerRegistry.getLogger("damage").log( (option, player)->
|
||||
verifyAndProduceMessage(option, player, source.getTrueSource(), target, () ->
|
||||
{
|
||||
if (final_amount == 0.0f)
|
||||
{
|
||||
return Messenger.c("g - reduced to ","r 0.0","g due to: "+component);
|
||||
}
|
||||
else if (previous_amount > final_amount)
|
||||
{
|
||||
float reduction = previous_amount-final_amount;
|
||||
return Messenger.c("g - reduced to ",
|
||||
String.format("l %.2f",final_amount),
|
||||
String.format("g by %.2f (%.1f%% less) due to: %s",reduction,100.0*reduction/previous_amount, component));
|
||||
}
|
||||
else
|
||||
{
|
||||
float increase = final_amount-previous_amount;
|
||||
return Messenger.c("g - increased to ",
|
||||
String.format("r %.2f",final_amount),
|
||||
String.format("g by %.2f (%.1f%% more) due to: %s",increase,100.0*increase/previous_amount, component));
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package carpet.logging.logHelpers;
|
||||
|
||||
import carpet.logging.LoggerRegistry;
|
||||
import carpet.utils.Messenger;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public class KillLogHelper {
|
||||
|
||||
public static void onSweep(String name, int count)
|
||||
{
|
||||
LoggerRegistry.getLogger("kills").log( () -> new ITextComponent[]{
|
||||
Messenger.c("g "+name+" smacked ","r "+count,"g entities with sweeping")});
|
||||
}
|
||||
|
||||
public static void onNonSweepAttack(String name)
|
||||
{
|
||||
LoggerRegistry.getLogger("kills").log( () -> new ITextComponent[]{
|
||||
Messenger.c("g "+name+" smacked ","r 1","g (no sweeping)")});
|
||||
}
|
||||
|
||||
public static void onDudHit(String name)
|
||||
{
|
||||
LoggerRegistry.getLogger("kills").log( () -> new ITextComponent[]{
|
||||
Messenger.c("g "+name+" dud hot = no one affected")});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package carpet.logging.logHelpers;
|
||||
|
||||
public class PacketCounter
|
||||
{
|
||||
public static long totalOut=0;
|
||||
public static long totalIn=0;
|
||||
public static void reset() {totalIn = 0l; totalOut = 0L; }
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package carpet.logging.logHelpers;
|
||||
|
||||
import carpet.logging.LoggerRegistry;
|
||||
import carpet.utils.Messenger;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public class TNTLogHelper
|
||||
{
|
||||
private double primedX, primedY, primedZ, 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, float angle)
|
||||
{
|
||||
primedX = x;
|
||||
primedY = y;
|
||||
primedZ = z;
|
||||
primedAngle = angle;
|
||||
}
|
||||
/**
|
||||
* Runs when the TNT explodes. Expects the position of the TNT.
|
||||
*/
|
||||
public void onExploded(double x, double y, double z)
|
||||
{
|
||||
LoggerRegistry.getLogger("tnt").log( (option) -> {
|
||||
switch (option)
|
||||
{
|
||||
case "brief":
|
||||
return new ITextComponent[]{Messenger.c(
|
||||
"l P ",Messenger.dblt("l",primedX,primedY,primedZ,primedAngle),
|
||||
"r E ",Messenger.dblt("r",x, y, z))};
|
||||
case "full":
|
||||
return new ITextComponent[]{Messenger.c(
|
||||
"l P ",Messenger.dblf("l",primedX,primedY,primedZ,primedAngle),
|
||||
"r E ",Messenger.dblf("r",x, y, z))};
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package carpet.logging.logHelpers;
|
||||
|
||||
import carpet.logging.Logger;
|
||||
import carpet.logging.LoggerRegistry;
|
||||
import carpet.utils.Messenger;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A generic log helper for logging the trajectory of things like blocks and throwables.
|
||||
*/
|
||||
public class TrajectoryLogHelper
|
||||
{
|
||||
private static final int MAX_TICKS_PER_LINE = 20;
|
||||
|
||||
private boolean doLog;
|
||||
private Logger logger;
|
||||
|
||||
private ArrayList<Vec3d> positions = new ArrayList<>();
|
||||
private ArrayList<Vec3d> motions = new ArrayList<>();
|
||||
|
||||
public TrajectoryLogHelper(String logName)
|
||||
{
|
||||
this.logger = LoggerRegistry.getLogger(logName);
|
||||
this.doLog = this.logger.hasOnlineSubscribers();
|
||||
}
|
||||
|
||||
public void onTick(double x, double y, double z, double motionX, double motionY, double motionZ)
|
||||
{
|
||||
if (!doLog) return;
|
||||
positions.add(new Vec3d(x, y, z));
|
||||
motions.add(new Vec3d(motionX, motionY, motionZ));
|
||||
}
|
||||
|
||||
public void onFinish()
|
||||
{
|
||||
if (!doLog) return;
|
||||
logger.log( (option) -> {
|
||||
List<ITextComponent> comp = new ArrayList<>();
|
||||
switch (option)
|
||||
{
|
||||
case "brief":
|
||||
comp.add(Messenger.s(""));
|
||||
List<String> line = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < positions.size(); i++)
|
||||
{
|
||||
Vec3d pos = positions.get(i);
|
||||
Vec3d mot = motions.get(i);
|
||||
line.add("w x");
|
||||
line.add(String.format("^w Tick: %d\nx: %f\ny: %f\nz: %f\n------------\nmx: %f\nmy: %f\nmz: %f",
|
||||
i, pos.x, pos.y, pos.z, mot.x, mot.y, mot.z));
|
||||
if ((((i+1) % MAX_TICKS_PER_LINE)==0) || i == positions.size()-1)
|
||||
{
|
||||
comp.add(Messenger.c(line.toArray(new Object[0])));
|
||||
line.clear();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "full":
|
||||
comp.add(Messenger.c("w ---------"));
|
||||
for (int i = 0; i < positions.size(); i++)
|
||||
{
|
||||
Vec3d pos = positions.get(i);
|
||||
Vec3d mot = motions.get(i);
|
||||
comp.add(Messenger.c(
|
||||
String.format("w tick: %3d pos",i),Messenger.dblt("w",pos.x, pos.y, pos.z),
|
||||
"w mot",Messenger.dblt("w",mot.x, mot.y, mot.z)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return comp.toArray(new ITextComponent[0]);
|
||||
});
|
||||
doLog = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user