Paper/patches/server/0415-PortalCreateEvent-need...

120 lines
7.2 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mariell Hoversholm <proximyst@proximyst.com>
Date: Fri, 21 Aug 2020 20:57:54 +0200
Subject: [PATCH] PortalCreateEvent needs to know its entity
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
2024-04-30 00:16:07 +02:00
index 91f342912372326a6ced16c23550da7727d6d3ad..b4cb9ff5553995dddfb99b6b3ac1250b92a65d9d 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
2024-04-27 00:08:35 +02:00
@@ -501,7 +501,7 @@ public final class ItemStack implements DataComponentHolder {
2021-06-11 14:02:28 +02:00
net.minecraft.world.level.block.state.BlockState block = world.getBlockState(newblockposition);
if (!(block.getBlock() instanceof BaseEntityBlock)) { // Containers get placed automatically
2024-04-24 14:11:27 +02:00
- block.onPlace(world, newblockposition, oldBlock, true);
+ block.onPlace(world, newblockposition, oldBlock, true, context); // Paper - pass context
2021-06-11 14:02:28 +02:00
}
world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getBlockState(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point
diff --git a/src/main/java/net/minecraft/world/level/block/BaseFireBlock.java b/src/main/java/net/minecraft/world/level/block/BaseFireBlock.java
2024-04-27 08:17:58 +02:00
index 233236733537e036d3a37a3102f3ca6b887d076f..83f48d543eac94276ee4d7f7a4c21abdfa8eb8e6 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/BaseFireBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/BaseFireBlock.java
2024-02-01 10:15:57 +01:00
@@ -144,12 +144,19 @@ public abstract class BaseFireBlock extends Block {
2021-06-11 14:02:28 +02:00
@Override
2024-04-24 14:11:27 +02:00
protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
2024-02-01 10:15:57 +01:00
+ // Paper start - UseOnContext param
+ this.onPlace(state, world, pos, oldState, notify, null);
+ }
+
+ @Override
2024-04-27 08:17:58 +02:00
+ protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify, @javax.annotation.Nullable net.minecraft.world.item.context.UseOnContext context) {
2024-02-01 10:15:57 +01:00
+ // Paper end - UseOnContext param
if (!oldState.is(state.getBlock())) {
2021-06-14 15:45:16 +02:00
if (BaseFireBlock.inPortalDimension(world)) {
2024-02-01 10:15:57 +01:00
Optional<PortalShape> optional = PortalShape.findEmptyPortalShape(world, pos, Direction.Axis.X);
2021-06-11 14:02:28 +02:00
if (optional.isPresent()) {
- ((PortalShape) optional.get()).createPortalBlocks();
2024-02-01 10:15:57 +01:00
+ ((PortalShape) optional.get()).createPortalBlocks(context); // Paper - pass context param
2021-06-11 14:02:28 +02:00
return;
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/FireBlock.java b/src/main/java/net/minecraft/world/level/block/FireBlock.java
2024-04-24 14:11:27 +02:00
index ceaa2a7048afc4955d3695af5291e83a79d83c5d..5dad1aa26a8908cba6a08398a4bad27f31d4c2c0 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/FireBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/FireBlock.java
2024-02-01 10:15:57 +01:00
@@ -368,8 +368,10 @@ public class FireBlock extends BaseFireBlock {
2021-06-11 14:02:28 +02:00
}
@Override
2024-04-24 14:11:27 +02:00
- protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
2021-06-11 14:02:28 +02:00
- super.onPlace(state, world, pos, oldState, notify);
2024-02-01 10:15:57 +01:00
+ // Paper start - UseOnContext param
2024-04-24 14:11:27 +02:00
+ protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify, net.minecraft.world.item.context.UseOnContext context) {
2024-02-01 10:15:57 +01:00
+ super.onPlace(state, world, pos, oldState, notify, context);
2024-04-24 14:11:27 +02:00
+ // Paper end - UseOnContext param
2024-02-01 10:15:57 +01:00
world.scheduleTick(pos, (Block) this, FireBlock.getFireTickDelay(world.random));
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
2024-04-26 05:15:07 +02:00
index 3e76f1baa321f1c2551a027a705bbeed48936e2b..24c2ec8e637373876a00bf292ac9318f79da7aef 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
2024-04-24 14:11:27 +02:00
@@ -155,6 +155,12 @@ public abstract class BlockBehaviour implements FeatureElement {
2021-06-11 14:02:28 +02:00
DebugPackets.sendNeighborsUpdatePacket(world, pos);
}
2024-02-01 10:15:57 +01:00
+ // Paper start - UseOnContext param
2024-04-24 14:11:27 +02:00
+ protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify, net.minecraft.world.item.context.UseOnContext context) {
2024-02-01 10:15:57 +01:00
+ this.onPlace(state, world, pos, oldState, notify);
2021-06-11 14:02:28 +02:00
+ }
2024-02-01 10:15:57 +01:00
+ // Paper end - UseOnContext param
+
2024-04-24 14:11:27 +02:00
protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
org.spigotmc.AsyncCatcher.catchOp("block onPlace"); // Spigot
}
@@ -1080,6 +1086,12 @@ public abstract class BlockBehaviour implements FeatureElement {
this.getBlock().updateIndirectNeighbourShapes(this.asState(), world, pos, flags, maxUpdateDepth);
}
+ // Paper start
+ public void onPlace(Level world, BlockPos pos, BlockState state, boolean notify, net.minecraft.world.item.context.UseOnContext context) {
+ this.getBlock().onPlace(this.asState(), world, pos, state, notify, context);
+ }
+ // Paper end
+
public void onPlace(Level world, BlockPos pos, BlockState state, boolean notify) {
this.getBlock().onPlace(this.asState(), world, pos, state, notify);
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/portal/PortalShape.java b/src/main/java/net/minecraft/world/level/portal/PortalShape.java
2024-04-27 08:17:58 +02:00
index 766884046e2c22da4cb99712ff09d1f439394523..af24467ee37cfc06f692b3b02e68f6cfbaaa8d59 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/portal/PortalShape.java
+++ b/src/main/java/net/minecraft/world/level/portal/PortalShape.java
2024-02-01 10:15:57 +01:00
@@ -190,7 +190,14 @@ public class PortalShape {
2021-06-11 14:02:28 +02:00
}
// CraftBukkit start - return boolean
2024-02-01 10:15:57 +01:00
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper
public boolean createPortalBlocks() {
+ // Paper start - UseOnContext param
+ return this.createPortalBlocks(null);
+ }
+
2024-04-27 08:17:58 +02:00
+ public boolean createPortalBlocks(@Nullable net.minecraft.world.item.context.UseOnContext useOnContext) {
2024-02-01 10:15:57 +01:00
+ // Paper end - UseOnContext param
2021-06-14 15:45:16 +02:00
org.bukkit.World bworld = this.level.getMinecraftWorld().getWorld();
2021-06-11 14:02:28 +02:00
// Copy below for loop
2024-02-01 10:15:57 +01:00
@@ -200,7 +207,7 @@ public class PortalShape {
2021-06-14 15:45:16 +02:00
this.blocks.setBlock(blockposition, iblockdata, 18);
2021-06-11 14:02:28 +02:00
});
2021-06-14 15:45:16 +02:00
- PortalCreateEvent event = new PortalCreateEvent((java.util.List<org.bukkit.block.BlockState>) (java.util.List) this.blocks.getList(), bworld, null, PortalCreateEvent.CreateReason.FIRE);
2024-02-01 10:15:57 +01:00
+ PortalCreateEvent event = new PortalCreateEvent((java.util.List<org.bukkit.block.BlockState>) (java.util.List) blocks.getList(), bworld, useOnContext == null || useOnContext.getPlayer() == null ? null : useOnContext.getPlayer().getBukkitEntity(), PortalCreateEvent.CreateReason.FIRE); // Paper - pass entity param
2021-06-14 15:45:16 +02:00
this.level.getMinecraftWorld().getServer().server.getPluginManager().callEvent(event);
2021-06-11 14:02:28 +02:00
if (event.isCancelled()) {