--- a/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
@@ -1,6 +1,7 @@
 package net.minecraft.world.level.block.entity;
 
 import com.mojang.logging.LogUtils;
+import java.util.Iterator;
 import javax.annotation.Nullable;
 import net.minecraft.core.BlockPos;
 import net.minecraft.core.Direction;
@@ -20,12 +21,15 @@
 import net.minecraft.world.level.block.Blocks;
 import net.minecraft.world.level.block.state.BlockState;
 import net.minecraft.world.level.chunk.LevelChunk;
+import net.minecraft.world.level.dimension.LevelStem;
+import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
 import net.minecraft.world.level.levelgen.feature.Feature;
 import net.minecraft.world.level.levelgen.feature.configurations.EndGatewayConfiguration;
 import net.minecraft.world.phys.Vec3;
 import org.slf4j.Logger;
 
 public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity {
+
     private static final Logger LOGGER = LogUtils.getLogger();
     private static final int SPAWN_TIME = 200;
     private static final int COOLDOWN_TIME = 40;
@@ -53,36 +57,42 @@
         if (this.exactTeleport) {
             nbt.putBoolean("ExactTeleport", true);
         }
+
     }
 
     @Override
     protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registryLookup) {
         super.loadAdditional(nbt, registryLookup);
         this.age = nbt.getLong("Age");
-        NbtUtils.readBlockPos(nbt, "exit_portal").filter(Level::isInSpawnableBounds).ifPresent(exitPortalPos -> this.exitPortal = exitPortalPos);
+        NbtUtils.readBlockPos(nbt, "exit_portal").filter(Level::isInSpawnableBounds).ifPresent((blockposition) -> {
+            this.exitPortal = blockposition;
+        });
         this.exactTeleport = nbt.getBoolean("ExactTeleport");
     }
 
     public static void beamAnimationTick(Level world, BlockPos pos, BlockState state, TheEndGatewayBlockEntity blockEntity) {
-        blockEntity.age++;
+        ++blockEntity.age;
         if (blockEntity.isCoolingDown()) {
-            blockEntity.teleportCooldown--;
+            --blockEntity.teleportCooldown;
         }
+
     }
 
     public static void portalTick(Level world, BlockPos pos, BlockState state, TheEndGatewayBlockEntity blockEntity) {
-        boolean bl = blockEntity.isSpawning();
-        boolean bl2 = blockEntity.isCoolingDown();
-        blockEntity.age++;
-        if (bl2) {
-            blockEntity.teleportCooldown--;
+        boolean flag = blockEntity.isSpawning();
+        boolean flag1 = blockEntity.isCoolingDown();
+
+        ++blockEntity.age;
+        if (flag1) {
+            --blockEntity.teleportCooldown;
         } else if (blockEntity.age % 2400L == 0L) {
-            triggerCooldown(world, pos, state, blockEntity);
+            TheEndGatewayBlockEntity.triggerCooldown(world, pos, state, blockEntity);
         }
 
-        if (bl != blockEntity.isSpawning() || bl2 != blockEntity.isCoolingDown()) {
+        if (flag != blockEntity.isSpawning() || flag1 != blockEntity.isCoolingDown()) {
             setChanged(world, pos, state);
         }
+
     }
 
     public boolean isSpawning() {
@@ -94,11 +104,11 @@
     }
 
     public float getSpawnPercent(float tickDelta) {
-        return Mth.clamp(((float)this.age + tickDelta) / 200.0F, 0.0F, 1.0F);
+        return Mth.clamp(((float) this.age + tickDelta) / 200.0F, 0.0F, 1.0F);
     }
 
     public float getCooldownPercent(float tickDelta) {
-        return 1.0F - Mth.clamp(((float)this.teleportCooldown - tickDelta) / 40.0F, 0.0F, 1.0F);
+        return 1.0F - Mth.clamp(((float) this.teleportCooldown - tickDelta) / 40.0F, 0.0F, 1.0F);
     }
 
     @Override
@@ -117,6 +127,7 @@
             world.blockEvent(pos, state.getBlock(), 1, 0);
             setChanged(world, pos, state);
         }
+
     }
 
     @Override
