From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Samsuik 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 cc363ba3bc719d8b93992141d779b4c1d1bbd2fb..cdcaf954cec280970f29ac11db906457f18190c6 100644 --- a/net/minecraft/world/item/BlockItem.java +++ b/net/minecraft/world/item/BlockItem.java @@ -38,8 +38,31 @@ public class BlockItem extends Item { this.block = block; } + // Sakura start - explosion durable blocks + private void sendBlockDurabilityToPlayer(UseOnContext context) { + Player player = context.getPlayer(); + 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 remaining = context.getLevel().durabilityManager.durability(context.getClickedPos(), material); + int durability = material.durability(); + + player.getBukkitEntity().sendRichMessage( + me.samsuik.sakura.configuration.GlobalConfiguration.get().messages.durableBlockInteraction, + 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)) + ); + } + } + @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 c7a5d369e9889353242d8a70772b2c45684a6951..54d97a271e6a500f5e4ca74bcecbb0f8a1fd1ae2 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 // 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 9f0dcaf0db44925c35fa46fdb2de83540ee959c4..48d98bac0140cec91fe2c9e7bb72a6f05a70aa49 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 resistance = !calculateResistance ? Optional.empty() : this.damageCalculator.getBlockExplosionResistance((Explosion)(Object)this, this.level, pos, blockState, fluidState); + Optional 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 calculateBlockResistance(BlockState blockState, FluidState fluidState, BlockPos pos) { + if (!blockState.isAir()) { + 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)) { + return Optional.of(material.resistance()); + } + } + + return this.damageCalculator.getBlockExplosionResistance(this, this.level, pos, blockState, fluidState); + } + // Sakura end - explosion durable blocks public ServerExplosion( ServerLevel level, @@ -767,6 +781,14 @@ public class ServerExplosion implements Explosion { } } // 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)) { + continue; + } + } + // Sakura end - explosion durable blocks this.level .getBlockState(blockPos)