9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-30 12:19:08 +00:00
Files
SakuraMC/sakura-server/minecraft-patches/features/0015-Explosion-Durable-Blocks.patch
Samsuik 23c775166e Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@c7714bb Update PlayerPostRespawnEvent to include full location data (#13237)
PaperMC/Paper@9d427a5 [ci skip] Enable unpick (#13241)
PaperMC/Paper@13e9c10 [ci skip] Update mache for new unpick definitions
PaperMC/Paper@9934c17 Set chunk loading radius to 0 in PlayerSpawnFinder
2025-10-29 21:26:33 +00:00

103 lines
6.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Wed, 15 Nov 2023 23:18:38 +0000
Subject: [PATCH] Explosion Durable Blocks
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
index 10530a630e4dbb100eef195944dd3bee7a4e70e1..cb10b9bf4951756e55dac55c24dd2ef741058761 100644
--- a/net/minecraft/world/item/BlockItem.java
+++ b/net/minecraft/world/item/BlockItem.java
@@ -37,8 +37,30 @@ public class BlockItem extends Item {
this.block = block;
}
+ // Sakura start - explosion durable blocks
+ private void sendBlockDurabilityToPlayer(final UseOnContext context) {
+ final Player player = context.getPlayer();
+ final Level level = context.getLevel();
+ final BlockPos clickedPos = context.getClickedPos();
+
+ // If the clicked block is a durable material then send the durability to the player
+ final BlockState state = level.getBlockState(clickedPos);
+ final Block clickedBlock = state.getBlock();
+ final me.samsuik.sakura.explosion.durable.DurableMaterial material = level.localConfig().at(clickedPos).durableMaterials.get(clickedBlock);
+
+ if (material != null) {
+ final int remaining = context.getLevel().durabilityManager.durability(clickedPos, material);
+ final int durability = material.durability();
+ player.getBukkitEntity().sendMessage(me.samsuik.sakura.configuration.GlobalConfiguration.get().messages.durableBlockInteractionComponent(remaining, durability));
+ }
+ }
+
@Override
public InteractionResult useOn(UseOnContext context) {
+ if (this.getBlock() == net.minecraft.world.level.block.Blocks.POTATOES && context.getPlayer() != null) {
+ this.sendBlockDurabilityToPlayer(context);
+ }
+ // Sakura end - explosion durable blocks
InteractionResult interactionResult = this.place(new BlockPlaceContext(context));
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 a25303e1b5e590b5f5b0f211fd68482cd8232756..9fe6a8ae7218fa9bdc271353f76ef6a7757d61d5 100644
--- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java
@@ -836,6 +836,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
// Sakura end - track block changes and tick scheduler
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(this); // Sakura - optimise 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 levelData,
diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java
index 301c8846d4c77c450d693ab3b42be476ec07dfcc..a27abc419b5e262223da88c6d6c2418dacf5340e 100644
--- a/net/minecraft/world/level/ServerExplosion.java
+++ b/net/minecraft/world/level/ServerExplosion.java
@@ -133,7 +133,7 @@ public class ServerExplosion implements Explosion {
BlockState blockState = ((ca.spottedleaf.moonrise.patches.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,
@@ -359,6 +359,20 @@ public class ServerExplosion implements Explosion {
}
}
// Sakura end - specialised explosions
+ // Sakura start - explosion durable blocks
+ private Optional<Float> calculateBlockResistance(final BlockState blockState, final FluidState fluidState, final BlockPos pos) {
+ if (!blockState.isAir()) {
+ final Block block = blockState.getBlock();
+ final me.samsuik.sakura.explosion.durable.DurableMaterial material = this.level.localConfig().at(pos).durableMaterials.get(block);
+
+ if (material != null && material.replaceBlastResistance() && pos.getY() > this.level.getMinY()) {
+ return Optional.of(material.resistance());
+ }
+ }
+
+ return this.damageCalculator.getBlockExplosionResistance(this, this.level, pos, blockState, fluidState);
+ }
+ // Sakura end - explosion durable blocks
public ServerExplosion(
ServerLevel level,
@@ -697,6 +711,14 @@ public class ServerExplosion implements Explosion {
}
}
// CraftBukkit end
+ // Sakura start - explosion durable blocks
+ final me.samsuik.sakura.explosion.durable.DurableMaterial material = this.level.localConfig().at(blockPos).durableMaterials.get(block);
+ if (material != null && material.applyDurability()) { // if durability is < 0 then only altar the blast resistance
+ if (material.onlyDamagedByTnt() && !(this.source instanceof PrimedTnt) || !this.level.durabilityManager.damage(blockPos, material)) {
+ continue;
+ }
+ }
+ // Sakura end - explosion durable blocks
this.level
.getBlockState(blockPos)