From 5c1da81b9f59bea46cddd9ddaf19928b46478900 Mon Sep 17 00:00:00 2001 From: gnembon <41132274+gnembon@users.noreply.github.com> Date: Wed, 8 Nov 2023 21:41:49 +0100 Subject: [PATCH] 23w45a fixes and unmaintainable optimized TNT rule pseudofix. --- gradle.properties | 4 ++-- .../java/carpet/helpers/OptimizedExplosion.java | 11 +++++++---- .../java/carpet/mixins/ExplosionAccessor.java | 5 ++++- .../mixins/Explosion_optimizedTntMixin.java | 15 +++++++++++---- .../mixins/Explosion_scarpetEventMixin.java | 6 ++++-- .../mixins/Explosion_xpFromBlocksMixin.java | 6 +++--- .../carpet/mixins/ServerLevel_scarpetMixin.java | 4 +++- src/main/java/carpet/script/api/WorldAccess.java | 7 +++++-- .../java/carpet/script/utils/AppStoreManager.java | 15 ++++++++++++++- 9 files changed, 53 insertions(+), 20 deletions(-) diff --git a/gradle.properties b/gradle.properties index 574659ab..246981ef 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check https://fabricmc.net/develop/ - minecraft_version=23w44a + minecraft_version=23w45a loader_version=0.14.24 jsr305_version=3.0.2 - fabric_version=0.90.6+1.20.3 + fabric_version=0.90.8+1.20.3 # Mod Properties mod_version = 1.4.124 diff --git a/src/main/java/carpet/helpers/OptimizedExplosion.java b/src/main/java/carpet/helpers/OptimizedExplosion.java index aec3620c..589e3a22 100644 --- a/src/main/java/carpet/helpers/OptimizedExplosion.java +++ b/src/main/java/carpet/helpers/OptimizedExplosion.java @@ -76,7 +76,7 @@ public class OptimizedExplosion boolean eventNeeded = EXPLOSION_OUTCOME.isNeeded() && !eAccess.getLevel().isClientSide(); blastCalc(e); - if (!CarpetSettings.explosionNoBlockDamage) { + if (!CarpetSettings.explosionNoBlockDamage && eAccess.getDamageSource() != null) { rayCalcDone = false; firstRay = true; getAffectedPositionsOnPlaneY(e, 0, 0, 15, 0, 15); // bottom @@ -132,7 +132,7 @@ public class OptimizedExplosion continue; } - if (!entity.ignoreExplosion()) { + if (!entity.ignoreExplosion(e)) { double d12 = Math.sqrt(entity.distanceToSqr(eAccess.getX(), eAccess.getY(), eAccess.getZ())) / (double) f3; if (d12 <= 1.0D) { @@ -165,8 +165,11 @@ public class OptimizedExplosion } double d10 = (1.0D - d12) * density; - entity.hurt(e.getDamageSource(), - (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D))); + if (eAccess.getDamageSource() != null) + { + entity.hurt(eAccess.getDamageSource(), + (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D))); + } double d11 = d10; if (entity instanceof LivingEntity) { diff --git a/src/main/java/carpet/mixins/ExplosionAccessor.java b/src/main/java/carpet/mixins/ExplosionAccessor.java index d4ef66ec..5b0875ba 100644 --- a/src/main/java/carpet/mixins/ExplosionAccessor.java +++ b/src/main/java/carpet/mixins/ExplosionAccessor.java @@ -1,10 +1,10 @@ package carpet.mixins; import net.minecraft.util.RandomSource; +import net.minecraft.world.damagesource.DamageSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -import java.util.Random; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; @@ -39,4 +39,7 @@ public interface ExplosionAccessor { @Accessor Entity getSource(); + @Accessor + DamageSource getDamageSource(); + } diff --git a/src/main/java/carpet/mixins/Explosion_optimizedTntMixin.java b/src/main/java/carpet/mixins/Explosion_optimizedTntMixin.java index 52e0dc34..eb9b3911 100644 --- a/src/main/java/carpet/mixins/Explosion_optimizedTntMixin.java +++ b/src/main/java/carpet/mixins/Explosion_optimizedTntMixin.java @@ -5,6 +5,11 @@ import carpet.CarpetSettings; import carpet.logging.LoggerRegistry; import carpet.logging.logHelpers.ExplosionLogHelper; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.monster.breeze.Breeze; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -32,13 +37,15 @@ public abstract class Explosion_optimizedTntMixin @Shadow @Final private Level level; + @Shadow @Nullable public abstract LivingEntity getIndirectSourceEntity(); + private ExplosionLogHelper eLogger; @Inject(method = "explode", at = @At("HEAD"), cancellable = true) private void onExplosionA(CallbackInfo ci) { - if (CarpetSettings.optimizedTNT) + if (CarpetSettings.optimizedTNT && !level.isClientSide && !(getIndirectSourceEntity() instanceof Breeze)) { OptimizedExplosion.doExplosionA((Explosion) (Object) this, eLogger); ci.cancel(); @@ -58,7 +65,7 @@ public abstract class Explosion_optimizedTntMixin { toBlow.clear(); } - if (CarpetSettings.optimizedTNT) + if (CarpetSettings.optimizedTNT && !level.isClientSide && !(getIndirectSourceEntity() instanceof Breeze)) { OptimizedExplosion.doExplosionB((Explosion) (Object) this, spawnParticles); ci.cancel(); @@ -74,9 +81,9 @@ public abstract class Explosion_optimizedTntMixin return world.getBlockState(pos); } - @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;)V", + @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/sounds/SoundEvent;)V", at = @At(value = "RETURN")) - private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, CallbackInfo ci) + private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, ParticleOptions particleOptions, ParticleOptions particleOptions2, SoundEvent soundEvent, CallbackInfo ci) { if (LoggerRegistry.__explosions && ! world.isClientSide) { diff --git a/src/main/java/carpet/mixins/Explosion_scarpetEventMixin.java b/src/main/java/carpet/mixins/Explosion_scarpetEventMixin.java index 2e8e72c3..97c0f8df 100644 --- a/src/main/java/carpet/mixins/Explosion_scarpetEventMixin.java +++ b/src/main/java/carpet/mixins/Explosion_scarpetEventMixin.java @@ -1,6 +1,8 @@ package carpet.mixins; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.sounds.SoundEvent; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -43,9 +45,9 @@ public abstract class Explosion_scarpetEventMixin private List affectedEntities; - @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;)V", + @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/sounds/SoundEvent;)V", at = @At(value = "RETURN")) - private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, CallbackInfo ci) + private void onExplosionCreated(Level world, Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionBehavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType, ParticleOptions particleOptions, ParticleOptions particleOptions2, SoundEvent soundEvent, CallbackInfo ci) { if (EXPLOSION_OUTCOME.isNeeded() && !world.isClientSide()) { diff --git a/src/main/java/carpet/mixins/Explosion_xpFromBlocksMixin.java b/src/main/java/carpet/mixins/Explosion_xpFromBlocksMixin.java index 1667c695..866e982c 100644 --- a/src/main/java/carpet/mixins/Explosion_xpFromBlocksMixin.java +++ b/src/main/java/carpet/mixins/Explosion_xpFromBlocksMixin.java @@ -4,16 +4,16 @@ import carpet.CarpetSettings; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(Explosion.class) +@Mixin(BlockBehaviour.class) public class Explosion_xpFromBlocksMixin { - @Redirect(method = "finalizeExplosion", at = @At( + @Redirect(method = "onExplosionHit", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;spawnAfterBreak(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;Z)V" )) diff --git a/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java b/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java index 4fb5295d..3bef4f5a 100644 --- a/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java +++ b/src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java @@ -4,8 +4,10 @@ import carpet.fakes.ServerWorldInterface; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; import net.minecraft.core.RegistryAccess; +import net.minecraft.core.particles.ParticleOptions; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvent; import net.minecraft.util.profiling.ProfilerFiller; import net.minecraft.world.DifficultyInstance; import net.minecraft.world.damagesource.DamageSource; @@ -64,7 +66,7 @@ public abstract class ServerLevel_scarpetMixin extends Level implements ServerWo } @Inject(method = "explode", at = @At("HEAD")) - private void handleExplosion(/*@Nullable*/ Entity entity, /*@Nullable*/ DamageSource damageSource, /*@Nullable*/ ExplosionDamageCalculator explosionBehavior, double d, double e, double f, float g, boolean bl, Level.ExplosionInteraction explosionInteraction, CallbackInfoReturnable cir) + private void handleExplosion(/*@Nullable*/ Entity entity, /*@Nullable*/ DamageSource damageSource, /*@Nullable*/ ExplosionDamageCalculator explosionBehavior, double d, double e, double f, float g, boolean bl, ExplosionInteraction explosionInteraction, ParticleOptions particleOptions, ParticleOptions particleOptions2, SoundEvent soundEvent, CallbackInfoReturnable cir) { if (EXPLOSION.isNeeded()) { Explosion.BlockInteraction var10000 = switch (explosionInteraction) { diff --git a/src/main/java/carpet/script/api/WorldAccess.java b/src/main/java/carpet/script/api/WorldAccess.java index 6ac05861..2bf8699f 100644 --- a/src/main/java/carpet/script/api/WorldAccess.java +++ b/src/main/java/carpet/script/api/WorldAccess.java @@ -38,6 +38,7 @@ import net.minecraft.core.Holder; import net.minecraft.core.HolderSet; import net.minecraft.core.QuartPos; import net.minecraft.core.Registry; +import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; @@ -46,6 +47,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.Ticket; import net.minecraft.server.level.TicketType; +import net.minecraft.sounds.SoundEvents; import net.minecraft.tags.TagKey; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.PalettedContainer; @@ -1066,7 +1068,7 @@ public class WorldAccess float thePowah = powah; // copy of ServerWorld.createExplosion #TRACK# - Explosion explosion = new Explosion(cc.level(), source, null, null, pos.x, pos.y, pos.z, powah, createFire, mode) + Explosion explosion = new Explosion(cc.level(), source, null, null, pos.x, pos.y, pos.z, powah, createFire, mode, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE) { @Override @Nullable @@ -1082,10 +1084,11 @@ public class WorldAccess { explosion.clearToBlow(); } + Explosion.BlockInteraction finalMode = mode; cc.level().players().forEach(spe -> { if (spe.distanceToSqr(pos) < 4096.0D) { - spe.connection.send(new ClientboundExplodePacket(pos.x, pos.y, pos.z, thePowah, explosion.getToBlow(), explosion.getHitPlayers().get(spe))); + spe.connection.send(new ClientboundExplodePacket(pos.x, pos.y, pos.z, thePowah, explosion.getToBlow(), explosion.getHitPlayers().get(spe), finalMode, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE)); } }); return Value.TRUE; diff --git a/src/main/java/carpet/script/utils/AppStoreManager.java b/src/main/java/carpet/script/utils/AppStoreManager.java index 505e73bc..963cd549 100644 --- a/src/main/java/carpet/script/utils/AppStoreManager.java +++ b/src/main/java/carpet/script/utils/AppStoreManager.java @@ -12,8 +12,8 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import net.minecraft.commands.CommandRuntimeException; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; import net.minecraft.world.level.storage.LevelResource; import java.io.BufferedWriter; @@ -473,4 +473,17 @@ public class AppStoreManager } CarpetScriptServer.LOG.info("Downloaded app " + target + " from " + contentUrl); } + + public static class CommandRuntimeException extends RuntimeException { + private final Component message; + + public CommandRuntimeException(Component message) { + super(message.getString(), null, false, false); + this.message = message; + } + + public Component getComponent() { + return message; + } + } }