Adding Explosion Logger (#299)
* Added Explosion Logger * Added Explosion Logger's Hook On Explosion.java * Update #2 * Add files via upload
This commit is contained in:
1 parent
7dc1fa5f41
commit
7bbae714ea
4 files changed
+203
-2
No files matched your search
@@ -7,8 +7,10 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import carpet.logging.logHelpers.ExplosionLogHelper;
|
||||
import carpet.mixins.ExplosionAccessor;
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.mixins.ExplosionMixin;
|
||||
import carpet.utils.Messenger;
|
||||
import com.google.common.collect.Lists;
|
||||
import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;
|
||||
@@ -51,6 +53,7 @@ public class OptimizedExplosion
|
||||
private static List<Entity> entitylist;
|
||||
private static Vec3d vec3dmem;
|
||||
private static long tickmem;
|
||||
private static Vec3d vec3dZero = new Vec3d(0, 0, 0);
|
||||
// For disabling the explosion particles and sound
|
||||
public static int explosionSound = 0;
|
||||
|
||||
@@ -66,7 +69,7 @@ public class OptimizedExplosion
|
||||
private static ArrayList<Float> chances = new ArrayList<>();
|
||||
private static BlockPos blastChanceLocation;
|
||||
|
||||
public static void doExplosionA(Explosion e) {
|
||||
public static void doExplosionA(Explosion e, ExplosionLogHelper eLogger) {
|
||||
ExplosionAccessor eAccess = (ExplosionAccessor) e;
|
||||
|
||||
blastCalc(e);
|
||||
@@ -120,6 +123,9 @@ public class OptimizedExplosion
|
||||
entity.getX() == eAccess.getEntity().getX() &&
|
||||
entity.getY() == eAccess.getEntity().getY() &&
|
||||
entity.getZ() == eAccess.getEntity().getZ()) {
|
||||
if (eLogger != null) {
|
||||
eLogger.onEntityImpacted(entity, new Vec3d(0,-0.9923437498509884d, 0));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -158,6 +164,10 @@ public class OptimizedExplosion
|
||||
d11 = ProtectionEnchantment.transformExplosionKnockback((LivingEntity) entity, d10);
|
||||
}
|
||||
|
||||
if (eLogger != null) {
|
||||
eLogger.onEntityImpacted(entity, new Vec3d(d5 * d11, d7 * d11, d9 * d11));
|
||||
}
|
||||
|
||||
entity.setVelocity(entity.getVelocity().add(d5 * d11, d7 * d11, d9 * d11));
|
||||
|
||||
if (entity instanceof PlayerEntity) {
|
||||
|
||||
@@ -30,6 +30,7 @@ public class LoggerRegistry
|
||||
public static boolean __packets;
|
||||
public static boolean __weather;
|
||||
public static boolean __pathfinding;
|
||||
public static boolean __explosions;
|
||||
|
||||
public static void initLoggers()
|
||||
{
|
||||
@@ -52,6 +53,7 @@ public class LoggerRegistry
|
||||
registerLogger("packets", HUDLogger.stardardHUDLogger("packets", null, null));
|
||||
registerLogger("counter",HUDLogger.stardardHUDLogger("counter","white", Arrays.stream(DyeColor.values()).map(Object::toString).toArray(String[]::new)));
|
||||
registerLogger("mobcaps", HUDLogger.stardardHUDLogger("mobcaps", "dynamic",new String[]{"dynamic", "overworld", "nether","end"}));
|
||||
registerLogger("explosions", HUDLogger.stardardLogger("explosions", "brief",new String[]{"brief", "full"}));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
package carpet.logging.logHelpers;
|
||||
|
||||
import carpet.logging.LoggerRegistry;
|
||||
import carpet.utils.Messenger;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.text.BaseText;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.explosion.Explosion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ExplosionLogHelper
|
||||
{
|
||||
private final boolean createFire;
|
||||
private final Explosion.DestructionType blockDestructionType;
|
||||
public final double x;
|
||||
public final double y;
|
||||
public final double z;
|
||||
public final Entity entity;
|
||||
private final float power;
|
||||
private boolean affectBlocks = false;
|
||||
private List<EntityChangedStatusWithCount> entityChangedStatusWithCount = Lists.newArrayList();
|
||||
|
||||
private static long lastGametime = 0;
|
||||
private static int explosionCountInCurretGT = 0;
|
||||
|
||||
public ExplosionLogHelper(Entity entity, double x, double y, double z, float power, boolean createFire, Explosion.DestructionType blockDestructionType) {
|
||||
this.entity = entity;
|
||||
this.power = power;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.createFire = createFire;
|
||||
this.blockDestructionType = blockDestructionType;
|
||||
}
|
||||
|
||||
public void setAffectBlocks(boolean b)
|
||||
{
|
||||
affectBlocks = b;
|
||||
}
|
||||
|
||||
public void onExplosionDone(long gametime)
|
||||
{
|
||||
BaseText timeDisplay;
|
||||
if (!(lastGametime == gametime)){
|
||||
explosionCountInCurretGT = 0;
|
||||
lastGametime = gametime;
|
||||
timeDisplay = Messenger.c("wb " + ">>>>>> CURRENT GAME TIME : ", "d " + gametime, "wb >>>>>>\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
timeDisplay = Messenger.s("");
|
||||
}
|
||||
explosionCountInCurretGT++;
|
||||
LoggerRegistry.getLogger("explosions").log( (option) -> {
|
||||
switch (option)
|
||||
{
|
||||
case "brief":
|
||||
return new BaseText[]{Messenger.c(
|
||||
timeDisplay, "gb EXPLOSION", "d #" + explosionCountInCurretGT,"gb -> ",
|
||||
"w P: ", "d ",Messenger.dblt("l",x ,y ,z),
|
||||
"w affectBlocks: ", "m " + this.affectBlocks
|
||||
)};
|
||||
case "full":
|
||||
return new BaseText[]{Messenger.c(
|
||||
timeDisplay, "gb EXPLOSION", "d #" + explosionCountInCurretGT,"gb -> ",
|
||||
"w P: ", "d ",Messenger.dblt("l",x ,y ,z),
|
||||
"w createFire: ", "m " + this.createFire,
|
||||
"w power: ", "c " + this.power,
|
||||
"w destructionType: ", "c " + this.blockDestructionType.name(),
|
||||
"w affectBlocks: ", "m " + this.affectBlocks,
|
||||
"b \n", ListToText()
|
||||
)};
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public void onEntityImpacted(Entity entity, Vec3d deltaVelocity)
|
||||
{
|
||||
for (EntityChangedStatusWithCount e : entityChangedStatusWithCount)
|
||||
{
|
||||
if (e.checkIfEquals(entity, deltaVelocity))
|
||||
{
|
||||
e.count++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
entityChangedStatusWithCount.add(new EntityChangedStatusWithCount(entity.getPos(), entity.getType(), deltaVelocity));
|
||||
}
|
||||
|
||||
public BaseText ListToText()
|
||||
{
|
||||
BaseText s = Messenger.s("Entities Impacted:\n");
|
||||
for (EntityChangedStatusWithCount entityChanges : entityChangedStatusWithCount)
|
||||
{
|
||||
s.append(entityChanges.asText());
|
||||
s.append("\n");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
public static class EntityChangedStatusWithCount
|
||||
{
|
||||
public final Vec3d entityPos;
|
||||
public final EntityType entityType;
|
||||
public final Vec3d deltaSpeed;
|
||||
public int count;
|
||||
public EntityChangedStatusWithCount(Vec3d entityPos, EntityType entityType, Vec3d deltaSpeed)
|
||||
{
|
||||
this.entityPos = entityPos;
|
||||
this.entityType = entityType;
|
||||
this.deltaSpeed = deltaSpeed;
|
||||
this.count = 1;
|
||||
}
|
||||
|
||||
public boolean equals(EntityChangedStatusWithCount e)
|
||||
{
|
||||
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 }"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,13 @@ package carpet.mixins;
|
||||
|
||||
import carpet.helpers.OptimizedExplosion;
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.logging.LoggerRegistry;
|
||||
import carpet.logging.logHelpers.ExplosionLogHelper;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.explosion.Explosion;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
@@ -24,13 +28,17 @@ public abstract class ExplosionMixin
|
||||
@Final
|
||||
private List<BlockPos> affectedBlocks;
|
||||
|
||||
@Shadow @Final private World world;
|
||||
|
||||
private ExplosionLogHelper eLogger;
|
||||
|
||||
@Inject(method = "collectBlocksAndDamageEntities", at = @At("HEAD"),
|
||||
cancellable = true)
|
||||
private void onExplosionA(CallbackInfo ci)
|
||||
{
|
||||
if (CarpetSettings.optimizedTNT)
|
||||
{
|
||||
OptimizedExplosion.doExplosionA((Explosion) (Object) this);
|
||||
OptimizedExplosion.doExplosionA((Explosion) (Object) this, eLogger);
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
@@ -39,6 +47,11 @@ public abstract class ExplosionMixin
|
||||
cancellable = true)
|
||||
private void onExplosionB(boolean spawnParticles, CallbackInfo ci)
|
||||
{
|
||||
if (eLogger != null)
|
||||
{
|
||||
eLogger.setAffectBlocks( ! affectedBlocks.isEmpty());
|
||||
eLogger.onExplosionDone(this.world.getTime());
|
||||
}
|
||||
if (CarpetSettings.explosionNoBlockDamage)
|
||||
{
|
||||
affectedBlocks.clear();
|
||||
@@ -58,4 +71,24 @@ public abstract class ExplosionMixin
|
||||
if (CarpetSettings.explosionNoBlockDamage) return Blocks.BEDROCK.getDefaultState();
|
||||
return world.getBlockState(pos);
|
||||
}
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/entity/Entity;DDDFZLnet/minecraft/world/explosion/Explosion$DestructionType;)V",
|
||||
at = @At(value = "RETURN"))
|
||||
private void onExplosionCreated(World world, Entity entity, double x, double y, double z, float power, boolean createFire, Explosion.DestructionType blockDestructionType, CallbackInfo ci)
|
||||
{
|
||||
if (LoggerRegistry.__explosions && ! world.isClient)
|
||||
{
|
||||
eLogger = new ExplosionLogHelper(entity, x, y, z, power, createFire, blockDestructionType);
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "collectBlocksAndDamageEntities",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V"))
|
||||
private void setVelocityAndUpdateLogging(Entity entity, Vec3d velocity)
|
||||
{
|
||||
if (eLogger != null) {
|
||||
eLogger.onEntityImpacted(entity, velocity.subtract(entity.getVelocity()));
|
||||
}
|
||||
entity.setVelocity(velocity);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user