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-06-13 22:57:13 +02:00
index cc8825acea0d84b36194313656a6f70d8c049072..7f7445a2b68fd2e6e5fcd509d950a0f8d680c1fe 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-06-13 22:57:13 +02:00
@@ -522,7 +522,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-06-13 22:57:13 +02:00
index e499a5eb843af3e2417bcb31add3c63443c0deff..993538f613e52ecd009f01e7b68fddba76b6a3e8 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()) {
2021-11-24 17:39:04 +01:00
- ((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-06-13 22:57:13 +02:00
index d02f7a547dbe8943f82c07103b1fff203e4533c2..335f43e49d31acecfec8b6da9be9afe88cd95ca9 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-06-13 22:57:13 +02:00
@@ -154,6 +154,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
}
2024-06-13 22:57:13 +02:00
@@ -1086,6 +1092,12 @@ public abstract class BlockBehaviour implements FeatureElement {
2024-04-24 14:11:27 +02:00
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-06-13 22:57:13 +02:00
index bb22b12b05de29bed00e433630c91f233fa9a366..57139a0b8adcd1ea25cd100be78402681856ee75 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-06-13 22:57:13 +02:00
@@ -189,7 +189,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-06-13 22:57:13 +02:00
@@ -199,7 +206,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()) {