From a6e391d6a77be87e3c1c564f134eabc10260568c Mon Sep 17 00:00:00 2001 From: Samsuik Date: Fri, 11 Apr 2025 22:21:15 +0100 Subject: [PATCH] Configure items that can that drop from explosions --- ...0009-Replace-explosion-density-cache.patch | 6 ++--- .../0011-Specialised-Explosions.patch | 8 +++---- .../0017-Configure-cannon-physics.patch | 6 ++--- .../world/entity/item/ItemEntity.java.patch | 6 +++-- .../world/level/ServerExplosion.java.patch | 16 +++++++++---- .../configuration/WorldConfiguration.java | 13 ++++++++++- .../ConfigurationTransformations.java | 1 + .../V8_RenameExplosionResistantItems.java | 23 +++++++++++++++++++ 8 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 sakura-server/src/main/java/me/samsuik/sakura/configuration/transformation/world/V8_RenameExplosionResistantItems.java diff --git a/sakura-server/minecraft-patches/features/0009-Replace-explosion-density-cache.patch b/sakura-server/minecraft-patches/features/0009-Replace-explosion-density-cache.patch index ee5e47f..82ca236 100644 --- a/sakura-server/minecraft-patches/features/0009-Replace-explosion-density-cache.patch +++ b/sakura-server/minecraft-patches/features/0009-Replace-explosion-density-cache.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Replace explosion density cache diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index fc70f238f551e819a610c5cf61e3fe4e6a547196..50bf6d317d5574e26cbfff431711cb6a5a1310c4 100644 +index a4428a3c23db6f795b5ff0ead634e2e21468e3a6..ae0b6d506f0344249bdc238fff0f5a3306d05334 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -688,6 +688,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -29,7 +29,7 @@ index 37271a9e9d3d16a01c437629806508accefa1b9c..d111bd5546613cefd8b4070788679901 protected Level( WritableLevelData levelData, diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java -index 5c029776df58976df6791f66618c97980fbfa4dc..38657fa606ae34a3bb752fcd01f7aa732fe17c7e 100644 +index 71d79a1204d9335c98a63ecda9782755a964b22f..cc337b1656b5bf86da9125a3a1c2da06cc2814ba 100644 --- a/net/minecraft/world/level/ServerExplosion.java +++ b/net/minecraft/world/level/ServerExplosion.java @@ -294,7 +294,12 @@ public class ServerExplosion implements Explosion { @@ -77,7 +77,7 @@ index 5c029776df58976df6791f66618c97980fbfa4dc..38657fa606ae34a3bb752fcd01f7aa73 for (BlockPos blockPos : blocks) { // CraftBukkit start - TNTPrimeEvent -@@ -844,14 +862,12 @@ public class ServerExplosion implements Explosion { +@@ -851,14 +869,12 @@ public class ServerExplosion implements Explosion { // Paper start - Optimize explosions protected float getBlockDensity(Vec3 vec3d, Entity entity) { diff --git a/sakura-server/minecraft-patches/features/0011-Specialised-Explosions.patch b/sakura-server/minecraft-patches/features/0011-Specialised-Explosions.patch index d063793..1f26d0f 100644 --- a/sakura-server/minecraft-patches/features/0011-Specialised-Explosions.patch +++ b/sakura-server/minecraft-patches/features/0011-Specialised-Explosions.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Specialised Explosions diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 50bf6d317d5574e26cbfff431711cb6a5a1310c4..effdd0e1382fc59b9d8a709c18a652fbd4e94e6d 100644 +index ae0b6d506f0344249bdc238fff0f5a3306d05334..919793ba79ab19e86e42a8a97711563e504c0aed 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -1891,7 +1891,16 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -78,7 +78,7 @@ index 13fdcee0437695ae22180c6091b7aa72a1f1d087..57cfc90b3193fe8603cf10c444ae9be6 // Sakura end - merge cannon entities diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java -index c597226b6a90ab687d176fe63e21c9c2cd71c7e1..6510ce55b9590fbfa50b70b56180840abf565731 100644 +index c776277ce455b32f99fe06ab409c1923f9dcd325..9f0dcaf0db44925c35fa46fdb2de83540ee959c4 100644 --- a/net/minecraft/world/level/ServerExplosion.java +++ b/net/minecraft/world/level/ServerExplosion.java @@ -358,6 +358,38 @@ public class ServerExplosion implements Explosion { @@ -132,7 +132,7 @@ index c597226b6a90ab687d176fe63e21c9c2cd71c7e1..6510ce55b9590fbfa50b70b56180840a } entity.onExplosionHit(this.source); -@@ -767,14 +802,7 @@ public class ServerExplosion implements Explosion { +@@ -774,14 +809,7 @@ public class ServerExplosion implements Explosion { return; } // CraftBukkit end @@ -148,7 +148,7 @@ index c597226b6a90ab687d176fe63e21c9c2cd71c7e1..6510ce55b9590fbfa50b70b56180840a this.level.gameEvent(this.source, GameEvent.EXPLODE, this.center); List list = this.calculateExplodedPositions(); this.hurtEntities(); -@@ -788,13 +816,7 @@ public class ServerExplosion implements Explosion { +@@ -795,13 +823,7 @@ public class ServerExplosion implements Explosion { if (this.fire) { this.createFire(list); } diff --git a/sakura-server/minecraft-patches/features/0017-Configure-cannon-physics.patch b/sakura-server/minecraft-patches/features/0017-Configure-cannon-physics.patch index 4b777f7..c2f2ad7 100644 --- a/sakura-server/minecraft-patches/features/0017-Configure-cannon-physics.patch +++ b/sakura-server/minecraft-patches/features/0017-Configure-cannon-physics.patch @@ -436,7 +436,7 @@ index dd7e32b8b176c0f4c13e50aeed33c2c9ccba4b53..673e07e24c0cc0bc8301a15ca028c0bd Vec3 minPosition = boundingBox.getMinPosition(); Vec3 vec31 = minPosition.subtract(vec3); diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java -index 65d2b93a6ca6f18aae72627b7a21215eecdcc9c2..26cd9559013ca2bb17b98f2675e7c43f76519d8b 100644 +index 323e91e494aef643ecd6f47c5b149a8e36a59dfb..ccf5470c26dee1431e2bd8fa8a90fb3770451807 100644 --- a/net/minecraft/world/level/ServerExplosion.java +++ b/net/minecraft/world/level/ServerExplosion.java @@ -409,6 +409,7 @@ public class ServerExplosion implements Explosion { @@ -499,7 +499,7 @@ index 65d2b93a6ca6f18aae72627b7a21215eecdcc9c2..26cd9559013ca2bb17b98f2675e7c43f if (squareRoot != 0.0) { d1 /= squareRoot; d2 /= squareRoot; -@@ -935,7 +957,7 @@ public class ServerExplosion implements Explosion { +@@ -942,7 +964,7 @@ public class ServerExplosion implements Explosion { // Sakura start - replace density cache float blockDensity = this.level.densityCache.getDensity(vec3d, entity); if (blockDensity == me.samsuik.sakura.explosion.density.BlockDensityCache.UNKNOWN_DENSITY) { @@ -508,7 +508,7 @@ index 65d2b93a6ca6f18aae72627b7a21215eecdcc9c2..26cd9559013ca2bb17b98f2675e7c43f this.level.densityCache.putDensity(vec3d, entity, blockDensity); // Sakura end - replace density cache } -@@ -943,6 +965,16 @@ public class ServerExplosion implements Explosion { +@@ -950,6 +972,16 @@ public class ServerExplosion implements Explosion { return blockDensity; } diff --git a/sakura-server/minecraft-patches/sources/net/minecraft/world/entity/item/ItemEntity.java.patch b/sakura-server/minecraft-patches/sources/net/minecraft/world/entity/item/ItemEntity.java.patch index 7407cac..39792fa 100644 --- a/sakura-server/minecraft-patches/sources/net/minecraft/world/entity/item/ItemEntity.java.patch +++ b/sakura-server/minecraft-patches/sources/net/minecraft/world/entity/item/ItemEntity.java.patch @@ -1,11 +1,13 @@ --- a/net/minecraft/world/entity/item/ItemEntity.java +++ b/net/minecraft/world/entity/item/ItemEntity.java -@@ -370,6 +_,11 @@ +@@ -370,6 +_,13 @@ @Override public boolean ignoreExplosion(Explosion explosion) { + // Sakura start - add list of items that ignore explosions -+ if (this.level().sakuraConfig().entity.items.explosionResistantItems.contains(this.getItem().getItem()) != this.level().sakuraConfig().entity.items.useWhitelistForExplosionResistantItems) { ++ final java.util.Set blastResistantTypes = this.level().sakuraConfig().entity.items.blastResistant.items; ++ final boolean whitelist = this.level().sakuraConfig().entity.items.blastResistant.whitelistOverBlacklist; ++ if (blastResistantTypes.contains(this.getItem().getItem()) != whitelist) { + return true; + } + // Sakura end - add list of items that ignore explosions diff --git a/sakura-server/minecraft-patches/sources/net/minecraft/world/level/ServerExplosion.java.patch b/sakura-server/minecraft-patches/sources/net/minecraft/world/level/ServerExplosion.java.patch index c2f35dc..86e4310 100644 --- a/sakura-server/minecraft-patches/sources/net/minecraft/world/level/ServerExplosion.java.patch +++ b/sakura-server/minecraft-patches/sources/net/minecraft/world/level/ServerExplosion.java.patch @@ -26,16 +26,24 @@ do { final int blockX = Mth.floor(currX); -@@ -618,6 +_,12 @@ - .getBlockState(blockPos) +@@ -619,7 +_,20 @@ .onExplosionHit(this.level, blockPos, this, (itemStack, blockPos1) -> addOrAppendStack(list, itemStack, blockPos1)); } -+ + + // Sakura start - configure explosions dropping items + if (!this.level.sakuraConfig().cannons.explosion.explosionsDropItems) { + list.clear(); + } + // Sakura end - configure explosions dropping items - ++ ++ // Sakura start - configure items that can that drop from explosions ++ final Set explosionItemDrops = this.level.sakuraConfig().entity.items.explosionItemDrops.items; ++ final boolean whitelist = this.level.sakuraConfig().entity.items.explosionItemDrops.whitelistOverBlacklist; for (ServerExplosion.StackCollector stackCollector : list) { ++ if (explosionItemDrops.contains(stackCollector.stack.getItem()) != whitelist) { ++ continue; ++ } ++ // Sakura start - configure items that can that drop from explosions Block.popResource(this.level, stackCollector.pos, stackCollector.stack); + } + } diff --git a/sakura-server/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java b/sakura-server/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java index 8036432..b423eea 100644 --- a/sakura-server/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java +++ b/sakura-server/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java @@ -23,6 +23,7 @@ import org.spongepowered.configurate.objectmapping.meta.Setting; import java.util.List; import java.util.Map; +import java.util.Set; @SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal", "NotNullFieldNotInitialized", "InnerClassMayBeStatic", "RedundantSuppression"}) public final class WorldConfiguration extends ConfigurationPart { @@ -191,7 +192,17 @@ public final class WorldConfiguration extends ConfigurationPart { public Items items = new Items(); public class Items extends ConfigurationPart { public boolean useWhitelistForExplosionResistantItems = true; - public List explosionResistantItems = List.of(); + public BlastResistant blastResistant = new BlastResistant(); + public class BlastResistant extends ConfigurationPart { + public Set items = Set.of(); + public boolean whitelistOverBlacklist = true; + } + + public ExplosionItemDrops explosionItemDrops = new ExplosionItemDrops(); + public class ExplosionItemDrops extends ConfigurationPart { + public Set items = Set.of(); + public boolean whitelistOverBlacklist = false; + } } @Comment("Entity travel distance limits") diff --git a/sakura-server/src/main/java/me/samsuik/sakura/configuration/transformation/ConfigurationTransformations.java b/sakura-server/src/main/java/me/samsuik/sakura/configuration/transformation/ConfigurationTransformations.java index 41c6c60..ebe9caf 100644 --- a/sakura-server/src/main/java/me/samsuik/sakura/configuration/transformation/ConfigurationTransformations.java +++ b/sakura-server/src/main/java/me/samsuik/sakura/configuration/transformation/ConfigurationTransformations.java @@ -25,6 +25,7 @@ public final class ConfigurationTransformations { V5_CombineLoadChunksOptions.apply(versionedBuilder); V6_FixIncorrectExtraKnockback.apply(versionedBuilder); V7_FixTntDuplicationName.apply(versionedBuilder); + V8_RenameExplosionResistantItems.apply(versionedBuilder); // ADD FUTURE VERSIONED TRANSFORMS TO versionedBuilder HERE versionedBuilder.build().apply(node); } diff --git a/sakura-server/src/main/java/me/samsuik/sakura/configuration/transformation/world/V8_RenameExplosionResistantItems.java b/sakura-server/src/main/java/me/samsuik/sakura/configuration/transformation/world/V8_RenameExplosionResistantItems.java new file mode 100644 index 0000000..16fcaf6 --- /dev/null +++ b/sakura-server/src/main/java/me/samsuik/sakura/configuration/transformation/world/V8_RenameExplosionResistantItems.java @@ -0,0 +1,23 @@ +package me.samsuik.sakura.configuration.transformation.world; + +import org.spongepowered.configurate.NodePath; +import org.spongepowered.configurate.transformation.ConfigurationTransformation; +import org.spongepowered.configurate.transformation.TransformAction; + +import static org.spongepowered.configurate.NodePath.path; + +public final class V8_RenameExplosionResistantItems { + private static final int VERSION = 8; + private static final NodePath BASE_PATH = path("entity", "items"); + private static final NodePath OLD_WHITELIST_PATH = BASE_PATH.plus(path("use-whitelist-for-explosion-resistant-items")); + private static final NodePath NEW_WHITELIST_PATH = BASE_PATH.plus(path("blast-resistant", "whitelist-over-blacklist")); + private static final NodePath OLD_ITEMS_PATH = BASE_PATH.plus(path("explosion-resistant-items")); + private static final NodePath NEW_ITEMS_PATH = BASE_PATH.plus(path("blast-resistant", "items")); + + public static void apply(ConfigurationTransformation.VersionedBuilder builder) { + builder.addVersion(VERSION, ConfigurationTransformation.builder() + .addAction(OLD_WHITELIST_PATH, TransformAction.rename(NEW_WHITELIST_PATH)) + .addAction(OLD_ITEMS_PATH, TransformAction.rename(NEW_ITEMS_PATH)) + .build()); + } +}