Search in sources :

Example 1 with PortalCoordinatesContainer

use of net.tslat.aoa3.library.misc.PortalCoordinatesContainer in project Advent-Of-Ascension by Tslat.

the class AncientCavernTeleporter method findExistingPortal.

@Override
public BlockPos findExistingPortal(World world, Entity entity) {
    if (world.provider.getDimension() == ConfigurationUtil.MainConfig.dimensionIds.ancientCavern) {
        if (entity.hasCapability(AdventPlayerProvider.ADVENT_PLAYER, null)) {
            PlayerDataManager plData = PlayerUtil.getAdventPlayer((EntityPlayer) entity);
            PortalCoordinatesContainer portalLoc = new PortalCoordinatesContainer(world.provider.getDimension(), entity.posX, entity.posY, entity.posZ);
            plData.setPortalReturnLocation(entity.world.provider.getDimension(), portalLoc);
        }
        return new BlockPos(0, 18, 0);
    }
    return super.findExistingPortal(world, entity);
}
Also used : PortalCoordinatesContainer(net.tslat.aoa3.library.misc.PortalCoordinatesContainer) BlockPos(net.minecraft.util.math.BlockPos) PlayerDataManager(net.tslat.aoa3.utils.player.PlayerDataManager)

Example 2 with PortalCoordinatesContainer

use of net.tslat.aoa3.library.misc.PortalCoordinatesContainer in project Advent-Of-Ascension by Tslat.

the class PlayerDataManager method loadFromNBT.

public void loadFromNBT(NBTTagCompound baseTag) {
    stats.loadFromNBT(baseTag);
    if (baseTag.hasKey("PortalMap")) {
        NBTTagCompound portalMapTag = baseTag.getCompoundTag("PortalMap");
        for (String s : portalMapTag.getKeySet()) {
            NBTTagCompound portalReturnTag = portalMapTag.getCompoundTag(s);
            int fromDim = portalReturnTag.getInteger("FromDim");
            double x = portalReturnTag.getDouble("PosX");
            double y = portalReturnTag.getDouble("PosY");
            double z = portalReturnTag.getDouble("PosZ");
            try {
                portalCoordinatesMap.put(Integer.valueOf(s), new PortalCoordinatesContainer(fromDim, x, y, z));
            } catch (NumberFormatException e) {
                AdventOfAscension.logMessage(Level.WARN, "Found invalid portal map data, has someone been tampering with files? Data: " + s);
            }
        }
    }
    checkAndUpdateLegitimacy();
}
Also used : PortalCoordinatesContainer(net.tslat.aoa3.library.misc.PortalCoordinatesContainer) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 3 with PortalCoordinatesContainer

use of net.tslat.aoa3.library.misc.PortalCoordinatesContainer in project Advent-Of-Ascension by Tslat.

the class PortalBlock method onEntityCollision.

@Override
public void onEntityCollision(World world, BlockPos pos, IBlockState state, Entity entity) {
    WorldProvider provider;
    ITeleporter teleporter;
    if (!world.isRemote && !entity.isRiding() && !entity.isBeingRidden()) {
        if (!ConfigurationUtil.MainConfig.allowNonPlayerPortalTravel & !(entity instanceof EntityPlayer))
            return;
        if (entity.timeUntilPortal > 0) {
            entity.timeUntilPortal = 30;
            return;
        }
        provider = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(dimId).provider;
        teleporter = provider instanceof AoAWorldProvider ? ((AoAWorldProvider) provider).getTeleporter((WorldServer) world) : dimId == -1 ? new NetherTeleporter((WorldServer) world) : ((WorldServer) world).getDefaultTeleporter();
        PortalCoordinatesContainer portalLoc = null;
        if (entity instanceof EntityPlayer) {
            PlayerDataManager plData = PlayerUtil.getAdventPlayer((EntityPlayerMP) entity);
            portalLoc = plData.getPortalReturnLocation(world.provider.getDimension());
            ((EntityPlayerMP) entity).connection.setPlayerLocation(pos.getX(), pos.getY(), pos.getZ(), entity.rotationYaw, entity.rotationPitch);
        } else {
            entity.setPositionAndUpdate(pos.getX(), pos.getY(), pos.getZ());
        }
        if (portalLoc == null) {
            if (world.provider.getDimension() == dimId) {
                entity = entity.changeDimension(0, teleporter);
            } else {
                entity = entity.changeDimension(dimId, teleporter);
            }
        } else if (world.provider.getDimension() != dimId) {
            entity = entity.changeDimension(dimId, teleporter);
        } else {
            entity = entity.changeDimension(portalLoc.fromDim, teleporter);
        }
        if (entity != null)
            entity.timeUntilPortal = 100;
    }
}
Also used : PortalCoordinatesContainer(net.tslat.aoa3.library.misc.PortalCoordinatesContainer) ITeleporter(net.minecraftforge.common.util.ITeleporter) AoAWorldProvider(net.tslat.aoa3.dimension.AoAWorldProvider) WorldProvider(net.minecraft.world.WorldProvider) AoAWorldProvider(net.tslat.aoa3.dimension.AoAWorldProvider) NetherTeleporter(net.tslat.aoa3.dimension.nether.NetherTeleporter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer) PlayerDataManager(net.tslat.aoa3.utils.player.PlayerDataManager)

