diff --git a/sakura-server/minecraft-patches/features/0015-Explosion-Durable-Blocks.patch b/sakura-server/minecraft-patches/features/0015-Explosion-Durable-Blocks.patch index a040d5b..cdea6ae 100644 --- a/sakura-server/minecraft-patches/features/0015-Explosion-Durable-Blocks.patch +++ b/sakura-server/minecraft-patches/features/0015-Explosion-Durable-Blocks.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Explosion Durable Blocks diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java -index b5b53168755525eccaa0a4361172006522cf4e05..56acdfc2a8d2ecd716065263c59dbcb0ec7135bf 100644 +index 6db566adf2d0df1d26221eda04aa01738df6d3d2..a12068c3adbb147eeb41a093fcd2938cc2c34a15 100644 --- a/net/minecraft/world/item/BlockItem.java +++ b/net/minecraft/world/item/BlockItem.java @@ -38,8 +38,31 @@ public class BlockItem extends Item { @@ -41,7 +41,7 @@ index b5b53168755525eccaa0a4361172006522cf4e05..56acdfc2a8d2ecd716065263c59dbcb0 return !interactionResult.consumesAction() && context.getItemInHand().has(DataComponents.CONSUMABLE) ? super.use(context.getLevel(), context.getPlayer(), context.getHand()) diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java -index ca5e2ec53590b731aedf33dfd69e728992f52b91..5aaa3f01b7e8b55742ba46dd614f1eaa233aa5c9 100644 +index 44849a074694a3f4438cf7f0672c78219859a20f..72537c6455ff0e38c98a83fd81c5afe17a0b387e 100644 --- a/net/minecraft/world/level/Level.java +++ b/net/minecraft/world/level/Level.java @@ -830,6 +830,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup, AutoCl @@ -53,7 +53,7 @@ index ca5e2ec53590b731aedf33dfd69e728992f52b91..5aaa3f01b7e8b55742ba46dd614f1eaa protected Level( WritableLevelData levelData, diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java -index d45582bdfc3fa837c5aa95f499183b60b877b7c2..4a6677fbc520d3f5d537f35a92dab9ec69db47a0 100644 +index d45582bdfc3fa837c5aa95f499183b60b877b7c2..341b162252efc4e65cba8a32b4c7936defede097 100644 --- a/net/minecraft/world/level/ServerExplosion.java +++ b/net/minecraft/world/level/ServerExplosion.java @@ -131,7 +131,7 @@ public class ServerExplosion implements Explosion { @@ -75,7 +75,7 @@ index d45582bdfc3fa837c5aa95f499183b60b877b7c2..4a6677fbc520d3f5d537f35a92dab9ec + final Block block = blockState.getBlock(); + final me.samsuik.sakura.explosion.durable.DurableMaterial material = this.level.localConfig().config(pos).durableMaterials.get(block); + -+ if (material != null && material.resistance() >= 0.0f && pos.getY() > this.level.getMinY() && (!this.level.sakuraConfig().cannons.explosion.requireTntToDamageDurableMaterials || this.source instanceof net.minecraft.world.entity.item.PrimedTnt)) { ++ if (material != null && material.resistance() >= 0.0f && pos.getY() > this.level.getMinY()) { + return Optional.of(material.resistance()); + } + } @@ -91,9 +91,9 @@ index d45582bdfc3fa837c5aa95f499183b60b877b7c2..4a6677fbc520d3f5d537f35a92dab9ec } // CraftBukkit end + // Sakura start - explosion durable blocks -+ if (!this.level.sakuraConfig().cannons.explosion.requireTntToDamageDurableMaterials || this.source instanceof net.minecraft.world.entity.item.PrimedTnt) { -+ final me.samsuik.sakura.explosion.durable.DurableMaterial material = this.level.localConfig().config(blockPos).durableMaterials.get(block); -+ if (material != null && material.durability() >= 0 && !this.level.durabilityManager.damage(blockPos, material)) { ++ final me.samsuik.sakura.explosion.durable.DurableMaterial material = this.level.localConfig().config(blockPos).durableMaterials.get(block); ++ if (material != null && material.durability() >= 0) { // if durability is < 0 then only altar the blast resistance ++ if (material.onlyDamagedByTnt() && !(this.source instanceof PrimedTnt) || !this.level.durabilityManager.damage(blockPos, material)) { + continue; + } + } diff --git a/sakura-server/minecraft-patches/features/0016-Destroy-Waterlogged-Blocks.patch b/sakura-server/minecraft-patches/features/0016-Destroy-Waterlogged-Blocks.patch index 6c6fa01..fd5d773 100644 --- a/sakura-server/minecraft-patches/features/0016-Destroy-Waterlogged-Blocks.patch +++ b/sakura-server/minecraft-patches/features/0016-Destroy-Waterlogged-Blocks.patch @@ -5,11 +5,11 @@ Subject: [PATCH] Destroy Waterlogged Blocks diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java -index 48d98bac0140cec91fe2c9e7bb72a6f05a70aa49..5810539dbe4ed782ec638bb9f08f183e5a720284 100644 +index 341b162252efc4e65cba8a32b4c7936defede097..9e5fe4314513b6364c51e60c1718ed942fd2dba9 100644 --- a/net/minecraft/world/level/ServerExplosion.java +++ b/net/minecraft/world/level/ServerExplosion.java @@ -399,6 +399,11 @@ public class ServerExplosion implements Explosion { - if (material != null && material.resistance() >= 0.0f && pos.getY() > this.level.getMinY() && (!this.level.sakuraConfig().cannons.explosion.requireTntToDamageDurableMaterials || this.source instanceof net.minecraft.world.entity.item.PrimedTnt)) { + if (material != null && material.resistance() >= 0.0f && pos.getY() > this.level.getMinY()) { return Optional.of(material.resistance()); } + // Sakura start - destroy water logged blocks 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 620f6fc..3381e70 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 @@ -28,7 +28,7 @@ import java.util.Set; public final class WorldConfiguration extends ConfigurationPart { private static final Logger LOGGER = LogUtils.getClassLogger(); - static final int CURRENT_VERSION = 9; // (when you change the version, change the comment, so it conflicts on rebases): rename filter bad nbt from spawn eggs + static final int CURRENT_VERSION = 10; // (when you change the version, change the comment, so it conflicts on rebases): rename filter bad nbt from spawn eggs private transient final ResourceLocation worldKey; WorldConfiguration(ResourceLocation worldKey) { @@ -88,13 +88,11 @@ public final class WorldConfiguration extends ConfigurationPart { public boolean useBlockCacheAcrossExplosions = false; public Map durableMaterials = Util.make(new Reference2ObjectOpenHashMap<>(), map -> { - map.put(Blocks.OBSIDIAN, new DurableMaterial(4, Blocks.COBBLESTONE.getExplosionResistance())); - map.put(Blocks.ANVIL, new DurableMaterial(3, Blocks.END_STONE.getExplosionResistance())); - map.put(Blocks.CHIPPED_ANVIL, new DurableMaterial(3, Blocks.END_STONE.getExplosionResistance())); - map.put(Blocks.DAMAGED_ANVIL, new DurableMaterial(3, Blocks.END_STONE.getExplosionResistance())); + map.put(Blocks.OBSIDIAN, new DurableMaterial(4, Blocks.COBBLESTONE.getExplosionResistance(), true)); + map.put(Blocks.ANVIL, new DurableMaterial(3, Blocks.END_STONE.getExplosionResistance(), true)); + map.put(Blocks.CHIPPED_ANVIL, new DurableMaterial(3, Blocks.END_STONE.getExplosionResistance(), true)); + map.put(Blocks.DAMAGED_ANVIL, new DurableMaterial(3, Blocks.END_STONE.getExplosionResistance(), true)); }); - @Comment("When disabled all explosions will be able to damage durable materials.") - public boolean requireTntToDamageDurableMaterials = true; public boolean protectScaffoldingFromCreepers = false; public boolean destroyWaterloggedBlocks = false; diff --git a/sakura-server/src/main/java/me/samsuik/sakura/configuration/local/LocalValueConfig.java b/sakura-server/src/main/java/me/samsuik/sakura/configuration/local/LocalValueConfig.java index 53f858a..1c442a9 100644 --- a/sakura-server/src/main/java/me/samsuik/sakura/configuration/local/LocalValueConfig.java +++ b/sakura-server/src/main/java/me/samsuik/sakura/configuration/local/LocalValueConfig.java @@ -32,7 +32,8 @@ public final class LocalValueConfig { storage.get(LocalValueKeys.DURABLE_MATERIALS).ifPresent(materials -> { materials.forEach((materialType, materialProperties) -> { Block nmsBlock = CraftMagicNumbers.getBlock(materialType); - DurableMaterial durableMaterial = new DurableMaterial(materialProperties.getKey(), materialProperties.getValue()); + // temp, will be updated later + DurableMaterial durableMaterial = new DurableMaterial(materialProperties.getKey(), materialProperties.getValue(), false); this.durableMaterials.put(nmsBlock, durableMaterial); }); }); 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 25b4864..30dfeaf 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 @@ -28,6 +28,7 @@ public final class ConfigurationTransformations { V7_FixTntDuplicationName.apply(versionedBuilder); V8_RenameExplosionResistantItems.apply(versionedBuilder); V9_RenameAllowNonTntBreakingDurableBlocks.apply(versionedBuilder); + V10_DurableMaterialOnlyDamagedByTnt.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/V10_DurableMaterialOnlyDamagedByTnt.java b/sakura-server/src/main/java/me/samsuik/sakura/configuration/transformation/world/V10_DurableMaterialOnlyDamagedByTnt.java new file mode 100644 index 0000000..d5b19df --- /dev/null +++ b/sakura-server/src/main/java/me/samsuik/sakura/configuration/transformation/world/V10_DurableMaterialOnlyDamagedByTnt.java @@ -0,0 +1,32 @@ +package me.samsuik.sakura.configuration.transformation.world; + +import org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.configurate.ConfigurateException; +import org.spongepowered.configurate.ConfigurationNode; +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 V10_DurableMaterialOnlyDamagedByTnt implements TransformAction { + private static final int VERSION = 10; + private static final V10_DurableMaterialOnlyDamagedByTnt INSTANCE = new V10_DurableMaterialOnlyDamagedByTnt(); + private static final NodePath EXPLOSION_PATH = path("cannons", "explosion"); + + public static void apply(final ConfigurationTransformation.VersionedBuilder builder) { + builder.addVersion(VERSION, ConfigurationTransformation.builder() + .addAction(EXPLOSION_PATH.plus(path("durable-materials")), INSTANCE) + .addAction(EXPLOSION_PATH.plus(path("require-tnt-to-damage-durable-materials")), TransformAction.remove()) + .build()); + } + + @Override + public Object @Nullable [] visitPath(final NodePath path, final ConfigurationNode value) throws ConfigurateException { + for (final ConfigurationNode child : value.childrenList()) { + child.node(path("only-damaged-by-tnt"), true); + } + + return new Object[0]; + } +} diff --git a/sakura-server/src/main/java/me/samsuik/sakura/explosion/durable/DurableMaterial.java b/sakura-server/src/main/java/me/samsuik/sakura/explosion/durable/DurableMaterial.java index 4024f97..c337091 100644 --- a/sakura-server/src/main/java/me/samsuik/sakura/explosion/durable/DurableMaterial.java +++ b/sakura-server/src/main/java/me/samsuik/sakura/explosion/durable/DurableMaterial.java @@ -1,7 +1,8 @@ package me.samsuik.sakura.explosion.durable; import org.spongepowered.configurate.objectmapping.ConfigSerializable; +import org.spongepowered.configurate.objectmapping.meta.Required; @ConfigSerializable -public record DurableMaterial(int durability, float resistance) { +public record DurableMaterial(int durability, float resistance, @Required boolean onlyDamagedByTnt) { }