Search in sources :

Example 26 with DimensionType

use of net.minecraft.world.DimensionType 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)

Example 27 with DimensionType

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

the class PortalCache method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbt) {
    NBTTagList tagList = nbt.getTagList("LastDim", NBT.TAG_COMPOUND);
    if (tagList != null && tagList.tagCount() > 0) {
        for (int i = 0; i < tagList.tagCount(); ++i) {
            NBTTagCompound tag = tagList.getCompoundTagAt(i);
            DimensionType type = null;
            try {
                type = DimensionType.getById(tag.getInteger("Dim"));
            } catch (IllegalArgumentException e) {
                continue;
            }
            if (type != null && tag.hasKey("Key", NBT.TAG_STRING)) {
                lastDim.put(new ResourceLocation(tag.getString("Key")), type);
            }
        }
    }
    tagList = nbt.getTagList("LastPos", NBT.TAG_COMPOUND);
    for (int i = 0; i < tagList.tagCount(); ++i) {
        NBTTagCompound tag = tagList.getCompoundTagAt(i);
        DimensionType type = null;
        try {
            type = DimensionType.getById(tag.getInteger("Dim"));
        } catch (IllegalArgumentException e) {
            continue;
        }
        if (type != null && tag.hasKey("Key", NBT.TAG_STRING)) {
            lastPos.put(new ResourceLocation(tag.getString("Key")), type, NBTUtil.getPosFromTag(tag));
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) DimensionType(net.minecraft.world.DimensionType) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 28 with DimensionType

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

the class PortalCache method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbt) {
    NBTTagList tagList = new NBTTagList();
    for (Entry<ResourceLocation, DimensionType> entry : lastDim.entrySet()) {
        ResourceLocation key = entry.getKey();
        DimensionType type = entry.getValue();
        if (key != null && type != null) {
            NBTTagCompound tag = new NBTTagCompound();
            tag.setString("Key", key.toString());
            tag.setInteger("Dim", type.getId());
            tagList.appendTag(tag);
        }
    }
    nbt.setTag("LastDim", tagList);
    tagList = new NBTTagList();
    for (Cell<ResourceLocation, DimensionType, BlockPos> entry : lastPos.cellSet()) {
        ResourceLocation key = entry.getRowKey();
        DimensionType type = entry.getColumnKey();
        BlockPos pos = entry.getValue();
        if (key != null && type != null && pos != null) {
            NBTTagCompound tag = NBTUtil.createPosTag(pos);
            tag.setString("Key", key.toString());
            tag.setInteger("Dim", type.getId());
            tagList.appendTag(tag);
        }
    }
    nbt.setTag("LastPos", tagList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) DimensionType(net.minecraft.world.DimensionType) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

DimensionType (net.minecraft.world.DimensionType)28 BlockPos (net.minecraft.util.math.BlockPos)8 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 WorldServer (net.minecraft.world.WorldServer)6 IPortalCache (cavern.api.IPortalCache)5 ItemStack (net.minecraft.item.ItemStack)5 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)5 NBTTagList (net.minecraft.nbt.NBTTagList)4 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 MinecraftServer (net.minecraft.server.MinecraftServer)3 File (java.io.File)2 PatternHelper (net.minecraft.block.state.pattern.BlockPattern.PatternHelper)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ActionResult (net.minecraft.util.ActionResult)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 Vec3d (net.minecraft.util.math.Vec3d)2 WorldProvider (net.minecraft.world.WorldProvider)2