Example 4 with PortalCoordinatesContainer

use of net.tslat.aoa3.library.misc.PortalCoordinatesContainer in project Advent-Of-Ascension by Tslat.

the class AoATeleporter method placeEntity.

@Override
public void placeEntity(World world, Entity entity, float yaw) {
    PlayerDataManager plData = null;
    if (entity.hasCapability(AdventPlayerProvider.ADVENT_PLAYER, null)) {
        entity.setNoGravity(false);
        PortalCoordinatesContainer loc = (plData = PlayerUtil.getAdventPlayer((EntityPlayer) entity)).getPortalReturnLocation(world.provider.getDimension());
        BlockPos locPos;
        if (loc != null) {
            Block locationBlock = world.getBlockState(locPos = loc.asBlockPos()).getBlock();
            if (locationBlock == getPortalBlock()) {
                placeInPortal(world, entity, locPos);
                return;
            } else if (!(locationBlock instanceof PortalBlock)) {
                plData.removePortalReturnLocation(world.provider.getDimension());
            }
        }
    }
    double movementFactor = world.provider.getMovementFactor() / fromWorld.provider.getMovementFactor();
    if (movementFactor != 1)
        entity.setPositionAndUpdate(entity.posX * movementFactor, entity.posY, entity.posZ * movementFactor);
    if (fromWorld.getBlockState(entity.getPosition()).getBlock() == getPortalBlock()) {
        ChunkPos chunkPos = fromWorld.getChunk(entity.getPosition()).getPos();
        getCachedPortalMap().put(ChunkPos.asLong(chunkPos.x, chunkPos.z), entity.getPosition());
    }
    BlockPos pos = findExistingPortal(world, entity);
    if (pos == null) {
        pos = findSuitablePortalLocation(world, entity);
        pos = makePortal(world, entity, pos);
    }
    placeInPortal(world, entity, pos);
    ChunkPos chunkPos = world.getChunk(pos).getPos();
    getCachedPortalMap().put(ChunkPos.asLong(chunkPos.x, chunkPos.z), pos);
    if (plData != null) {
        PortalCoordinatesContainer portalLoc = plData.getPortalReturnLocation(world.provider.getDimension());
        if (portalLoc != null) {
            PortalCoordinatesContainer returnPortalLoc = plData.getPortalReturnLocation(entity.world.provider.getDimension());
            if (returnPortalLoc != null && returnPortalLoc.fromDim == world.provider.getDimension())
                return;
        }
        if (portalLoc == null || entity.world.provider.getDimension() == portalLoc.fromDim || entity.getDistanceSq(portalLoc.asBlockPos()) > ConfigurationUtil.MainConfig.portalSearchRadius)
            plData.setPortalReturnLocation(world.provider.getDimension(), new PortalCoordinatesContainer(entity.world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ()));
    }
}
Also used : PortalCoordinatesContainer(net.tslat.aoa3.library.misc.PortalCoordinatesContainer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PortalBlock(net.tslat.aoa3.block.functional.portal.PortalBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) PlayerDataManager(net.tslat.aoa3.utils.player.PlayerDataManager) PortalBlock(net.tslat.aoa3.block.functional.portal.PortalBlock)

Example 5 with PortalCoordinatesContainer

use of net.tslat.aoa3.library.misc.PortalCoordinatesContainer in project Advent-Of-Ascension by Tslat.

the class ImmortallisTeleporter method findExistingPortal.

@Override
public BlockPos findExistingPortal(World world, Entity entity) {
    if (world.provider.getDimension() == ConfigurationUtil.MainConfig.dimensionIds.immortallis) {
        if (entity.hasCapability(AdventPlayerProvider.ADVENT_PLAYER, null)) {
            PlayerDataManager plData = PlayerUtil.getAdventPlayer((EntityPlayer) entity);
            PortalCoordinatesContainer portalLoc = new PortalCoordinatesContainer(world.provider.getDimension(), entity.posX, entity.posY, entity.posZ);
            plData.setPortalReturnLocation(entity.world.provider.getDimension(), portalLoc);
        }
        return new BlockPos(-5, 20, 3);
    }
    return super.findExistingPortal(world, entity);
}
Also used : PortalCoordinatesContainer(net.tslat.aoa3.library.misc.PortalCoordinatesContainer) BlockPos(net.minecraft.util.math.BlockPos) PlayerDataManager(net.tslat.aoa3.utils.player.PlayerDataManager)

Aggregations

PortalCoordinatesContainer (net.tslat.aoa3.library.misc.PortalCoordinatesContainer)6 PlayerDataManager (net.tslat.aoa3.utils.player.PlayerDataManager)4 BlockPos (net.minecraft.util.math.BlockPos)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Block (net.minecraft.block.Block)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 WorldProvider (net.minecraft.world.WorldProvider)1 WorldServer (net.minecraft.world.WorldServer)1 ITeleporter (net.minecraftforge.common.util.ITeleporter)1 PortalBlock (net.tslat.aoa3.block.functional.portal.PortalBlock)1 AoAWorldProvider (net.tslat.aoa3.dimension.AoAWorldProvider)1 NetherTeleporter (net.tslat.aoa3.dimension.nether.NetherTeleporter)1