Search in sources :

Example 6 with Teleporter

use of net.minecraft.world.Teleporter in project NetherEx by LogicTechCorp.

the class TeleporterNetherEx method placeInExistingPortal.

@Override
public boolean placeInExistingPortal(Entity entity, float rotationYaw) {
    double d0 = -1.0D;
    int j = MathHelper.floor(entity.posX);
    int k = MathHelper.floor(entity.posZ);
    boolean flag = true;
    BlockPos blockpos = BlockPos.ORIGIN;
    long l = ChunkPos.asLong(j, k);
    if (destinationCoordinateCache.containsKey(l)) {
        Teleporter.PortalPosition teleporter$portalposition = destinationCoordinateCache.get(l);
        d0 = 0.0D;
        blockpos = teleporter$portalposition;
        teleporter$portalposition.lastUpdateTime = world.getTotalWorldTime();
        flag = false;
    } else {
        BlockPos blockpos3 = new BlockPos(entity);
        for (int i1 = -128; i1 <= 128; ++i1) {
            BlockPos blockpos2;
            for (int j1 = -128; j1 <= 128; ++j1) {
                for (BlockPos blockpos1 = blockpos3.add(i1, world.getActualHeight() - 1 - blockpos3.getY(), j1); blockpos1.getY() >= 0; blockpos1 = blockpos2) {
                    blockpos2 = blockpos1.down();
                    if (world.getBlockState(blockpos1).getBlock() == NetherExBlocks.BLOCK_PORTAL_NETHER || world.getBlockState(blockpos1).getBlock() == Blocks.PORTAL) {
                        for (blockpos2 = blockpos1.down(); world.getBlockState(blockpos2).getBlock() == NetherExBlocks.BLOCK_PORTAL_NETHER || world.getBlockState(blockpos2).getBlock() == Blocks.PORTAL; blockpos2 = blockpos2.down()) {
                            blockpos1 = blockpos2;
                        }
                        double d1 = blockpos1.distanceSq(blockpos3);
                        if (d0 < 0.0D || d1 < d0) {
                            d0 = d1;
                            blockpos = blockpos1;
                        }
                    }
                }
            }
        }
    }
    if (d0 >= 0.0D) {
        if (flag) {
            destinationCoordinateCache.put(l, new Teleporter.PortalPosition(blockpos, world.getTotalWorldTime()));
        }
        double xPos = blockpos.getX() + 0.5D;
        double yPos = blockpos.getY();
        double zPos = blockpos.getZ() + 0.5D;
        entity.motionX = entity.motionY = entity.motionZ = 0.0D;
        if (entity instanceof EntityPlayerMP) {
            ((EntityPlayerMP) entity).connection.setPlayerLocation(xPos, yPos, zPos, entity.rotationYaw, entity.rotationPitch);
        } else {
            entity.setLocationAndAngles(xPos, yPos, zPos, entity.rotationYaw, entity.rotationPitch);
        }
        return true;
    } else {
        return false;
    }
}
Also used : Teleporter(net.minecraft.world.Teleporter) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 7 with Teleporter

use of net.minecraft.world.Teleporter in project Gaia-Dimension by Andromander.

the class TeleporterGaia method getTeleporterForDim.

public static TeleporterGaia getTeleporterForDim(MinecraftServer server, int dim) {
    WorldServer ws = server.getWorld(dim);
    for (Teleporter t : ws.customTeleporters) {
        if (t instanceof TeleporterGaia) {
            return (TeleporterGaia) t;
        }
    }
    TeleporterGaia tp = new TeleporterGaia(ws);
    ws.customTeleporters.add(tp);
    return tp;
}
Also used : Teleporter(net.minecraft.world.Teleporter) WorldServer(net.minecraft.world.WorldServer)

Example 8 with Teleporter

use of net.minecraft.world.Teleporter in project Gaia-Dimension by Andromander.

the class GDGaiaPortal method changeDimension.

