Paper/patches/server/0235-Add-TNTPrimeEvent.patch
Spottedleaf 01a13871de
Rewrite chunk system (#8177)
Patch documentation to come

Issues with the old system that are fixed now:
- World generation does not scale with cpu cores effectively.
- Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps.
- Unreliable prioritisation of chunk gen/load calls that block the main thread.
- Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved.
- Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal.
- Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles.

The above list is not complete. The patch documentation will complete it.

New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil.

Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft.

The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 01:02:51 -07:00

114 Zeilen
7.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mark Vainomaa <mikroskeem@mikroskeem.eu>
Date: Mon, 16 Jul 2018 00:05:05 +0300
Subject: [PATCH] Add TNTPrimeEvent
diff --git a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
index 1709126f0853edc6bece6f31d7c65a5f8955683a..6495b0421cab1b067b9483cc448222705c15578c 100644
--- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
+++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
@@ -532,6 +532,11 @@ public class EnderDragon extends Mob implements Enemy {
});
craftBlock.getNMS().spawnAfterBreak((ServerLevel) level, blockposition, ItemStack.EMPTY, false);
}
+ // Paper start - TNTPrimeEvent
+ org.bukkit.block.Block tntBlock = level.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ if(!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.EXPLOSION, explosionSource.getSourceMob().getBukkitEntity()).callEvent())
+ continue;
+ // Paper end
nmsBlock.wasExploded(level, blockposition, explosionSource);
this.level.removeBlock(blockposition, false);
diff --git a/src/main/java/net/minecraft/world/level/block/FireBlock.java b/src/main/java/net/minecraft/world/level/block/FireBlock.java
index 037902b3addd34dfc6b751ca225373a06c2d6a89..2188cfc34ab4bd67fac9aedd861a597c137a5c40 100644
--- a/src/main/java/net/minecraft/world/level/block/FireBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/FireBlock.java
@@ -290,12 +290,19 @@ public class FireBlock extends BaseFireBlock {
world.setBlock(blockposition, this.getStateWithAge(world, blockposition, l), 3);
} else {
- world.removeBlock(blockposition, false);
+ if(iblockdata.getBlock() != Blocks.TNT) world.removeBlock(blockposition, false); // Paper - TNTPrimeEvent - We might be cancelling it below, move the setAir down
}
Block block = iblockdata.getBlock();
if (block instanceof TntBlock) {
+ // Paper start - TNTPrimeEvent
+ org.bukkit.block.Block tntBlock = net.minecraft.server.MCUtil.toBukkitBlock(world, blockposition);
+ if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.FIRE, null).callEvent()) {
+ return;
+ }
+ world.removeBlock(blockposition, false);
+ // Paper end
TntBlock.explode(world, blockposition);
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/TntBlock.java b/src/main/java/net/minecraft/world/level/block/TntBlock.java
index 9fcad0eb55a4a91a89ab8bce1f22d91127a94fb2..355448a08cca780f4f0b95e2abcdc87eb61de6dc 100644
--- a/src/main/java/net/minecraft/world/level/block/TntBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/TntBlock.java
@@ -38,6 +38,11 @@ public class TntBlock extends Block {
public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
if (!oldState.is(state.getBlock())) {
if (world.hasNeighborSignal(pos)) {
+ // Paper start - TNTPrimeEvent
+ org.bukkit.block.Block tntBlock = net.minecraft.server.MCUtil.toBukkitBlock(world, pos);;
+ if(!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.REDSTONE, null).callEvent())
+ return;
+ // Paper end
TntBlock.explode(world, pos);
world.removeBlock(pos, false);
}
@@ -48,6 +53,11 @@ public class TntBlock extends Block {
@Override
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
if (world.hasNeighborSignal(pos)) {
+ // Paper start - TNTPrimeEvent
+ org.bukkit.block.Block tntBlock = net.minecraft.server.MCUtil.toBukkitBlock(world, pos);;
+ if(!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.REDSTONE, null).callEvent())
+ return;
+ // Paper end
TntBlock.explode(world, pos);
world.removeBlock(pos, false);
}
@@ -66,6 +76,12 @@ public class TntBlock extends Block {
@Override
public void wasExploded(Level world, BlockPos pos, Explosion explosion) {
if (!world.isClientSide) {
+ // Paper start - TNTPrimeEvent
+ org.bukkit.block.Block tntBlock = net.minecraft.server.MCUtil.toBukkitBlock(world, pos);
+ org.bukkit.entity.Entity source = explosion.source != null ? explosion.source.getBukkitEntity() : null;
+ if(!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.EXPLOSION, source).callEvent())
+ return;
+ // Paper end
PrimedTnt entitytntprimed = new PrimedTnt(world, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, explosion.getSourceMob());
int i = entitytntprimed.getFuse();
@@ -95,6 +111,11 @@ public class TntBlock extends Block {
if (!itemstack.is(Items.FLINT_AND_STEEL) && !itemstack.is(Items.FIRE_CHARGE)) {
return super.use(state, world, pos, player, hand, hit);
} else {
+ // Paper start - TNTPrimeEvent
+ org.bukkit.block.Block tntBlock = net.minecraft.server.MCUtil.toBukkitBlock(world, pos);
+ if(!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.ITEM, player.getBukkitEntity()).callEvent())
+ return InteractionResult.FAIL;
+ // Paper end
TntBlock.explode(world, pos, player);
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 11);
Item item = itemstack.getItem();
@@ -126,6 +147,12 @@ public class TntBlock extends Block {
return;
}
// CraftBukkit end
+ // Paper start - TNTPrimeEvent
+ org.bukkit.block.Block tntBlock = net.minecraft.server.MCUtil.toBukkitBlock(world, blockposition);
+ if (!new com.destroystokyo.paper.event.block.TNTPrimeEvent(tntBlock, com.destroystokyo.paper.event.block.TNTPrimeEvent.PrimeReason.PROJECTILE, projectile.getBukkitEntity()).callEvent()) {
+ return;
+ }
+ // Paper end
TntBlock.explode(world, blockposition, entity instanceof LivingEntity ? (LivingEntity) entity : null);
world.removeBlock(blockposition, false);
}