Search in sources :

Example 6 with IPortalCache

use of cavern.api.IPortalCache in project Cavern2 by kegare.

the class ItemMirageBook method transferTo.

public boolean transferTo(@Nullable DimensionType dimNew, EntityPlayer entityPlayer) {
    if (entityPlayer == null || !(entityPlayer instanceof EntityPlayerMP)) {
        return false;
    }
    EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
    ResourceLocation key = CaveUtils.getKey("mirage_worlds");
    IPortalCache cache = PortalCache.get(player);
    DimensionType dimOld = player.world.provider.getDimensionType();
    if (dimNew == null) {
        dimNew = cache.getLastDim(key, null);
    }
    if (dimNew == null || dimOld == dimNew) {
        return false;
    }
    if (CavernAPI.dimension.isMirageWorlds(dimNew)) {
        cache.setLastDim(key, dimOld);
    }
    cache.setLastPos(key, dimOld, player.getPosition());
    player.timeUntilPortal = player.getPortalCooldown();
    player.changeDimension(dimNew.getId(), this);
    if (player.getBedLocation(dimNew.getId()) == null) {
        player.setSpawnChunk(player.getPosition(), true, dimNew.getId());
    }
    return true;
}
Also used : DimensionType(net.minecraft.world.DimensionType) IPortalCache(cavern.api.IPortalCache) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 7 with IPortalCache

use of cavern.api.IPortalCache in project Cavern2 by kegare.

the class TeleporterCavern method placeInPortal.

@Override
public void placeInPortal(Entity entity, float rotationYaw) {
    DimensionType type = world.provider.getDimensionType();
    boolean flag = false;
    if (GeneralConfig.portalCache) {
        IPortalCache cache = PortalCache.get(entity);
        ResourceLocation key = getKey();
        BlockPos prevPos = entity.getPosition();
        if (cache.hasLastPos(key, type)) {
            BlockPos pos = cache.getLastPos(key, type);
            entity.moveToBlockPosAndAngles(pos, entity.rotationYaw, entity.rotationPitch);
            if (placeInExistingPortal(entity, rotationYaw)) {
                flag = true;
            } else {
                entity.moveToBlockPosAndAngles(prevPos, entity.rotationYaw, entity.rotationPitch);
            }
        }
    }
    if (!flag && !placeInExistingPortal(entity, rotationYaw)) {
        makePortal(entity);
        placeInExistingPortal(entity, rotationYaw);
    }
    if (entity instanceof EntityPlayerMP) {
        EntityPlayerMP player = (EntityPlayerMP) entity;
        if (CavernAPI.dimension.isInCaveDimensions(player) && player.getBedLocation() == null) {
            player.setSpawnPoint(player.getPosition(), true);
        }
    }
}
Also used : DimensionType(net.minecraft.world.DimensionType) IPortalCache(cavern.api.IPortalCache) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Aggregations

IPortalCache (cavern.api.IPortalCache)7 BlockPos (net.minecraft.util.math.BlockPos)5 DimensionType (net.minecraft.world.DimensionType)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 Vec3d (net.minecraft.util.math.Vec3d)3 PatternHelper (net.minecraft.block.state.pattern.BlockPattern.PatternHelper)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)2 WorldServer (net.minecraft.world.WorldServer)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IMinerStats (cavern.api.IMinerStats)1 IPlayerData (cavern.api.IPlayerData)1 BlockPortalCavern (cavern.block.BlockPortalCavern)1 ConfigCaveborn (cavern.config.property.ConfigCaveborn)1 ItemMeta (cavern.util.ItemMeta)1 BlockPattern (net.minecraft.block.state.pattern.BlockPattern)1 IProjectile (net.minecraft.entity.IProjectile)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1