From 00f50a50269e2c4857cbbae79f62284ea1a423fa Mon Sep 17 00:00:00 2001 From: ProfMobius Date: Sun, 23 Mar 2014 02:15:27 +0100 Subject: [PATCH] Move target determination and fix from EntityManager to Teleport. --- .../opis/data/managers/EntityManager.java | 91 +----------------- mcp/mobius/opis/helpers/Teleport.java | 95 +++++++++++++++++++ 2 files changed, 99 insertions(+), 87 deletions(-) diff --git a/mcp/mobius/opis/data/managers/EntityManager.java b/mcp/mobius/opis/data/managers/EntityManager.java index d58dd70..a8e9626 100644 --- a/mcp/mobius/opis/data/managers/EntityManager.java +++ b/mcp/mobius/opis/data/managers/EntityManager.java @@ -193,100 +193,17 @@ public class EntityManager { return cumData; } - public static CoordinatesBlock getTeleportTarget(CoordinatesBlock coord){ - World world = DimensionManager.getWorld(coord.dim); - if (world == null) {return null;} - - int maxOffset = 16; - boolean targetFound = false; - - if (coord.y > 0){ - for (int xoffset = 0; xoffset <= maxOffset; xoffset++){ - for (int zoffset = 0; zoffset <= maxOffset; zoffset++){ - if ( world.isAirBlock(coord.x + xoffset, coord.y, coord.z + zoffset) && - world.isAirBlock(coord.x + xoffset, coord.y + 1, coord.z + zoffset) && - !world.isAirBlock(coord.x + xoffset, coord.y - 1, coord.z + zoffset)) - return new CoordinatesBlock(coord.dim, coord.x + xoffset, coord.y, coord.z + zoffset); - - if (world.isAirBlock(coord.x - xoffset, coord.y, coord.z + zoffset) && - world.isAirBlock(coord.x - xoffset, coord.y + 1, coord.z + zoffset) && - !world.isAirBlock(coord.x - xoffset, coord.y - 1, coord.z + zoffset)) - return new CoordinatesBlock(coord.dim, coord.x - xoffset, coord.y, coord.z + zoffset); - - if (world.isAirBlock(coord.x + xoffset, coord.y, coord.z - zoffset) && - world.isAirBlock(coord.x + xoffset, coord.y + 1, coord.z - zoffset) && - !world.isAirBlock(coord.x + xoffset, coord.y - 1, coord.z - zoffset)) - return new CoordinatesBlock(coord.dim, coord.x + xoffset, coord.y, coord.z - zoffset); - - if (world.isAirBlock(coord.x - xoffset, coord.y, coord.z - zoffset) && - world.isAirBlock(coord.x - xoffset, coord.y + 1, coord.z - zoffset) && - !world.isAirBlock(coord.x - xoffset, coord.y - 1, coord.z - zoffset)) - return new CoordinatesBlock(coord.dim, coord.x - xoffset, coord.y, coord.z - zoffset); - } - } - } else { - int y = 256; - while (world.isAirBlock(coord.x, y, coord.z) || - world.getBlockId(coord.x, y, coord.z) == Block.vine.blockID - ) - y--; - - for (int xoffset = 0; xoffset <= maxOffset; xoffset++){ - for (int zoffset = 0; zoffset <= maxOffset; zoffset++){ - if (world.isAirBlock(coord.x + xoffset, y, coord.z + zoffset) && world.isAirBlock(coord.x + xoffset, y + 1, coord.z + zoffset)) - return new CoordinatesBlock(coord.dim, coord.x + xoffset, y, coord.z + zoffset); - - if (world.isAirBlock(coord.x - xoffset, y, coord.z + zoffset) && world.isAirBlock(coord.x - xoffset, y + 1, coord.z + zoffset)) - return new CoordinatesBlock(coord.dim, coord.x - xoffset, y, coord.z + zoffset); - - if (world.isAirBlock(coord.x + xoffset, y, coord.z - zoffset) && world.isAirBlock(coord.x + xoffset, y + 1, coord.z - zoffset)) - return new CoordinatesBlock(coord.dim, coord.x + xoffset, y, coord.z - zoffset); - - if (world.isAirBlock(coord.x - xoffset, y, coord.z - zoffset) && world.isAirBlock(coord.x - xoffset, y + 1, coord.z - zoffset)) - return new CoordinatesBlock(coord.dim, coord.x - xoffset, y, coord.z - zoffset); - } - } - } - - return null; - } - public static boolean teleportPlayer(CoordinatesBlock coord, EntityPlayerMP player){ //System.out.printf("%s %s\n", coord, getTeleportTarget(coord)); - CoordinatesBlock target = EntityManager.getTeleportTarget(coord); + CoordinatesBlock target = Teleport.instance().getTeleportTarget(coord); if (target == null) return false; - World targetWorld = DimensionManager.getWorld(coord.dim); - boolean isBedrock = targetWorld.getBlockId(target.x, target.y - 1, target.z) == Block.bedrock.blockID; - boolean canTeleport = false; - CoordinatesBlock finalTarget; - - // Fix for the nether and all cavern worlds. - if ((target.y > 64) && isBedrock){ - int tempY = target.y - 1; - while (tempY > 1){ - if (targetWorld.isAirBlock(target.x, tempY, target.z) && targetWorld.isAirBlock(target.x, tempY - 1, target.z)){ - canTeleport = true; - - while (targetWorld.isAirBlock(target.x, tempY, target.z)){tempY -= 1;} - - break; - } - tempY -= 1; - } - - finalTarget = new CoordinatesBlock(target.dim, target.x, tempY + 1, target.z); - - - } else { - canTeleport = true; - finalTarget = target; - } + target = Teleport.instance().fixNetherTP(target); - if (!canTeleport) return false; + if (target == null) return false; if (Teleport.instance().movePlayerToDimension(player, coord.dim)) - player.setPositionAndUpdate(finalTarget.x + 0.5, finalTarget.y, finalTarget.z + 0.5); + player.setPositionAndUpdate(target.x + 0.5, target.y, target.z + 0.5); else return false; diff --git a/mcp/mobius/opis/helpers/Teleport.java b/mcp/mobius/opis/helpers/Teleport.java index 3dc3910..37c7930 100644 --- a/mcp/mobius/opis/helpers/Teleport.java +++ b/mcp/mobius/opis/helpers/Teleport.java @@ -3,6 +3,8 @@ package mcp.mobius.opis.helpers; import java.util.Iterator; import cpw.mods.fml.common.registry.GameRegistry; +import mcp.mobius.opis.data.holders.basetypes.CoordinatesBlock; +import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.player.EntityPlayerMP; @@ -14,6 +16,7 @@ import net.minecraft.server.management.ServerConfigurationManager; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.MathHelper; import net.minecraft.world.Teleporter; +import net.minecraft.world.World; import net.minecraft.world.WorldProvider; import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; @@ -137,4 +140,96 @@ public class Teleport { return true; } + public CoordinatesBlock getTeleportTarget(CoordinatesBlock coord){ + World world = DimensionManager.getWorld(coord.dim); + if (world == null) {return null;} + + int maxOffset = 16; + boolean targetFound = false; + + if (coord.y > 0){ + for (int xoffset = 0; xoffset <= maxOffset; xoffset++){ + for (int zoffset = 0; zoffset <= maxOffset; zoffset++){ + if ( world.isAirBlock(coord.x + xoffset, coord.y, coord.z + zoffset) && + world.isAirBlock(coord.x + xoffset, coord.y + 1, coord.z + zoffset) && + !world.isAirBlock(coord.x + xoffset, coord.y - 1, coord.z + zoffset)) + return new CoordinatesBlock(coord.dim, coord.x + xoffset, coord.y, coord.z + zoffset); + + if (world.isAirBlock(coord.x - xoffset, coord.y, coord.z + zoffset) && + world.isAirBlock(coord.x - xoffset, coord.y + 1, coord.z + zoffset) && + !world.isAirBlock(coord.x - xoffset, coord.y - 1, coord.z + zoffset)) + return new CoordinatesBlock(coord.dim, coord.x - xoffset, coord.y, coord.z + zoffset); + + if (world.isAirBlock(coord.x + xoffset, coord.y, coord.z - zoffset) && + world.isAirBlock(coord.x + xoffset, coord.y + 1, coord.z - zoffset) && + !world.isAirBlock(coord.x + xoffset, coord.y - 1, coord.z - zoffset)) + return new CoordinatesBlock(coord.dim, coord.x + xoffset, coord.y, coord.z - zoffset); + + if (world.isAirBlock(coord.x - xoffset, coord.y, coord.z - zoffset) && + world.isAirBlock(coord.x - xoffset, coord.y + 1, coord.z - zoffset) && + !world.isAirBlock(coord.x - xoffset, coord.y - 1, coord.z - zoffset)) + return new CoordinatesBlock(coord.dim, coord.x - xoffset, coord.y, coord.z - zoffset); + } + } + } else { + int y = 256; + while (world.isAirBlock(coord.x, y, coord.z) || + world.getBlockId(coord.x, y, coord.z) == Block.vine.blockID + ) + y--; + + for (int xoffset = 0; xoffset <= maxOffset; xoffset++){ + for (int zoffset = 0; zoffset <= maxOffset; zoffset++){ + if (world.isAirBlock(coord.x + xoffset, y, coord.z + zoffset) && world.isAirBlock(coord.x + xoffset, y + 1, coord.z + zoffset)) + return new CoordinatesBlock(coord.dim, coord.x + xoffset, y, coord.z + zoffset); + + if (world.isAirBlock(coord.x - xoffset, y, coord.z + zoffset) && world.isAirBlock(coord.x - xoffset, y + 1, coord.z + zoffset)) + return new CoordinatesBlock(coord.dim, coord.x - xoffset, y, coord.z + zoffset); + + if (world.isAirBlock(coord.x + xoffset, y, coord.z - zoffset) && world.isAirBlock(coord.x + xoffset, y + 1, coord.z - zoffset)) + return new CoordinatesBlock(coord.dim, coord.x + xoffset, y, coord.z - zoffset); + + if (world.isAirBlock(coord.x - xoffset, y, coord.z - zoffset) && world.isAirBlock(coord.x - xoffset, y + 1, coord.z - zoffset)) + return new CoordinatesBlock(coord.dim, coord.x - xoffset, y, coord.z - zoffset); + } + } + } + + return null; + } + + public CoordinatesBlock fixNetherTP(CoordinatesBlock target){ + World targetWorld = DimensionManager.getWorld(target.dim); + boolean isBedrock = targetWorld.getBlockId(target.x, target.y - 1, target.z) == Block.bedrock.blockID; + boolean canTeleport = false; + CoordinatesBlock finalTarget; + + // Fix for the nether and all cavern worlds. + if ((target.y > 64) && isBedrock){ + int tempY = target.y - 1; + while (tempY > 1){ + if (targetWorld.isAirBlock(target.x, tempY, target.z) && targetWorld.isAirBlock(target.x, tempY - 1, target.z)){ + canTeleport = true; + + while (targetWorld.isAirBlock(target.x, tempY, target.z)){tempY -= 1;} + + break; + } + tempY -= 1; + } + + finalTarget = new CoordinatesBlock(target.dim, target.x, tempY + 1, target.z); + + + } else { + canTeleport = true; + finalTarget = target; + } + + if (canTeleport) + return finalTarget; + else + return null; + } + }