private void changeDimension(Entity toTeleport, int dimensionIn) {
    if (!toTeleport.world.isRemote && !toTeleport.isDead) {
        if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(toTeleport, dimensionIn))
            return;
        toTeleport.world.profiler.startSection("changeDimension");
        MinecraftServer minecraftserver = toTeleport.getServer();
        int i = toTeleport.dimension;
        WorldServer worldserver = minecraftserver.getWorld(i);
        WorldServer worldserver1 = minecraftserver.getWorld(dimensionIn);
        toTeleport.dimension = dimensionIn;
        if (i == 1 && dimensionIn == 1) {
            worldserver1 = minecraftserver.getWorld(0);
            toTeleport.dimension = 0;
        }
        toTeleport.world.removeEntity(toTeleport);
        toTeleport.isDead = false;
        toTeleport.world.profiler.startSection("reposition");
        BlockPos blockpos;
        if (dimensionIn == 1) {
            blockpos = worldserver1.getSpawnCoordinate();
        } else {
            double d0 = toTeleport.posX;
            double d1 = toTeleport.posZ;
            double d2 = 8.0D;
            d0 = (double) MathHelper.clamp((int) d0, -29999872, 29999872);
            d1 = (double) MathHelper.clamp((int) d1, -29999872, 29999872);
            float f = toTeleport.rotationYaw;
            toTeleport.setLocationAndAngles(d0, toTeleport.posY, d1, 90.0F, 0.0F);
            Teleporter teleporter = TeleporterGaia.getTeleporterForDim(minecraftserver, dimensionIn);
            teleporter.placeInExistingPortal(toTeleport, f);
            blockpos = new BlockPos(toTeleport);
        }
        worldserver.updateEntityWithOptionalForce(toTeleport, false);
        toTeleport.world.profiler.endStartSection("reloading");
        Entity entity = EntityList.newEntity(toTeleport.getClass(), worldserver1);
        if (entity != null) {
            entity.copyDataFromOld(toTeleport);
            if (i == 1 && dimensionIn == 1) {
                BlockPos blockpos1 = worldserver1.getTopSolidOrLiquidBlock(worldserver1.getSpawnPoint());
                entity.moveToBlockPosAndAngles(blockpos1, entity.rotationYaw, entity.rotationPitch);
            } else {
                entity.setLocationAndAngles((double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), entity.rotationYaw, entity.rotationPitch);
            }
            boolean flag = entity.forceSpawn;
            entity.forceSpawn = true;
            worldserver1.spawnEntity(entity);
            entity.forceSpawn = flag;
            worldserver1.updateEntityWithOptionalForce(entity, false);
        }
        toTeleport.isDead = true;
        toTeleport.world.profiler.endSection();
        worldserver.resetUpdateEntityTick();
        worldserver1.resetUpdateEntityTick();
        toTeleport.world.profiler.endSection();
    }
}
Also used : Entity(net.minecraft.entity.Entity) Teleporter(net.minecraft.world.Teleporter) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 9 with Teleporter

use of net.minecraft.world.Teleporter in project Cavern2 by kegare.

the class BlockPortalCavern method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
    if (world.isRemote || getDimension() == null || teleporting) {
        return;
    }
    if (entity.isDead || entity.isSneaking() || entity.isRiding() || entity.isBeingRidden() || !entity.isNonBoss() || entity instanceof IProjectile) {
        return;
    }
    if (entity.timeUntilPortal <= 0) {
        ResourceLocation key = getRegistryName();
        IPortalCache cache = PortalCache.get(entity);
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        DimensionType dimOld = world.provider.getDimensionType();
        DimensionType dimNew = isEntityInCave(entity) ? cache.getLastDim(key) : getDimension();
        WorldServer worldNew = server.getWorld(dimNew.getId());
        Teleporter teleporter = getTeleporter(worldNew);
        BlockPos prevPos = entity.getPosition();
        entity.timeUntilPortal = Math.max(entity.getPortalCooldown(), 100);
        if (entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entity;
            if (MinerStats.get(player).getRank() < getMinerRank().getRank()) {
                player.sendStatusMessage(new TextComponentTranslation("cavern.message.portal.rank", new TextComponentTranslation(getMinerRank().getUnlocalizedName())), true);
                return;
            }
        }
        teleporting = true;
        cache.setLastDim(key, dimOld);
        cache.setLastPos(key, dimOld, prevPos);
        PatternHelper pattern = createPatternHelper(world, pos);
        double d0 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? (double) pattern.getFrontTopLeft().getZ() : (double) pattern.getFrontTopLeft().getX();
        double d1 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? entity.posZ : entity.posX;
        d1 = Math.abs(MathHelper.pct(d1 - (pattern.getForwards().rotateY().getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? 1 : 0), d0, d0 - pattern.getWidth()));
        double d2 = MathHelper.pct(entity.posY - 1.0D, pattern.getFrontTopLeft().getY(), pattern.getFrontTopLeft().getY() - pattern.getHeight());
        cache.setLastPortalVec(new Vec3d(d1, d2, 0.0D));
        cache.setTeleportDirection(pattern.getForwards());
        entity.changeDimension(dimNew.getId(), teleporter);
        teleporting = false;
    } else {
        entity.timeUntilPortal = Math.max(entity.getPortalCooldown(), 100);
    }
}
Also used : DimensionType(net.minecraft.world.DimensionType) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) PatternHelper(net.minecraft.block.state.pattern.BlockPattern.PatternHelper) Teleporter(net.minecraft.world.Teleporter) WorldServer(net.minecraft.world.WorldServer) Vec3d(net.minecraft.util.math.Vec3d) IProjectile(net.minecraft.entity.IProjectile) MinecraftServer(net.minecraft.server.MinecraftServer) IPortalCache(cavern.api.IPortalCache) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Example 10 with Teleporter