@@ -131,81 +142,88 @@
 
     @Nullable
     public Vec3 getPortalPosition(ServerLevel world, BlockPos pos) {
-        if (this.exitPortal == null && world.dimension() == Level.END) {
-            BlockPos blockPos = findOrCreateValidTeleportPos(world, pos);
-            blockPos = blockPos.above(10);
-            LOGGER.debug("Creating portal at {}", blockPos);
-            spawnGatewayPortal(world, blockPos, EndGatewayConfiguration.knownExit(pos, false));
-            this.setExitPosition(blockPos, this.exactTeleport);
+        BlockPos blockposition1;
+
+        if (this.exitPortal == null && world.getTypeKey() == LevelStem.END) { // CraftBukkit - work in alternate worlds
+            blockposition1 = TheEndGatewayBlockEntity.findOrCreateValidTeleportPos(world, pos);
+            blockposition1 = blockposition1.above(10);
+            TheEndGatewayBlockEntity.LOGGER.debug("Creating portal at {}", blockposition1);
+            TheEndGatewayBlockEntity.spawnGatewayPortal(world, blockposition1, EndGatewayConfiguration.knownExit(pos, false));
+            this.setExitPosition(blockposition1, this.exactTeleport);
         }
 
         if (this.exitPortal != null) {
-            BlockPos blockPos2 = this.exactTeleport ? this.exitPortal : findExitPosition(world, this.exitPortal);
-            return blockPos2.getBottomCenter();
+            blockposition1 = this.exactTeleport ? this.exitPortal : TheEndGatewayBlockEntity.findExitPosition(world, this.exitPortal);
+            return blockposition1.getBottomCenter();
         } else {
             return null;
         }
     }
 
     private static BlockPos findExitPosition(Level world, BlockPos pos) {
-        BlockPos blockPos = findTallestBlock(world, pos.offset(0, 2, 0), 5, false);
-        LOGGER.debug("Best exit position for portal at {} is {}", pos, blockPos);
-        return blockPos.above();
+        BlockPos blockposition1 = TheEndGatewayBlockEntity.findTallestBlock(world, pos.offset(0, 2, 0), 5, false);
+
+        TheEndGatewayBlockEntity.LOGGER.debug("Best exit position for portal at {} is {}", pos, blockposition1);
+        return blockposition1.above();
     }
 
     private static BlockPos findOrCreateValidTeleportPos(ServerLevel world, BlockPos pos) {
-        Vec3 vec3 = findExitPortalXZPosTentative(world, pos);
-        LevelChunk levelChunk = getChunk(world, vec3);
-        BlockPos blockPos = findValidSpawnInChunk(levelChunk);
-        if (blockPos == null) {
-            BlockPos blockPos2 = BlockPos.containing(vec3.x + 0.5, 75.0, vec3.z + 0.5);
-            LOGGER.debug("Failed to find a suitable block to teleport to, spawning an island on {}", blockPos2);
-            world.registryAccess()
-                .registry(Registries.CONFIGURED_FEATURE)
-                .flatMap(registry -> registry.getHolder(EndFeatures.END_ISLAND))
-                .ifPresent(
-                    reference -> reference.value().place(world, world.getChunkSource().getGenerator(), RandomSource.create(blockPos2.asLong()), blockPos2)
-                );
-            blockPos = blockPos2;
+        Vec3 vec3d = TheEndGatewayBlockEntity.findExitPortalXZPosTentative(world, pos);
+        LevelChunk chunk = TheEndGatewayBlockEntity.getChunk(world, vec3d);
+        BlockPos blockposition1 = TheEndGatewayBlockEntity.findValidSpawnInChunk(chunk);
+
+        if (blockposition1 == null) {
+            BlockPos blockposition2 = BlockPos.containing(vec3d.x + 0.5D, 75.0D, vec3d.z + 0.5D);
+
+            TheEndGatewayBlockEntity.LOGGER.debug("Failed to find a suitable block to teleport to, spawning an island on {}", blockposition2);
+            world.registryAccess().registry(Registries.CONFIGURED_FEATURE).flatMap((iregistry) -> {
+                return iregistry.getHolder(EndFeatures.END_ISLAND);
+            }).ifPresent((holder_c) -> {
+                ((ConfiguredFeature) holder_c.value()).place(world, world.getChunkSource().getGenerator(), RandomSource.create(blockposition2.asLong()), blockposition2);
+            });
+            blockposition1 = blockposition2;
         } else {
-            LOGGER.debug("Found suitable block to teleport to: {}", blockPos);
+            TheEndGatewayBlockEntity.LOGGER.debug("Found suitable block to teleport to: {}", blockposition1);
         }
 
-        return findTallestBlock(world, blockPos, 16, true);
+        return TheEndGatewayBlockEntity.findTallestBlock(world, blockposition1, 16, true);
     }
 
     private static Vec3 findExitPortalXZPosTentative(ServerLevel world, BlockPos pos) {
-        Vec3 vec3 = new Vec3((double)pos.getX(), 0.0, (double)pos.getZ()).normalize();
-        int i = 1024;
-        Vec3 vec32 = vec3.scale(1024.0);
+        Vec3 vec3d = (new Vec3((double) pos.getX(), 0.0D, (double) pos.getZ())).normalize();
+        boolean flag = true;
+        Vec3 vec3d1 = vec3d.scale(1024.0D);
 
-        for (int j = 16; !isChunkEmpty(world, vec32) && j-- > 0; vec32 = vec32.add(vec3.scale(-16.0))) {
-            LOGGER.debug("Skipping backwards past nonempty chunk at {}", vec32);
+        int i;
+
+        for (i = 16; !TheEndGatewayBlockEntity.isChunkEmpty(world, vec3d1) && i-- > 0; vec3d1 = vec3d1.add(vec3d.scale(-16.0D))) {
+            TheEndGatewayBlockEntity.LOGGER.debug("Skipping backwards past nonempty chunk at {}", vec3d1);
         }
 
-        for (int var6 = 16; isChunkEmpty(world, vec32) && var6-- > 0; vec32 = vec32.add(vec3.scale(16.0))) {
-            LOGGER.debug("Skipping forward past empty chunk at {}", vec32);
+        for (i = 16; TheEndGatewayBlockEntity.isChunkEmpty(world, vec3d1) && i-- > 0; vec3d1 = vec3d1.add(vec3d.scale(16.0D))) {
+            TheEndGatewayBlockEntity.LOGGER.debug("Skipping forward past empty chunk at {}", vec3d1);
         }
 
-        LOGGER.debug("Found chunk at {}", vec32);
-        return vec32;
+        TheEndGatewayBlockEntity.LOGGER.debug("Found chunk at {}", vec3d1);
+        return vec3d1;
     }
 
     private static boolean isChunkEmpty(ServerLevel world, Vec3 pos) {
-        return getChunk(world, pos).getHighestFilledSectionIndex() == -1;
+        return TheEndGatewayBlockEntity.getChunk(world, pos).getHighestFilledSectionIndex() == -1;
     }
 
     private static BlockPos findTallestBlock(BlockGetter world, BlockPos pos, int searchRadius, boolean force) {
-        BlockPos blockPos = null;
+        BlockPos blockposition1 = null;
 
-        for (int i = -searchRadius; i <= searchRadius; i++) {
-            for (int j = -searchRadius; j <= searchRadius; j++) {
-                if (i != 0 || j != 0 || force) {
-                    for (int k = world.getMaxBuildHeight() - 1; k > (blockPos == null ? world.getMinBuildHeight() : blockPos.getY()); k--) {
-                        BlockPos blockPos2 = new BlockPos(pos.getX() + i, k, pos.getZ() + j);
-                        BlockState blockState = world.getBlockState(blockPos2);
-                        if (blockState.isCollisionShapeFullBlock(world, blockPos2) && (force || !blockState.is(Blocks.BEDROCK))) {
-                            blockPos = blockPos2;
+        for (int j = -searchRadius; j <= searchRadius; ++j) {
+            for (int k = -searchRadius; k <= searchRadius; ++k) {
+                if (j != 0 || k != 0 || force) {
+                    for (int l = world.getMaxBuildHeight() - 1; l > (blockposition1 == null ? world.getMinBuildHeight() : blockposition1.getY()); --l) {
+                        BlockPos blockposition2 = new BlockPos(pos.getX() + j, l, pos.getZ() + k);
+                        BlockState iblockdata = world.getBlockState(blockposition2);
+
+                        if (iblockdata.isCollisionShapeFullBlock(world, blockposition2) && (force || !iblockdata.is(Blocks.BEDROCK))) {
+                            blockposition1 = blockposition2;
                             break;
                         }
                     }
@@ -213,38 +231,40 @@
             }
         }
 
-        return blockPos == null ? pos : blockPos;
+        return blockposition1 == null ? pos : blockposition1;
     }
 
     private static LevelChunk getChunk(Level world, Vec3 pos) {
-        return world.getChunk(Mth.floor(pos.x / 16.0), Mth.floor(pos.z / 16.0));
+        return world.getChunk(Mth.floor(pos.x / 16.0D), Mth.floor(pos.z / 16.0D));
     }
 
     @Nullable
     private static BlockPos findValidSpawnInChunk(LevelChunk chunk) {
-        ChunkPos chunkPos = chunk.getPos();
-        BlockPos blockPos = new BlockPos(chunkPos.getMinBlockX(), 30, chunkPos.getMinBlockZ());
+        ChunkPos chunkcoordintpair = chunk.getPos();
+        BlockPos blockposition = new BlockPos(chunkcoordintpair.getMinBlockX(), 30, chunkcoordintpair.getMinBlockZ());
         int i = chunk.getHighestSectionPosition() + 16 - 1;
-        BlockPos blockPos2 = new BlockPos(chunkPos.getMaxBlockX(), i, chunkPos.getMaxBlockZ());
-        BlockPos blockPos3 = null;
-        double d = 0.0;
+        BlockPos blockposition1 = new BlockPos(chunkcoordintpair.getMaxBlockX(), i, chunkcoordintpair.getMaxBlockZ());
+        BlockPos blockposition2 = null;
+        double d0 = 0.0D;
+        Iterator iterator = BlockPos.betweenClosed(blockposition, blockposition1).iterator();
 
-        for (BlockPos blockPos4 : BlockPos.betweenClosed(blockPos, blockPos2)) {
-            BlockState blockState = chunk.getBlockState(blockPos4);
-            BlockPos blockPos5 = blockPos4.above();
-            BlockPos blockPos6 = blockPos4.above(2);
-            if (blockState.is(Blocks.END_STONE)
-                && !chunk.getBlockState(blockPos5).isCollisionShapeFullBlock(chunk, blockPos5)
-                && !chunk.getBlockState(blockPos6).isCollisionShapeFullBlock(chunk, blockPos6)) {
-                double e = blockPos4.distToCenterSqr(0.0, 0.0, 0.0);
-                if (blockPos3 == null || e < d) {
-                    blockPos3 = blockPos4;
-                    d = e;
+        while (iterator.hasNext()) {
+            BlockPos blockposition3 = (BlockPos) iterator.next();
+            BlockState iblockdata = chunk.getBlockState(blockposition3);
+            BlockPos blockposition4 = blockposition3.above();
+            BlockPos blockposition5 = blockposition3.above(2);
+
+            if (iblockdata.is(Blocks.END_STONE) && !chunk.getBlockState(blockposition4).isCollisionShapeFullBlock(chunk, blockposition4) && !chunk.getBlockState(blockposition5).isCollisionShapeFullBlock(chunk, blockposition5)) {
+                double d1 = blockposition3.distToCenterSqr(0.0D, 0.0D, 0.0D);
+
+                if (blockposition2 == null || d1 < d0) {
+                    blockposition2 = blockposition3;
+                    d0 = d1;
                 }
             }
         }
 
-        return blockPos3;
+        return blockposition2;
     }
 
     private static void spawnGatewayPortal(ServerLevel world, BlockPos pos, EndGatewayConfiguration config) {
@@ -258,9 +278,13 @@
 
     public int getParticleAmount() {
         int i = 0;
+        Direction[] aenumdirection = Direction.values();
+        int j = aenumdirection.length;
 
-        for (Direction direction : Direction.values()) {
-            i += this.shouldRenderFace(direction) ? 1 : 0;
+        for (int k = 0; k < j; ++k) {
+            Direction enumdirection = aenumdirection[k];
+
+            i += this.shouldRenderFace(enumdirection) ? 1 : 0;
         }
 
         return i;
