9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-22 08:19:26 +00:00

Add consistent explosion radius to api

This commit is contained in:
Samsuik
2024-05-26 18:27:05 +01:00
parent 28fccff6c4
commit 70c53277c5
6 changed files with 52 additions and 23 deletions

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Add redstone implementation API
diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
index 3beb5830d623e72a3f4dec63aedc8b69a6396bf0..1a725c1f349b9b8f86c118e579004d7974f016fd 100644 index 4735e5d8dcea4835061b5cada9d601794efdf390..4d8c83f48d8ef739a00ea1b8a17ac8cdf10ac396 100644
--- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java --- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java +++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
@@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
@@ -16,13 +16,17 @@ index 3beb5830d623e72a3f4dec63aedc8b69a6396bf0..1a725c1f349b9b8f86c118e579004d79
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@@ -20,6 +21,10 @@ public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) { @@ -20,6 +21,14 @@ public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
new NamespacedKey("sakura", "durable-materials"), HashMap::new new NamespacedKey("sakura", "durable-materials"), HashMap::new
); );
+ public static final LocalValueKey<RedstoneImplementation> REDSTONE_IMPLEMENTATION = new LocalValueKey<>( + public static final LocalValueKey<RedstoneImplementation> REDSTONE_IMPLEMENTATION = new LocalValueKey<>(
+ new NamespacedKey("sakura", "redstone-implementation"), () -> RedstoneImplementation.VANILLA + new NamespacedKey("sakura", "redstone-implementation"), () -> RedstoneImplementation.VANILLA
+ ); + );
+
+ public static final LocalValueKey<Boolean> CONSISTENT_EXPLOSION_RADIUS = new LocalValueKey<>(
+ new NamespacedKey("saskua", "consistent-radius"), () -> false
+ );
+ +
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {

View File

@@ -155,10 +155,10 @@ index 0000000000000000000000000000000000000000..a3a09b8d58589883c7c465597bc64502
+} +}
diff --git a/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java diff --git a/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..f0037f98e93fd1f0dea9c224ba402ebcacf9b21f index 0000000000000000000000000000000000000000..dd61d4e8811ffb1e8a842df1db6ac6ce5a8258c6
--- /dev/null --- /dev/null
+++ b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java +++ b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java
@@ -0,0 +1,59 @@ @@ -0,0 +1,68 @@
+package me.samsuik.sakura.local.config; +package me.samsuik.sakura.local.config;
+ +
+import io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation; +import io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation;
@@ -180,6 +180,7 @@ index 0000000000000000000000000000000000000000..f0037f98e93fd1f0dea9c224ba402ebc
+ public Map<Block, DurableMaterial> durableMaterials; + public Map<Block, DurableMaterial> durableMaterials;
+ public PhysicsVersion physicsVersion; + public PhysicsVersion physicsVersion;
+ public RedstoneImplementation redstoneImplementation; + public RedstoneImplementation redstoneImplementation;
+ public boolean consistentRadius;
+ +
+ LocalValueConfig(Expiry expiry) { + LocalValueConfig(Expiry expiry) {
+ this.expiry = expiry; + this.expiry = expiry;
@@ -194,6 +195,9 @@ index 0000000000000000000000000000000000000000..f0037f98e93fd1f0dea9c224ba402ebc
+ +
+ // redstone implementation + // redstone implementation
+ this.redstoneImplementation = level.paperConfig().misc.redstoneImplementation; + this.redstoneImplementation = level.paperConfig().misc.redstoneImplementation;
+
+ // consistent explosion radius
+ this.consistentRadius = level.sakuraConfig().cannons.explosion.consistentRadius;
+ } + }
+ +
+ void load(LocalValueStorage storage) { + void load(LocalValueStorage storage) {
@@ -211,6 +215,11 @@ index 0000000000000000000000000000000000000000..f0037f98e93fd1f0dea9c224ba402ebc
+ if (storage.exists(LocalValueKey.REDSTONE_IMPLEMENTATION)) { + if (storage.exists(LocalValueKey.REDSTONE_IMPLEMENTATION)) {
+ this.redstoneImplementation = RedstoneImplementation.values()[storage.value(LocalValueKey.REDSTONE_IMPLEMENTATION).ordinal()]; + this.redstoneImplementation = RedstoneImplementation.values()[storage.value(LocalValueKey.REDSTONE_IMPLEMENTATION).ordinal()];
+ } + }
+
+ // consistent explosion radius
+ if (storage.exists(LocalValueKey.CONSISTENT_EXPLOSION_RADIUS)) {
+ this.consistentRadius = storage.value(LocalValueKey.CONSISTENT_EXPLOSION_RADIUS);
+ }
+ } + }
+ +
+ Expiry expiry() { + Expiry expiry() {

View File

@@ -5,15 +5,31 @@ Subject: [PATCH] Consistent Explosion Radius
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
index 9f4fbb9475ab011ab6b19e709b6673cd5c9d0895..085ea33ed1ce47d3eaa5dc72d3baea44991f2c06 100644 index 779285b59fec13274bb8de9927407e3145b110ac..e2a560846ed479309b18d8474b3c9f9d1f89bd5c 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java --- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java +++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -584,7 +584,7 @@ public class Explosion { @@ -74,6 +74,7 @@ public class Explosion {
public boolean wasCanceled = false;
public float yield;
// CraftBukkit end
+ private final boolean consistentRadius; // Sakura - consistent explosion radius
public static DamageSource getDefaultDamageSource(Level world, @Nullable Entity source) {
return world.damageSources().explosion(source, Explosion.getIndirectSourceEntityInternal(source));
@@ -111,6 +112,7 @@ public class Explosion {
this.largeExplosionParticles = emitterParticle;
this.explosionSound = soundEvent;
this.yield = this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F; // CraftBukkit
+ this.consistentRadius = world.localConfig().config(BlockPos.containing(x, y, z)).consistentRadius; // Sakura - consistent explosion radius
}
// Sakura start - optimise paper explosions
@@ -584,7 +586,7 @@ public class Explosion {
double d2 = CACHED_RAYS[ray + 2]; double d2 = CACHED_RAYS[ray + 2];
ray += 3; ray += 3;
// Paper end - optimise explosions // Paper end - optimise explosions
- float f = this.radius * (0.7F + this.level.random.nextFloat() * 0.6F); - float f = this.radius * (0.7F + this.level.random.nextFloat() * 0.6F);
+ float f = this.radius * (0.7F + (this.level.sakuraConfig().cannons.explosion.consistentRadius ? 0.7F : this.level.random.nextFloat()) * 0.6F); // Sakura - consistent explosion radius + float f = this.radius * (0.7F + (consistentRadius ? 0.7F : this.level.random.nextFloat()) * 0.6F); // Sakura - consistent explosion radius
double d4 = this.x; double d4 = this.x;
double d5 = this.y; double d5 = this.y;
double d6 = this.z; double d6 = this.z;

View File

@@ -255,7 +255,7 @@ index a4dc4154550bb4bd30d3e548f145cff5c693dc18..33ad3583a524bb61cc7116b50e0fc87f
if (this.level().hasChunksAt(blockposition, blockposition1)) { if (this.level().hasChunksAt(blockposition, blockposition1)) {
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos(); BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
index 05c5b6be55bf6a81ff454532b40a372f9b9c8e13..b5ecadeb96750cbdca2023eefe7778596a040c97 100644 index 21f827678437ea538f0130812c9869e3619041a5..8c34808770e590ea3308d81f891ab1f2b1268739 100644
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java --- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java +++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -90,6 +90,8 @@ public class FallingBlockEntity extends Entity { @@ -90,6 +90,8 @@ public class FallingBlockEntity extends Entity {
@@ -393,7 +393,7 @@ index 05c5b6be55bf6a81ff454532b40a372f9b9c8e13..b5ecadeb96750cbdca2023eefe777859
} }
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
index f5d391ae2a9b015f4dd753f7658ac359bc5db43e..c65e178206041600b09b238214440ed6690329e7 100644 index 2db76425a1f295ad179aacfb3abb7efb1be647d9..e7dd0c8aab980d9850a2124598f8a0369603e825 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java --- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java +++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -60,6 +60,13 @@ public class PrimedTnt extends Entity implements TraceableEntity { @@ -60,6 +60,13 @@ public class PrimedTnt extends Entity implements TraceableEntity {
@@ -487,26 +487,26 @@ index f5d391ae2a9b015f4dd753f7658ac359bc5db43e..c65e178206041600b09b238214440ed6
// Paper end - Option to prevent TNT from moving in water // Paper end - Option to prevent TNT from moving in water
} }
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
index d441e7d5e2ef15a2d719bae6bbc8ada116787416..ae350482fe2eff621dc32c6ed8f28d9bbe2fbd16 100644 index e2a560846ed479309b18d8474b3c9f9d1f89bd5c..c1687a2867832387c9038eb8c7b6b2fcd3d836e1 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java --- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java +++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -74,6 +74,7 @@ public class Explosion { @@ -75,6 +75,7 @@ public class Explosion {
public boolean wasCanceled = false;
public float yield; public float yield;
// CraftBukkit end // CraftBukkit end
private final boolean consistentRadius; // Sakura - consistent explosion radius
+ protected final me.samsuik.sakura.physics.PhysicsVersion physics; // Sakura - physics version api + protected final me.samsuik.sakura.physics.PhysicsVersion physics; // Sakura - physics version api
public static DamageSource getDefaultDamageSource(Level world, @Nullable Entity source) { public static DamageSource getDefaultDamageSource(Level world, @Nullable Entity source) {
return world.damageSources().explosion(source, Explosion.getIndirectSourceEntityInternal(source)); return world.damageSources().explosion(source, Explosion.getIndirectSourceEntityInternal(source));
@@ -111,6 +112,7 @@ public class Explosion { @@ -113,6 +114,7 @@ public class Explosion {
this.largeExplosionParticles = emitterParticle;
this.explosionSound = soundEvent; this.explosionSound = soundEvent;
this.yield = this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F; // CraftBukkit this.yield = this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F; // CraftBukkit
this.consistentRadius = world.localConfig().config(BlockPos.containing(x, y, z)).consistentRadius; // Sakura - consistent explosion radius
+ this.physics = entity != null ? entity.physics() : world.localConfig().config(BlockPos.containing(x, y, z)).physicsVersion; // Sakura - physics version api + this.physics = entity != null ? entity.physics() : world.localConfig().config(BlockPos.containing(x, y, z)).physicsVersion; // Sakura - physics version api
} }
// Sakura start - optimise paper explosions // Sakura start - optimise paper explosions
@@ -503,8 +505,12 @@ public class Explosion { @@ -505,8 +507,12 @@ public class Explosion {
final float density = entity.level().densityCache.getKnownDensity(vec3d1); final float density = entity.level().densityCache.getKnownDensity(vec3d1);
if (density != me.samsuik.sakura.explosion.density.BlockDensityCache.UNKNOWN_DENSITY) { if (density != me.samsuik.sakura.explosion.density.BlockDensityCache.UNKNOWN_DENSITY) {
hitResult = density != 0.0f ? net.minecraft.world.phys.HitResult.Type.MISS : net.minecraft.world.phys.HitResult.Type.BLOCK; hitResult = density != 0.0f ? net.minecraft.world.phys.HitResult.Type.MISS : net.minecraft.world.phys.HitResult.Type.BLOCK;
@@ -520,7 +520,7 @@ index d441e7d5e2ef15a2d719bae6bbc8ada116787416..ae350482fe2eff621dc32c6ed8f28d9b
} }
if (hitResult == HitResult.Type.MISS) { if (hitResult == HitResult.Type.MISS) {
// Sakura end - replace density cache // Sakura end - replace density cache
@@ -609,6 +615,14 @@ public class Explosion { @@ -611,6 +617,14 @@ public class Explosion {
} }
if (cachedBlock.outOfWorld) { if (cachedBlock.outOfWorld) {
@@ -535,7 +535,7 @@ index d441e7d5e2ef15a2d719bae6bbc8ada116787416..ae350482fe2eff621dc32c6ed8f28d9b
break; break;
} }
@@ -714,9 +728,15 @@ public class Explosion { @@ -716,9 +730,15 @@ public class Explosion {
if (d7 <= 1.0D) { if (d7 <= 1.0D) {
double d8 = entity.getX() - this.x; double d8 = entity.getX() - this.x;
@@ -552,7 +552,7 @@ index d441e7d5e2ef15a2d719bae6bbc8ada116787416..ae350482fe2eff621dc32c6ed8f28d9b
if (d11 != 0.0D) { if (d11 != 0.0D) {
d8 /= d11; d8 /= d11;
@@ -1048,7 +1068,7 @@ public class Explosion { @@ -1050,7 +1070,7 @@ public class Explosion {
// Sakura start - replace density cache // Sakura start - replace density cache
float blockDensity = this.level.densityCache.getDensity(vec3d, entity); float blockDensity = this.level.densityCache.getDensity(vec3d, entity);
if (blockDensity == me.samsuik.sakura.explosion.density.BlockDensityCache.UNKNOWN_DENSITY) { if (blockDensity == me.samsuik.sakura.explosion.density.BlockDensityCache.UNKNOWN_DENSITY) {
@@ -561,7 +561,7 @@ index d441e7d5e2ef15a2d719bae6bbc8ada116787416..ae350482fe2eff621dc32c6ed8f28d9b
this.level.densityCache.putDensity(vec3d, entity, blockDensity); this.level.densityCache.putDensity(vec3d, entity, blockDensity);
// Sakura end - replace density cache // Sakura end - replace density cache
} }
@@ -1056,6 +1076,17 @@ public class Explosion { @@ -1058,6 +1078,17 @@ public class Explosion {
return blockDensity; return blockDensity;
} }

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Allow explosions to destroy lava
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
index 9da068ebf5c0245aa099af9e53d34f1dfb5cdde9..3b9e5ffe45dcf1e4a0b2c5d334b0bec666594fa6 100644 index c1687a2867832387c9038eb8c7b6b2fcd3d836e1..02ec223ad1275ecc7ecfe6a3b1152ed150b57178 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java --- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java +++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -286,7 +286,7 @@ public class Explosion { @@ -288,7 +288,7 @@ public class Explosion {
if (material != null && material.resistance() >= 0.0f && (this.level.sakuraConfig().cannons.explosion.allowNonTntBreakingDurableBlocks || this.source instanceof net.minecraft.world.entity.item.PrimedTnt)) { if (material != null && material.resistance() >= 0.0f && (this.level.sakuraConfig().cannons.explosion.allowNonTntBreakingDurableBlocks || this.source instanceof net.minecraft.world.entity.item.PrimedTnt)) {
return Optional.of(material.resistance()); return Optional.of(material.resistance());
// Sakura start - destroy water logged blocks // Sakura start - destroy water logged blocks

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Add explosions dropping items config
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
index 3b9e5ffe45dcf1e4a0b2c5d334b0bec666594fa6..88a7d47c9c7d142474f54342331a31ade829c9ed 100644 index 02ec223ad1275ecc7ecfe6a3b1152ed150b57178..22007aa4c85befa80938adf3126bda12b8ff58c9 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java --- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java +++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -941,6 +941,11 @@ public class Explosion { @@ -943,6 +943,11 @@ public class Explosion {
this.level.densityCache.clear(-1); this.level.densityCache.clear(-1);
} }
// Sakura end - explosion density cache // Sakura end - explosion density cache