mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 08:19:26 +00:00
190 lines
10 KiB
Diff
190 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..c58e52f7cc012babf4235e405e5fb5015c6e95d9
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/explosion/durable/DurableBlockManager.java
|
|
@@ -0,0 +1,63 @@
|
|
+package me.samsuik.sakura.explosion.durable;
|
|
+
|
|
+import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
|
+import me.samsuik.sakura.utils.objects.Expiry;
|
|
+import net.minecraft.core.BlockPos;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+
|
|
+public final class DurableBlockManager {
|
|
+
|
|
+ private final Long2ObjectOpenHashMap<DurableBlock> blocks = new Long2ObjectOpenHashMap<>();
|
|
+
|
|
+ public boolean damage(BlockPos pos, DurableMaterial material) {
|
|
+ long packed = pos.asLong();
|
|
+
|
|
+ DurableBlock block = this.blocks.computeIfAbsent(packed, k -> new DurableBlock(
|
|
+ material.durability(),
|
|
+ // expire after 1 minute
|
|
+ new Expiry(MinecraftServer.currentTickLong, 1200)
|
|
+ ));
|
|
+
|
|
+ if (block.damage()) {
|
|
+ this.blocks.remove(packed);
|
|
+ return true;
|
|
+ } else {
|
|
+ block.getExpiry().refresh(MinecraftServer.currentTickLong);
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public int durability(BlockPos pos, DurableMaterial material) {
|
|
+ DurableBlock block = this.blocks.get(pos.asLong());
|
|
+ return block != null ? block.getDurability() : material.durability();
|
|
+ }
|
|
+
|
|
+ public void expire(long tick) {
|
|
+ if (tick % 200 == 0) {
|
|
+ this.blocks.values().removeIf(block -> block.getExpiry().isExpired(tick));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static class DurableBlock {
|
|
+ private int durability;
|
|
+ private final Expiry expiry;
|
|
+
|
|
+ public DurableBlock(int durability, Expiry expiry) {
|
|
+ this.durability = durability;
|
|
+ this.expiry = expiry;
|
|
+ }
|
|
+
|
|
+ public Expiry getExpiry() {
|
|
+ return expiry;
|
|
+ }
|
|
+
|
|
+ public int getDurability() {
|
|
+ return 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 4ee6b6177df48701bd3521e3489797e62a85511f..7a400d332fb4d9df7210fe4efabcc308cf37b296 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1819,6 +1819,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
worldserver.minimalTNT.clear(); // Sakura - visibility api
|
|
worldserver.mergeHistory.expire(currentTickLong); // Sakura - merge cannon entities
|
|
worldserver.densityCache.clear(currentTickLong); // Sakura - explosion density cache
|
|
+ worldserver.durabilityManager.expire(currentTickLong); // 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 546c56d3465ca9c2358f1008d9db96f5fcdd6672..6495c02d089426b8ee3726f072b5d1662af3cdd5 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,
|
|
@@ -840,6 +855,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 ccf8867882f37a55368d2f44a2eddb2c31a20413..70c4ef672dd5a8bcf8c7b011cc3ead2533012d79 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -223,6 +223,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
|
|
private ca.spottedleaf.moonrise.patches.chunk_system.level.entity.EntityLookup entityLookup;
|
|
public final me.samsuik.sakura.entity.merge.MergeHistory mergeHistory = new me.samsuik.sakura.entity.merge.MergeHistory(); // Sakura - cannon entity merging
|
|
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
|
|
|
|
@Override
|
|
public final ca.spottedleaf.moonrise.patches.chunk_system.level.entity.EntityLookup moonrise$getEntityLookup() {
|