use of org.bukkit.event.world.PortalCreateEvent in project Arclight by IzzelAliz.
the class TeleporterMixin_1_15 method createPortal.
public boolean createPortal(Entity entity, BlockPos createPosition, int createRadius) {
boolean flag = true;
double d0 = -1.0;
int i = createPosition.getX();
int j = createPosition.getY();
int k = createPosition.getZ();
int l = i;
int i2 = j;
int j2 = k;
int k2 = 0;
int l2 = this.random.nextInt(4);
BlockPos.Mutable blockposition_mutableblockposition = new BlockPos.Mutable();
for (int i3 = i - createRadius; i3 <= i + createRadius; ++i3) {
double d2 = i3 + 0.5 - createPosition.getX();
for (int j3 = k - createRadius; j3 <= k + createRadius; ++j3) {
double d3 = j3 + 0.5 - createPosition.getZ();
Label_0439: for (int k3 = this.world.getActualHeight() - 1; k3 >= 0; --k3) {
if (this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3, j3))) {
while (k3 > 0 && this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3 - 1, j3))) {
--k3;
}
for (int i4 = l2; i4 < l2 + 4; ++i4) {
int l3 = i4 % 2;
int j4 = 1 - l3;
if (i4 % 4 >= 2) {
l3 = -l3;
j4 = -j4;
}
for (int l4 = 0; l4 < 3; ++l4) {
for (int i5 = 0; i5 < 4; ++i5) {
for (int k4 = -1; k4 < 4; ++k4) {
int k5 = i3 + (i5 - 1) * l3 + l4 * j4;
int j5 = k3 + k4;
int l5 = j3 + (i5 - 1) * j4 - l4 * l3;
blockposition_mutableblockposition.setPos(k5, j5, l5);
if (k4 < 0 && !this.world.getBlockState(blockposition_mutableblockposition).getMaterial().isSolid()) {
continue Label_0439;
}
if (k4 >= 0 && !this.world.isAirBlock(blockposition_mutableblockposition)) {
continue Label_0439;
}
}
}
}
double d4 = k3 + 0.5 - entity.getPosY();
double d5 = d2 * d2 + d4 * d4 + d3 * d3;
if (d0 < 0.0 || d5 < d0) {
d0 = d5;
l = i3;
i2 = k3;
j2 = j3;
k2 = i4 % 4;
}
}
}
}
}
}
if (d0 < 0.0) {
for (int i3 = i - createRadius; i3 <= i + createRadius; ++i3) {
double d2 = i3 + 0.5 - createPosition.getX();
for (int j3 = k - createRadius; j3 <= k + createRadius; ++j3) {
double d3 = j3 + 0.5 - createPosition.getZ();
Label_0812: for (int k3 = this.world.getActualHeight() - 1; k3 >= 0; --k3) {
if (this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3, j3))) {
while (k3 > 0 && this.world.isAirBlock(blockposition_mutableblockposition.setPos(i3, k3 - 1, j3))) {
--k3;
}
for (int i4 = l2; i4 < l2 + 2; ++i4) {
int l3 = i4 % 2;
int j4 = 1 - l3;
for (int l4 = 0; l4 < 4; ++l4) {
for (int i5 = -1; i5 < 4; ++i5) {
int k4 = i3 + (l4 - 1) * l3;
int k5 = k3 + i5;
int j5 = j3 + (l4 - 1) * j4;
blockposition_mutableblockposition.setPos(k4, k5, j5);
if (i5 < 0 && !this.world.getBlockState(blockposition_mutableblockposition).getMaterial().isSolid()) {
continue Label_0812;
}
if (i5 >= 0 && !this.world.isAirBlock(blockposition_mutableblockposition)) {
continue Label_0812;
}
}
}
double d4 = k3 + 0.5 - entity.getPosY();
double d5 = d2 * d2 + d4 * d4 + d3 * d3;
if (d0 < 0.0 || d5 < d0) {
d0 = d5;
l = i3;
i2 = k3;
j2 = j3;
k2 = i4 % 2;
}
}
}
}
}
}
}
int i6 = l;
int j6 = i2;
int j3 = j2;
int k6 = k2 % 2;
int l6 = 1 - k6;
if (k2 % 4 >= 2) {
k6 = -k6;
l6 = -l6;
}
BlockStateListPopulator blockList = new BlockStateListPopulator(this.world);
if (d0 < 0.0) {
i2 = (j6 = MathHelper.clamp(i2, 70, this.world.getActualHeight() - 10));
for (int k3 = -1; k3 <= 1; ++k3) {
for (int i4 = 1; i4 < 3; ++i4) {
for (int l3 = -1; l3 < 3; ++l3) {
int j4 = i6 + (i4 - 1) * k6 + k3 * l6;
int l4 = j6 + l3;
int i5 = j3 + (i4 - 1) * l6 - k3 * k6;
boolean flag2 = l3 < 0;
blockposition_mutableblockposition.setPos(j4, l4, i5);
blockList.setBlockState(blockposition_mutableblockposition, flag2 ? Blocks.OBSIDIAN.getDefaultState() : Blocks.AIR.getDefaultState(), 3);
}
}
}
}
for (int k3 = -1; k3 < 3; ++k3) {
for (int i4 = -1; i4 < 4; ++i4) {
if (k3 == -1 || k3 == 2 || i4 == -1 || i4 == 3) {
blockposition_mutableblockposition.setPos(i6 + k3 * k6, j6 + i4, j3 + k3 * l6);
blockList.setBlockState(blockposition_mutableblockposition, Blocks.OBSIDIAN.getDefaultState(), 3);
}
}
}
BlockState iblockdata = (Blocks.NETHER_PORTAL.getDefaultState()).with(NetherPortalBlock.AXIS, (k6 == 0) ? Direction.Axis.Z : Direction.Axis.X);
for (int i4 = 0; i4 < 2; ++i4) {
for (int l3 = 0; l3 < 3; ++l3) {
blockposition_mutableblockposition.setPos(i6 + i4 * k6, j6 + l3, j3 + i4 * l6);
blockList.setBlockState(blockposition_mutableblockposition, iblockdata, 18);
}
}
org.bukkit.World bworld = ((WorldBridge) this.world).bridge$getWorld();
PortalCreateEvent event = new PortalCreateEvent((List) blockList.getList(), bworld, ((EntityBridge) entity).bridge$getBukkitEntity(), PortalCreateEvent.CreateReason.NETHER_PAIR);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
blockList.updateList();
}
return true;
}
Aggregations