Merge branch 'master' into 1.16

This commit is contained in:
gnembon committed 2020-06-10 23:25:17 -03:00
commit eb09803e60
1 file changed
+125 -156
@@ -1,156 +1,125 @@
package carpet.logging.logHelpers; package carpet.logging.logHelpers;
import carpet.logging.LoggerRegistry; import carpet.logging.LoggerRegistry;
import carpet.utils.Messenger; import carpet.utils.Messenger;
import com.google.common.collect.Lists; import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.entity.Entity; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.entity.EntityType; import net.minecraft.entity.Entity;
import net.minecraft.text.BaseText; import net.minecraft.entity.EntityType;
import net.minecraft.util.math.Vec3d; import net.minecraft.text.BaseText;
import net.minecraft.util.registry.Registry; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.explosion.Explosion; import net.minecraft.util.registry.Registry;
import net.minecraft.world.explosion.Explosion;
import java.util.List;
import java.util.ArrayList;
public class ExplosionLogHelper import java.util.List;
{
private final boolean createFire; import static carpet.utils.Messenger.c;
private final Explosion.DestructionType blockDestructionType;
public final double x; public class ExplosionLogHelper
public final double y; {
public final double z; private final boolean createFire;
public final Entity entity; private final Explosion.DestructionType blockDestructionType;
private final float power; public final Vec3d pos;
private boolean affectBlocks = false; public final Entity entity;
private List<EntityChangedStatusWithCount> entityChangedStatusWithCount = Lists.newArrayList(); private final float power;
private boolean affectBlocks = false;
private static long lastGametime = 0; private Object2IntMap<EntityChangedStatusWithCount> impactedEntities = new Object2IntOpenHashMap<>();
private static int explosionCountInCurretGT = 0;
private static long lastGametime = 0;
public ExplosionLogHelper(Entity entity, double x, double y, double z, float power, boolean createFire, Explosion.DestructionType blockDestructionType) { private static int explosionCountInCurretGT = 0;
this.entity = entity;
this.power = power; public ExplosionLogHelper(Entity entity, double x, double y, double z, float power, boolean createFire, Explosion.DestructionType blockDestructionType) {
this.x = x; this.entity = entity;
this.y = y; this.power = power;
this.z = z; this.pos = new Vec3d(x,y,z);
this.createFire = createFire; this.createFire = createFire;
this.blockDestructionType = blockDestructionType; this.blockDestructionType = blockDestructionType;
} }
public void setAffectBlocks(boolean b) public void setAffectBlocks(boolean b)
{ {
affectBlocks = b; affectBlocks = b;
} }
public void onExplosionDone(long gametime) public void onExplosionDone(long gametime)
{ {
BaseText timeDisplay; List<BaseText> messages = new ArrayList<>();
if (!(lastGametime == gametime)){ if (!(lastGametime == gametime)){
explosionCountInCurretGT = 0; explosionCountInCurretGT = 0;
lastGametime = gametime; lastGametime = gametime;
timeDisplay = Messenger.c("wb " + ">>>>>> CURRENT GAME TIME : ", "d " + gametime, "wb >>>>>>\n"); messages.add(c("wb tick : ", "d " + gametime));
} }
else explosionCountInCurretGT++;
{ LoggerRegistry.getLogger("explosions").log( (option) -> {
timeDisplay = Messenger.s(""); if ("brief".equals(option))
} {
explosionCountInCurretGT++; messages.add( c("d #" + explosionCountInCurretGT,"gb ->",
LoggerRegistry.getLogger("explosions").log( (option) -> { Messenger.dblt("l", pos.x, pos.y, pos.z), (affectBlocks)?"m (affects blocks)":"m (doesn't affect blocks)" ));
switch (option) }
{ if ("full".equals(option))
case "brief": {
return new BaseText[]{Messenger.c( messages.add( c("d #" + explosionCountInCurretGT,"gb ->", Messenger.dblt("l", pos.x, pos.y, pos.z) ));
timeDisplay, "gb EXPLOSION", "d #" + explosionCountInCurretGT,"gb -> ", messages.add(c("w affects blocks: ", "m " + this.affectBlocks));
"w P: ", "d ",Messenger.dblt("l",x ,y ,z), messages.add(c("w creates fire: ", "m " + this.createFire));
"w affectBlocks: ", "m " + this.affectBlocks messages.add(c("w power: ", "c " + this.power));
)}; messages.add(c( "w destruction: ", "c " + this.blockDestructionType.name()));
case "full": if (impactedEntities.isEmpty())
return new BaseText[]{Messenger.c( {
timeDisplay, "gb EXPLOSION", "d #" + explosionCountInCurretGT,"gb -> ", messages.add(c("w affected entities: ", "m None"));
"w P: ", "d ",Messenger.dblt("l",x ,y ,z), }
"w createFire: ", "m " + this.createFire, else
"w power: ", "c " + this.power, {
"w destructionType: ", "c " + this.blockDestructionType.name(), messages.add(c("w affected entities:"));
"w affectBlocks: ", "m " + this.affectBlocks, impactedEntities.forEach((k, v) ->
"b \n", ListToText() {
)}; messages.add(c((k.pos.equals(pos))?"r - TNT":"w - ",
} Messenger.dblt((k.pos.equals(pos))?"r":"y", k.pos.x, k.pos.y, k.pos.z), "w dV",
return null; Messenger.dblt("d", k.accel.x, k.accel.y, k.accel.z),
}); "w "+Registry.ENTITY_TYPE.getId(k.type).getPath(), (v>1)?"l ("+v+")":""
} ));
});
public void onEntityImpacted(Entity entity, Vec3d deltaVelocity) }
{ }
for (EntityChangedStatusWithCount e : entityChangedStatusWithCount) return messages.toArray(new BaseText[0]);
{ });
if (e.checkIfEquals(entity, deltaVelocity)) }
{
e.count++; public void onEntityImpacted(Entity entity, Vec3d accel)
return; {
} EntityChangedStatusWithCount ent = new EntityChangedStatusWithCount(entity, accel);
} impactedEntities.put(ent, impactedEntities.getOrDefault(ent, 0)+1);
entityChangedStatusWithCount.add(new EntityChangedStatusWithCount(entity.getPos(), entity.getType(), deltaVelocity)); }
}
public BaseText ListToText() public static class EntityChangedStatusWithCount
{ {
BaseText s = Messenger.s("Entities Impacted:\n"); public final Vec3d pos;
for (EntityChangedStatusWithCount entityChanges : entityChangedStatusWithCount) public final EntityType type;
{ public final Vec3d accel;
s.append(entityChanges.asText());
s.append("\n"); public EntityChangedStatusWithCount(Entity e, Vec3d accel)
} {
return s; this.pos = e.getPos();
} this.type = e.getType();
this.accel = accel;
}
public static class EntityChangedStatusWithCount
{ @Override
public final Vec3d entityPos; public boolean equals(Object obj)
public final EntityType entityType; {
public final Vec3d deltaSpeed; if (obj instanceof EntityChangedStatusWithCount)
public int count; {
public EntityChangedStatusWithCount(Vec3d entityPos, EntityType entityType, Vec3d deltaSpeed) EntityChangedStatusWithCount other = (EntityChangedStatusWithCount) obj;
{ return other.pos.equals(pos) && other.accel.equals(accel) && other.type.equals(type);
this.entityPos = entityPos; }
this.entityType = entityType; return super.equals(obj);
this.deltaSpeed = deltaSpeed; }
this.count = 1;
} @Override
public int hashCode()
public boolean equals(EntityChangedStatusWithCount e) {
{ return pos.hashCode()+ type.hashCode()+accel.hashCode();
return ( }
e.entityType == this.entityType && }
e.deltaSpeed.equals(this.deltaSpeed) && }
e.entityPos.equals(this.entityPos)
);
}
public boolean checkIfEquals(Entity e, Vec3d deltaSpeed)
{
return (
e.getType() == this.entityType &&
deltaSpeed.equals(this.deltaSpeed) &&
e.getPos().equals(this.entityPos)
);
}
public String toString()
{
return String.format("{EntityType: %s, EntityPos: %s ,DeltaSpeed: %s}", entityType.getName().asString(), entityPos.toString(), deltaSpeed.toString());
}
public BaseText asText()
{
return Messenger.c(
"m Entity(count="+ this.count +") of",
"l " + Registry.ENTITY_TYPE.getId(entityType), "g {",
"w P: ", "y ", Messenger.dblt("t", entityPos.x, entityPos.y, entityPos.z),
"w dV: ", "gbi " + (deltaSpeed.equals(new Vec3d(0,-0.9923437498509884d, 0)) ? "<TNTs-AT-SAME-SPOT>":""),"y ", Messenger.dblt("d", deltaSpeed.x, deltaSpeed.y, deltaSpeed.z),
"g }"
);
}
}
}