use of net.minecraft.world.Teleporter in project EnderIO by SleepyTrousers.

the class TeleportUtil method serverTeleport.

public static boolean serverTeleport(@Nonnull Entity entity, @Nonnull BlockPos pos, int targetDim, boolean conserveMotion, @Nonnull TravelSource source) {
    TeleportEntityEvent evt = new TeleportEntityEvent(entity, source, pos, targetDim);
    if (MinecraftForge.EVENT_BUS.post(evt)) {
        return false;
    }
    EntityPlayerMP player = null;
    if (entity instanceof EntityPlayerMP) {
        player = (EntityPlayerMP) entity;
    }
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    int from = entity.dimension;
    if (from != targetDim) {
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        WorldServer fromDim = server.getWorld(from);
        WorldServer toDim = server.getWorld(targetDim);
        Teleporter teleporter = new TeleporterEIO(toDim);
        // play sound at the dimension we are leaving for others to hear
        SoundHelper.playSound(server.getWorld(entity.dimension), entity, source.sound, 1.0F, 1.0F);
        if (player != null) {
            server.getPlayerList().transferPlayerToDimension(player, targetDim, teleporter);
            if (from == 1 && entity.isEntityAlive()) {
                // get around vanilla End
                // hacks
                toDim.spawnEntity(entity);
                toDim.updateEntityWithOptionalForce(entity, false);
            }
        } else {
            NBTTagCompound tagCompound = new NBTTagCompound();
            float rotationYaw = entity.rotationYaw;
            float rotationPitch = entity.rotationPitch;
            entity.writeToNBT(tagCompound);
            Class<? extends Entity> entityClass = entity.getClass();
            fromDim.removeEntity(entity);
            try {
                Entity newEntity = entityClass.getConstructor(World.class).newInstance(toDim);
                newEntity.readFromNBT(tagCompound);
                newEntity.setLocationAndAngles(x, y, z, rotationYaw, rotationPitch);
                newEntity.forceSpawn = true;
                toDim.spawnEntity(newEntity);
                // necessary?
                newEntity.forceSpawn = false;
            } catch (Exception e) {
                // Throwables.propagate(e);
                Log.error("serverTeleport: Error creating a entity to be created in new dimension.");
                return false;
            }
        }
    }
    // Force the chunk to load
    if (!entity.world.isBlockLoaded(pos)) {
        entity.world.getChunkFromBlockCoords(pos);
    }
    if (player != null) {
        player.connection.setPlayerLocation(x + 0.5, y + 1.1, z + 0.5, player.rotationYaw, player.rotationPitch);
    } else {
        entity.setPositionAndUpdate(x + 0.5, y + 1.1, z + 0.5);
    }
    entity.fallDistance = 0;
    SoundHelper.playSound(entity.world, entity, source.sound, 1.0F, 1.0F);
    if (player != null) {
        if (conserveMotion) {
            Vector3d velocityVex = Util.getLookVecEio(player);
            SPacketEntityVelocity p = new SPacketEntityVelocity(entity.getEntityId(), velocityVex.x, velocityVex.y, velocityVex.z);
            player.connection.sendPacket(p);
        }
    }
    return true;
}
Also used : Entity(net.minecraft.entity.Entity) TeleportEntityEvent(crazypants.enderio.api.teleport.TeleportEntityEvent) Teleporter(net.minecraft.world.Teleporter) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer) Vector3d(com.enderio.core.common.vecmath.Vector3d) SPacketEntityVelocity(net.minecraft.network.play.server.SPacketEntityVelocity) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Aggregations

Teleporter (net.minecraft.world.Teleporter)10 WorldServer (net.minecraft.world.WorldServer)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 MinecraftServer (net.minecraft.server.MinecraftServer)5 BlockPos (net.minecraft.util.math.BlockPos)5 Entity (net.minecraft.entity.Entity)2 PlayerList (net.minecraft.server.management.PlayerList)2 IPortalCache (cavern.api.IPortalCache)1 Vector3d (com.enderio.core.common.vecmath.Vector3d)1 Vector3i (com.flowpowered.math.vector.Vector3i)1 IColony (com.minecolonies.api.colony.IColony)1 Colony (com.minecolonies.coremod.colony.Colony)1 BuildingTownHall (com.minecolonies.coremod.colony.buildings.BuildingTownHall)1 TakumiTeleporter (com.tntmodders.takumi.world.teleport.TakumiTeleporter)1 TeleportEntityEvent (crazypants.enderio.api.teleport.TeleportEntityEvent)1 PatternHelper (net.minecraft.block.state.pattern.BlockPattern.PatternHelper)1 IProjectile (net.minecraft.entity.IProjectile)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 SPacketEffect (net.minecraft.network.play.server.SPacketEffect)1