mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-23 16:59:16 +00:00
Fix and individually configure durable materials being damaged by tnt
This commit is contained in:
@@ -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
|
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
|
--- a/net/minecraft/world/item/BlockItem.java
|
||||||
+++ b/net/minecraft/world/item/BlockItem.java
|
+++ b/net/minecraft/world/item/BlockItem.java
|
||||||
@@ -38,8 +38,31 @@ public class BlockItem extends Item {
|
@@ -38,8 +38,31 @@ public class BlockItem extends Item {
|
||||||
@@ -41,7 +41,7 @@ index b5b53168755525eccaa0a4361172006522cf4e05..56acdfc2a8d2ecd716065263c59dbcb0
|
|||||||
return !interactionResult.consumesAction() && context.getItemInHand().has(DataComponents.CONSUMABLE)
|
return !interactionResult.consumesAction() && context.getItemInHand().has(DataComponents.CONSUMABLE)
|
||||||
? super.use(context.getLevel(), context.getPlayer(), context.getHand())
|
? super.use(context.getLevel(), context.getPlayer(), context.getHand())
|
||||||
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
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
|
--- a/net/minecraft/world/level/Level.java
|
||||||
+++ b/net/minecraft/world/level/Level.java
|
+++ b/net/minecraft/world/level/Level.java
|
||||||
@@ -830,6 +830,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
@@ -830,6 +830,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
||||||
@@ -53,7 +53,7 @@ index ca5e2ec53590b731aedf33dfd69e728992f52b91..5aaa3f01b7e8b55742ba46dd614f1eaa
|
|||||||
protected Level(
|
protected Level(
|
||||||
WritableLevelData levelData,
|
WritableLevelData levelData,
|
||||||
diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java
|
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
|
--- a/net/minecraft/world/level/ServerExplosion.java
|
||||||
+++ b/net/minecraft/world/level/ServerExplosion.java
|
+++ b/net/minecraft/world/level/ServerExplosion.java
|
||||||
@@ -131,7 +131,7 @@ public class ServerExplosion implements Explosion {
|
@@ -131,7 +131,7 @@ public class ServerExplosion implements Explosion {
|
||||||
@@ -75,7 +75,7 @@ index d45582bdfc3fa837c5aa95f499183b60b877b7c2..4a6677fbc520d3f5d537f35a92dab9ec
|
|||||||
+ final Block block = blockState.getBlock();
|
+ final Block block = blockState.getBlock();
|
||||||
+ final me.samsuik.sakura.explosion.durable.DurableMaterial material = this.level.localConfig().config(pos).durableMaterials.get(block);
|
+ 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());
|
+ return Optional.of(material.resistance());
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
@@ -91,9 +91,9 @@ index d45582bdfc3fa837c5aa95f499183b60b877b7c2..4a6677fbc520d3f5d537f35a92dab9ec
|
|||||||
}
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
+ // Sakura start - explosion durable blocks
|
+ // 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);
|
||||||
+ 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 != null && material.durability() >= 0 && !this.level.durabilityManager.damage(blockPos, material)) {
|
+ if (material.onlyDamagedByTnt() && !(this.source instanceof PrimedTnt) || !this.level.durabilityManager.damage(blockPos, material)) {
|
||||||
+ continue;
|
+ continue;
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
|
|||||||
@@ -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
|
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
|
--- a/net/minecraft/world/level/ServerExplosion.java
|
||||||
+++ b/net/minecraft/world/level/ServerExplosion.java
|
+++ b/net/minecraft/world/level/ServerExplosion.java
|
||||||
@@ -399,6 +399,11 @@ public class ServerExplosion implements Explosion {
|
@@ -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());
|
return Optional.of(material.resistance());
|
||||||
}
|
}
|
||||||
+ // Sakura start - destroy water logged blocks
|
+ // Sakura start - destroy water logged blocks
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import java.util.Set;
|
|||||||
public final class WorldConfiguration extends ConfigurationPart {
|
public final class WorldConfiguration extends ConfigurationPart {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogUtils.getClassLogger();
|
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;
|
private transient final ResourceLocation worldKey;
|
||||||
WorldConfiguration(ResourceLocation worldKey) {
|
WorldConfiguration(ResourceLocation worldKey) {
|
||||||
@@ -88,13 +88,11 @@ public final class WorldConfiguration extends ConfigurationPart {
|
|||||||
public boolean useBlockCacheAcrossExplosions = false;
|
public boolean useBlockCacheAcrossExplosions = false;
|
||||||
|
|
||||||
public Map<Block, DurableMaterial> durableMaterials = Util.make(new Reference2ObjectOpenHashMap<>(), map -> {
|
public Map<Block, DurableMaterial> durableMaterials = Util.make(new Reference2ObjectOpenHashMap<>(), map -> {
|
||||||
map.put(Blocks.OBSIDIAN, new DurableMaterial(4, Blocks.COBBLESTONE.getExplosionResistance()));
|
map.put(Blocks.OBSIDIAN, new DurableMaterial(4, Blocks.COBBLESTONE.getExplosionResistance(), true));
|
||||||
map.put(Blocks.ANVIL, new DurableMaterial(3, Blocks.END_STONE.getExplosionResistance()));
|
map.put(Blocks.ANVIL, new DurableMaterial(3, Blocks.END_STONE.getExplosionResistance(), true));
|
||||||
map.put(Blocks.CHIPPED_ANVIL, new DurableMaterial(3, Blocks.END_STONE.getExplosionResistance()));
|
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()));
|
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 protectScaffoldingFromCreepers = false;
|
||||||
public boolean destroyWaterloggedBlocks = false;
|
public boolean destroyWaterloggedBlocks = false;
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ public final class LocalValueConfig {
|
|||||||
storage.get(LocalValueKeys.DURABLE_MATERIALS).ifPresent(materials -> {
|
storage.get(LocalValueKeys.DURABLE_MATERIALS).ifPresent(materials -> {
|
||||||
materials.forEach((materialType, materialProperties) -> {
|
materials.forEach((materialType, materialProperties) -> {
|
||||||
Block nmsBlock = CraftMagicNumbers.getBlock(materialType);
|
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);
|
this.durableMaterials.put(nmsBlock, durableMaterial);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public final class ConfigurationTransformations {
|
|||||||
V7_FixTntDuplicationName.apply(versionedBuilder);
|
V7_FixTntDuplicationName.apply(versionedBuilder);
|
||||||
V8_RenameExplosionResistantItems.apply(versionedBuilder);
|
V8_RenameExplosionResistantItems.apply(versionedBuilder);
|
||||||
V9_RenameAllowNonTntBreakingDurableBlocks.apply(versionedBuilder);
|
V9_RenameAllowNonTntBreakingDurableBlocks.apply(versionedBuilder);
|
||||||
|
V10_DurableMaterialOnlyDamagedByTnt.apply(versionedBuilder);
|
||||||
// ADD FUTURE VERSIONED TRANSFORMS TO versionedBuilder HERE
|
// ADD FUTURE VERSIONED TRANSFORMS TO versionedBuilder HERE
|
||||||
versionedBuilder.build().apply(node);
|
versionedBuilder.build().apply(node);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package me.samsuik.sakura.explosion.durable;
|
package me.samsuik.sakura.explosion.durable;
|
||||||
|
|
||||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||||
|
import org.spongepowered.configurate.objectmapping.meta.Required;
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public record DurableMaterial(int durability, float resistance) {
|
public record DurableMaterial(int durability, float resistance, @Required boolean onlyDamagedByTnt) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user