9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2026-01-04 15:31:43 +00:00
Files
SakuraMC/sakura-server/minecraft-patches/features/0015-Explosion-Durable-Blocks.patch

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 6db566adf2d0df1d26221eda04aa01738df6d3d2..23c135a6355e920535734e946e5bd4d06f7f33b7 100644
--- a/net/minecraft/world/item/BlockItem.java
+++ b/net/minecraft/world/item/BlockItem.java
@@ -38,8 +38,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 7a922d26952be2f19161053542fa3a4b1a3bdf80..68cc49c65c3098f0aeb2d6dfbe75262e1fff1681 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<Entity>, AutoCl
// 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(); // 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 levelData,
diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java
index dfe4058155a83ec213a37553996d2dbb9744881b..7f57531254031f7134fc6d72a5077aab5b48c7f0 100644
--- a/net/minecraft/world/level/ServerExplosion.java
+++ b/net/minecraft/world/level/ServerExplosion.java
@@ -131,7 +131,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,
@@ -390,6 +390,20 @@ public class ServerExplosion implements Explosion {
// Paper end - collision optimisations
}
// 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,
@@ -770,6 +784,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)