9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-19 14:59:30 +00:00

Configure items that can that drop from explosions

This commit is contained in:
Samsuik
2025-04-11 22:21:15 +01:00
parent 352dfb2881
commit a6e391d6a7
8 changed files with 62 additions and 17 deletions

View File

@@ -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) {

View File

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

View File

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

View File

@@ -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<Item> 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

View File

@@ -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<net.minecraft.world.item.Item> 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);
}
}

View File

@@ -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<Item> explosionResistantItems = List.of();
public BlastResistant blastResistant = new BlastResistant();
public class BlastResistant extends ConfigurationPart {
public Set<Item> items = Set.of();
public boolean whitelistOverBlacklist = true;
}
public ExplosionItemDrops explosionItemDrops = new ExplosionItemDrops();
public class ExplosionItemDrops extends ConfigurationPart {
public Set<Item> items = Set.of();
public boolean whitelistOverBlacklist = false;
}
}
@Comment("Entity travel distance limits")

View File

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

View File

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