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:
X-Green authored and GitHub committed 2020-06-06 16:56:43 -03:00
1 parent 7dc1fa5f41
commit 7bbae714ea
4 files changed
+203 -2

No files matched your search

@@ -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);
}
}