9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-22 16:29:16 +00:00
Files
SakuraMC/patches/server/0029-Explosion-Durable-Blocks.patch
Samsuik ca5ff29a0d Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@691d452 Fix bundled spark permission check (#11355)
PaperMC/Paper@012c527 Update Velocity natives (#11347)
PaperMC/Paper@953e6e9 Fire BlockExpEvent on grindstone use (#11346)
PaperMC/Paper@10f5879 Change condition check order of entity tracking Y (#11348)
PaperMC/Paper@805a974 Improve console completion with brig suggestions (#9251)
PaperMC/Paper@e0021b1 Fix allowSpiderWorldBorderClimbing world config (#11321)
PaperMC/Paper@3db4758 Check dead flag in isAlive() (#11330)
PaperMC/Paper@21f125f Revert velocity natives to 3.1.2 (#11368)
PaperMC/Paper@0e82527 Fix NPE while trying to respawn an already disconnected player (#11353)
PaperMC/Paper@5d91bef Fix shulkerbox loot table replenish (#11366)
PaperMC/Paper@a8e6a93 Deprecate for removal all OldEnum-related methods (#11371)
PaperMC/Paper@925c3b9 Add FeatureFlag API (#8952)
PaperMC/Paper@426f992 Enchantment is data-driven, so not FeatureDependant (#11377)
PaperMC/Paper@1ba1be7 Update Velocity natives again
PaperMC/Paper@7632de5 Tag Lifecycle Events (#10993)
PaperMC/Paper@b09eaf2 Add Item serialization as json api (#11235)
PaperMC/Paper@971a7a5 Add Decorated Pot Cracked API (#11365)
PaperMC/Paper@61fe23c deprecate isEnabledByFeature in Item/BlockType
PaperMC/Paper@e945cfe Fix PaperServerListPingEvent#getPlayerSample not being populated or used (#11387)
PaperMC/Paper@4ff58c4 Update spark
PaperMC/Paper@d1a72ea Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11405)
PaperMC/Paper@0a53f1d Set default drop behavior for player deaths (#11380)
PaperMC/Paper@951e7dd Fix TrialSpawner forgetting assigned mob when placed by player (#11381)
PaperMC/Paper@13a2395 Fix enable-player-collisions playing sounds when set to false (#11390)
PaperMC/Paper@1348e44 Prevent NPE when serializing unresolved profile (#11407)
PaperMC/Paper@2aaf436 Validate slot in PlayerInventory#setSlot (#11399)
PaperMC/Paper@5c82955 Only mark decorations dirty if a removal actually occurs (#11413)
PaperMC/Paper@c5a1066 Remove wall-time / unused skip tick protection (#11412)
2024-09-22 20:38:14 +01:00

170 lines
10 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <40902469+Samsuik@users.noreply.github.com>
Date: Wed, 15 Nov 2023 23:18:38 +0000
Subject: [PATCH] Explosion Durable Blocks
diff --git a/src/main/java/me/samsuik/sakura/explosion/durable/DurableBlockManager.java b/src/main/java/me/samsuik/sakura/explosion/durable/DurableBlockManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..e52cae27c2bbf4fa02d49d1c69d8e1240fddfb81
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/explosion/durable/DurableBlockManager.java
@@ -0,0 +1,43 @@
+package me.samsuik.sakura.explosion.durable;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import net.minecraft.core.BlockPos;
+
+import java.util.concurrent.TimeUnit;
+
+public final class DurableBlockManager {
+ private final Cache<BlockPos, DurableBlock> durableBlocks = CacheBuilder.newBuilder()
+ .expireAfterAccess(1, TimeUnit.MINUTES)
+ .maximumSize(65534)
+ .build();
+
+ public boolean damage(BlockPos pos, DurableMaterial material) {
+ DurableBlock block = this.durableBlocks.getIfPresent(pos);
+ if (block == null) {
+ this.durableBlocks.put(pos, block = new DurableBlock(material.durability()));
+ }
+ return block.damage();
+ }
+
+ public int durability(BlockPos pos, DurableMaterial material) {
+ final DurableBlock block = this.durableBlocks.getIfPresent(pos);
+ return block != null ? block.durability() : material.durability();
+ }
+
+ private static final class DurableBlock {
+ private int durability;
+
+ public DurableBlock(int durability) {
+ this.durability = durability;
+ }
+
+ public int durability() {
+ return this.durability;
+ }
+
+ public boolean damage() {
+ return --this.durability <= 0;
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 8041737aa751bec1c51ee3d9dacd6dfb2b845265..7073914cfd5759bea92ce098ad36a86afee5dd37 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1824,6 +1824,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
worldserver.localConfig().expire(currentTick); // Sakura - add local config
worldserver.mergeHandler.expire(currentTick); // Sakura - merge cannon entities
worldserver.densityCache.invalidate(); // Sakura - explosion density cache
+ worldserver.redstoneTracker.expire(currentTick); // Sakura
}
this.isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
diff --git a/src/main/java/net/minecraft/world/item/ItemNameBlockItem.java b/src/main/java/net/minecraft/world/item/ItemNameBlockItem.java
index a8008c7550488be34b51f4280f5569170b1ebd1d..2e5a46b9d27b930870c68dbde93d8731fd364219 100644
--- a/src/main/java/net/minecraft/world/item/ItemNameBlockItem.java
+++ b/src/main/java/net/minecraft/world/item/ItemNameBlockItem.java
@@ -7,6 +7,33 @@ public class ItemNameBlockItem extends BlockItem {
super(block, settings);
}
+ // Sakura start - explosion durable blocks
+ @Override
+ public net.minecraft.world.InteractionResult useOn(net.minecraft.world.item.context.UseOnContext context) {
+ Block itemBlock = this.getBlock();
+ if (context.getPlayer() != null && itemBlock.equals(net.minecraft.world.level.block.Blocks.POTATOES)) {
+ net.minecraft.world.entity.player.Player player = context.getPlayer();
+ net.minecraft.world.level.block.state.BlockState state = context.getLevel().getBlockState(context.getClickedPos());
+ Block block = state.getBlock();
+ me.samsuik.sakura.explosion.durable.DurableMaterial material = context.getLevel().localConfig().config(context.getClickedPos()).durableMaterials.get(block);
+
+ if (material != null) {
+ int durability = context.getLevel().durabilityManager.durability(context.getClickedPos(), material);
+ this.sendPotatoMessage(player, durability, material.durability());
+ }
+ }
+ return super.useOn(context);
+ }
+
+ private void sendPotatoMessage(net.minecraft.world.entity.player.Player player, int remaining, int durability) {
+ player.getBukkitEntity().sendRichMessage(
+ me.samsuik.sakura.configuration.GlobalConfiguration.get().players.potatoMessage,
+ net.kyori.adventure.text.minimessage.tag.resolver.Placeholder.unparsed("remaining", String.valueOf(remaining)),
+ net.kyori.adventure.text.minimessage.tag.resolver.Placeholder.unparsed("durability", String.valueOf(durability))
+ );
+ }
+ // Sakura end - explosion durable blocks
+
@Override
public String getDescriptionId() {
return this.getOrCreateDescriptionId();
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
index 4702f1d07ad32e94aeada46122f84ac68ece9af7..da6f8d2f9b27de6c256920187c9841536842147b 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -144,7 +144,7 @@ public class Explosion {
BlockState blockState = ((ca.spottedleaf.moonrise.patches.chunk_getblock.GetBlockChunk)chunk).moonrise$getBlock(x, y, z);
FluidState fluidState = blockState.getFluidState();
- Optional<Float> resistance = !calculateResistance ? Optional.empty() : this.damageCalculator.getBlockExplosionResistance((Explosion)(Object)this, this.level, pos, blockState, fluidState);
+ Optional<Float> resistance = !calculateResistance ? Optional.empty() : this.calculateBlockResistance(blockState, fluidState, pos); // Sakura - explosion durable blocks
ret = new ca.spottedleaf.moonrise.patches.collisions.ExplosionBlockCache(
key, pos, blockState, fluidState,
@@ -158,6 +158,21 @@ public class Explosion {
return ret;
}
+ // Sakura start - explosion durable blocks
+ private Optional<Float> calculateBlockResistance(BlockState blockState, FluidState fluidState, BlockPos pos) {
+ if (!blockState.isAir()) {
+ Block block = blockState.getBlock();
+ me.samsuik.sakura.explosion.durable.DurableMaterial material = this.level.localConfig().config(pos).durableMaterials.get(block);
+
+ 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 this.damageCalculator.getBlockExplosionResistance((Explosion)(Object)this, this.level, pos, blockState, fluidState);
+ }
+ // Sakura end - explosion durable blocks
+
private boolean clipsAnything(final Vec3 from, final Vec3 to,
final ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.LazyEntityCollisionContext context,
final ca.spottedleaf.moonrise.patches.collisions.ExplosionBlockCache[] blockCache,
@@ -831,6 +846,16 @@ public class Explosion {
// CraftBukkit start - TNTPrimeEvent
BlockState iblockdata = this.level.getBlockState(blockposition);
Block block = iblockdata.getBlock();
+ // Sakura start - explosion durable blocks
+ if (this.level.sakuraConfig().cannons.explosion.allowNonTntBreakingDurableBlocks || this.source instanceof net.minecraft.world.entity.item.PrimedTnt) {
+ me.samsuik.sakura.explosion.durable.DurableMaterial material = this.level.localConfig().config(blockposition).durableMaterials.get(block);
+
+ if (material != null && material.durability() >= 0 && !this.level.durabilityManager.damage(blockposition, material)) {
+ objectlistiterator.remove();
+ continue;
+ }
+ }
+ // Sakura end - explosion durable blocks
if (block instanceof net.minecraft.world.level.block.TntBlock) {
Entity sourceEntity = this.source == null ? null : this.source;
BlockPos sourceBlock = sourceEntity == null ? BlockPos.containing(this.x, this.y, this.z) : null;
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index ec47e7da3c06ee74e0c134e4a881ab373fc68af8..88aa465a4bc6ae79dbad8dc8ecc21345f70abf0b 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -697,6 +697,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
// Paper end - optimise random ticking
public final me.samsuik.sakura.entity.merge.EntityMergeHandler mergeHandler = new me.samsuik.sakura.entity.merge.EntityMergeHandler(); // Sakura - merge cannon entities
public final me.samsuik.sakura.explosion.density.BlockDensityCache densityCache = new me.samsuik.sakura.explosion.density.BlockDensityCache(); // Sakura - explosion density cache
+ public final me.samsuik.sakura.explosion.durable.DurableBlockManager durabilityManager = new me.samsuik.sakura.explosion.durable.DurableBlockManager(); // Sakura - explosion durable blocks
protected Level(WritableLevelData worlddatamutable, ResourceKey<Level> resourcekey, RegistryAccess iregistrycustom, Holder<DimensionType> holder, Supplier<ProfilerFiller> supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env, java.util.function.Function<org.spigotmc.SpigotWorldConfig, io.papermc.paper.configuration.WorldConfiguration> paperWorldConfigCreator, Supplier<me.samsuik.sakura.configuration.WorldConfiguration> sakuraWorldConfigCreator, java.util.concurrent.Executor executor) { // Sakura - sakura configuration files// Paper - create paper world config & Anti-Xray
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot