Paper/nms-patches/BlockPortal.patch

140 Zeilen
6.1 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/BlockPortal.java
+++ b/net/minecraft/server/BlockPortal.java
@@ -4,6 +4,13 @@
import java.util.Random;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
2018-07-15 02:00:00 +02:00
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.block.CraftBlockState;
2018-07-15 02:00:00 +02:00
+import org.bukkit.event.entity.EntityPortalEnterEvent;
+import org.bukkit.event.world.PortalCreateEvent;
+// CraftBukkit end
+
2018-07-15 02:00:00 +02:00
public class BlockPortal extends Block {
2020-06-25 02:00:00 +02:00
public static final BlockStateEnum<EnumDirection.EnumAxis> AXIS = BlockProperties.E;
@@ -34,7 +41,8 @@
}
2020-06-25 02:00:00 +02:00
if (worldserver.getType(blockposition).a((IBlockAccess) worldserver, blockposition, EntityTypes.ZOMBIFIED_PIGLIN)) {
- Entity entity = EntityTypes.ZOMBIFIED_PIGLIN.spawnCreature(worldserver, (NBTTagCompound) null, (IChatBaseComponent) null, (EntityHuman) null, blockposition.up(), EnumMobSpawn.STRUCTURE, false, false);
+ // CraftBukkit - set spawn reason to NETHER_PORTAL
2020-06-25 02:00:00 +02:00
+ Entity entity = EntityTypes.ZOMBIFIED_PIGLIN.spawnCreature(worldserver, (NBTTagCompound) null, (IChatBaseComponent) null, (EntityHuman) null, blockposition.up(), EnumMobSpawn.STRUCTURE, false, false, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NETHER_PORTAL);
if (entity != null) {
2020-06-25 02:00:00 +02:00
entity.portalCooldown = entity.getDefaultPortalCooldown();
@@ -48,8 +56,10 @@
2020-06-25 02:00:00 +02:00
BlockPortal.Shape blockportal_shape = b(generatoraccess, blockposition);
2018-07-15 02:00:00 +02:00
if (blockportal_shape != null) {
2015-07-30 08:56:52 +02:00
- blockportal_shape.createPortal();
- return true;
+ // CraftBukkit start - return portalcreator
2015-07-30 08:56:52 +02:00
+ return blockportal_shape.createPortal();
+ // return true;
2018-07-15 02:00:00 +02:00
+ // CraftBukkit end
} else {
2018-07-15 02:00:00 +02:00
return false;
}
2019-12-10 23:00:00 +01:00
@@ -80,6 +90,10 @@
2019-04-23 04:00:00 +02:00
@Override
2018-07-15 02:00:00 +02:00
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
2019-04-23 04:00:00 +02:00
if (!entity.isPassenger() && !entity.isVehicle() && entity.canPortal()) {
+ // CraftBukkit start - Entity in portal
+ EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ world.getServer().getPluginManager().callEvent(event);
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
entity.d(blockposition);
2015-02-26 23:41:06 +01:00
}
2019-12-10 23:00:00 +01:00
@@ -172,6 +186,7 @@
2015-07-30 08:56:52 +02:00
private BlockPosition position;
private int height;
private int width;
+ java.util.List<org.bukkit.block.BlockState> blocks = new java.util.ArrayList<org.bukkit.block.BlockState>(); // CraftBukkit - add field
2015-02-26 23:41:06 +01:00
2018-07-15 02:00:00 +02:00
public Shape(GeneratorAccess generatoraccess, BlockPosition blockposition, EnumDirection.EnumAxis enumdirection_enumaxis) {
this.a = generatoraccess;
2020-06-25 02:00:00 +02:00
@@ -228,6 +243,9 @@
2015-02-26 23:41:06 +01:00
}
protected int c() {
+ // CraftBukkit start
+ this.blocks.clear();
+ // CraftBukkit end
int i;
label56:
2020-06-25 02:00:00 +02:00
@@ -247,9 +265,19 @@
if (i == 0) {
if (!this.a.getType(blockposition.shift(this.d)).a(Blocks.OBSIDIAN)) {
2015-02-26 23:41:06 +01:00
break label56;
+ // CraftBukkit start - add the block to our list
+ } else {
+ BlockPosition pos = blockposition.shift(this.d);
+ blocks.add(CraftBlock.at(this.a, pos).getState());
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
}
2020-06-25 02:00:00 +02:00
} else if (i == this.width - 1 && !this.a.getType(blockposition.shift(this.c)).a(Blocks.OBSIDIAN)) {
break label56;
+ // CraftBukkit start - add the block to our list
+ } else {
+ BlockPosition pos = blockposition.shift(this.c);
+ blocks.add(CraftBlock.at(this.a, pos).getState());
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
}
}
2020-06-25 02:00:00 +02:00
}
@@ -258,6 +286,11 @@
if (!this.a.getType(this.position.shift(this.c, i).up(this.height)).a(Blocks.OBSIDIAN)) {
2015-07-30 08:56:52 +02:00
this.height = 0;
2015-02-26 23:41:06 +01:00
break;
+ // CraftBukkit start - add the block to our list
+ } else {
2015-07-30 08:56:52 +02:00
+ BlockPosition pos = this.position.shift(this.c, i).up(this.height);
+ blocks.add(CraftBlock.at(this.a, pos).getState());
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
}
}
2020-06-25 02:00:00 +02:00
@@ -279,7 +312,29 @@
2015-07-30 08:56:52 +02:00
return this.position != null && this.width >= 2 && this.width <= 21 && this.height >= 3 && this.height <= 21;
}
2015-07-30 08:56:52 +02:00
- public void createPortal() {
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - return boolean
2015-07-30 08:56:52 +02:00
+ public boolean createPortal() {
2018-07-15 02:00:00 +02:00
+ org.bukkit.World bworld = this.a.getMinecraftWorld().getWorld();
2015-02-26 23:41:06 +01:00
+
+ // Copy below for loop
2015-07-30 08:56:52 +02:00
+ for (int i = 0; i < this.width; ++i) {
+ BlockPosition blockposition = this.position.shift(this.c, i);
2015-02-26 23:41:06 +01:00
+
2015-07-30 08:56:52 +02:00
+ for (int j = 0; j < this.height; ++j) {
2015-02-26 23:41:06 +01:00
+ BlockPosition pos = blockposition.up(j);
+ CraftBlockState state = CraftBlockState.getBlockState(this.a.getMinecraftWorld(), pos, 18);
+ state.setData((IBlockData) Blocks.NETHER_PORTAL.getBlockData().set(BlockPortal.AXIS, this.b));
+ blocks.add(state);
2015-02-26 23:41:06 +01:00
+ }
+ }
+
+ PortalCreateEvent event = new PortalCreateEvent(blocks, bworld, null, PortalCreateEvent.CreateReason.FIRE);
2018-07-15 02:00:00 +02:00
+ this.a.getMinecraftWorld().getMinecraftServer().server.getPluginManager().callEvent(event);
2015-02-26 23:41:06 +01:00
+
+ if (event.isCancelled()) {
+ return false;
+ }
+ // CraftBukkit end
2015-07-30 08:56:52 +02:00
for (int i = 0; i < this.width; ++i) {
BlockPosition blockposition = this.position.shift(this.c, i);
2015-02-26 23:41:06 +01:00
2020-06-25 02:00:00 +02:00
@@ -288,6 +343,7 @@
2015-02-26 23:41:06 +01:00
}
}
+ return true; // CraftBukkit
}
2018-07-15 02:00:00 +02:00
private boolean g() {