Paper/nms-patches/BlockPortal.patch

142 lines
6.3 KiB
Diff
Raw Normal View History

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 {
2019-04-23 04:00:00 +02:00
public static final BlockStateEnum<EnumDirection.EnumAxis> AXIS = BlockProperties.D;
@@ -34,7 +41,8 @@
}
2019-12-10 23:00:00 +01:00
if (worldserver.getType(blockposition).a((IBlockAccess) worldserver, blockposition, EntityTypes.ZOMBIE_PIGMAN)) {
- Entity entity = EntityTypes.ZOMBIE_PIGMAN.spawnCreature(worldserver, (NBTTagCompound) null, (IChatBaseComponent) null, (EntityHuman) null, blockposition.up(), EnumMobSpawn.STRUCTURE, false, false);
+ // CraftBukkit - set spawn reason to NETHER_PORTAL
2019-12-10 23:00:00 +01:00
+ Entity entity = EntityTypes.ZOMBIE_PIGMAN.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) {
2019-12-10 23:00:00 +01:00
entity.portalCooldown = entity.ba();
@@ -48,8 +56,10 @@
2018-07-15 02:00:00 +02:00
BlockPortal.Shape blockportal_shape = this.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
2019-04-23 04:00:00 +02:00
entity.c(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;
2019-12-10 23:00:00 +01:00
@@ -230,6 +245,9 @@
2015-02-26 23:41:06 +01:00
}
protected int c() {
+ // CraftBukkit start
+ this.blocks.clear();
+ // CraftBukkit end
int i;
label56:
2019-12-10 23:00:00 +01:00
@@ -252,11 +270,21 @@
2015-02-26 23:41:06 +01:00
block = this.a.getType(blockposition.shift(this.d)).getBlock();
if (block != Blocks.OBSIDIAN) {
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
}
2015-07-30 08:56:52 +02:00
} else if (i == this.width - 1) {
2015-02-26 23:41:06 +01:00
block = this.a.getType(blockposition.shift(this.c)).getBlock();
if (block != 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());
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
}
}
}
2019-12-10 23:00:00 +01:00
@@ -266,6 +294,11 @@
2015-07-30 08:56:52 +02:00
if (this.a.getType(this.position.shift(this.c, i).up(this.height)).getBlock() != Blocks.OBSIDIAN) {
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
}
}
2019-12-10 23:00:00 +01:00
@@ -289,7 +322,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
2019-12-10 23:00:00 +01:00
@@ -298,6 +353,7 @@
2015-02-26 23:41:06 +01:00
}
}
+ return true; // CraftBukkit
}
2018-07-15 02:00:00 +02:00
private boolean g() {