Search in sources :

Example 21 with DimensionType

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

the class BlockPortalMirageWorlds method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
    if (world.isRemote || entity.isDead || entity.isRiding() || entity.isBeingRidden() || !(entity instanceof EntityPlayerMP)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) entity;
    if (player.timeUntilPortal <= 0) {
        player.timeUntilPortal = player.getPortalCooldown();
        Set<DimensionType> types = Sets.newHashSet();
        for (ItemStack stack : player.inventory.mainInventory) {
            DimensionType type = getDimension(stack);
            if (type != null) {
                types.add(type);
            }
        }
        for (ItemStack stack : player.getHeldEquipment()) {
            DimensionType type = getDimension(stack);
            if (type != null) {
                types.add(type);
            }
        }
        if (types.isEmpty()) {
            player.sendStatusMessage(new TextComponentTranslation("cavern.message.portal.mirage"), true);
            return;
        }
        MirageSelectMessage message = new MirageSelectMessage();
        for (DimensionType type : types) {
            if (player.capabilities.isCreativeMode) {
                message.dimensions.add(type);
                continue;
            }
            long teleportTime = PlayerData.get(player).getLastTeleportTime(type);
            if (teleportTime <= 0L || teleportTime + 6000L < world.getTotalWorldTime()) {
                message.dimensions.add(type);
            }
        }
        if (message.dimensions.isEmpty()) {
            player.sendStatusMessage(new TextComponentTranslation("cavern.message.portal.wait"), true);
            return;
        } else if (message.dimensions.size() == 1) {
            for (DimensionType type : message.dimensions) {
                double x = player.posX;
                double y = player.posY + player.getEyeHeight();
                double z = player.posZ;
                player.getServerWorld().playSound(player, x, y, z, CaveSounds.CAVE_PORTAL, SoundCategory.BLOCKS, 0.5F, 1.0F);
                CaveItems.MIRAGE_BOOK.transferTo(type, player);
                return;
            }
        }
        CaveNetworkRegistry.sendTo(message, player);
    } else {
        player.timeUntilPortal = player.getPortalCooldown();
    }
}
Also used : DimensionType(net.minecraft.world.DimensionType) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MirageSelectMessage(cavern.network.client.MirageSelectMessage) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 22 with DimensionType

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

the class CavebornEventHooks method onPlayerLoggedIn.

@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
    if (!(event.player instanceof EntityPlayerMP)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) event.player;
    if (!FIRST_PLAYERS.contains(player.getCachedUniqueIdString())) {
        return;
    }
    WorldServer world = player.getServerWorld();
    ConfigCaveborn.Type caveborn = GeneralConfig.caveborn.getType();
    BlockPortalCavern portal = caveborn.getPortalBlock();
    BlockPos pos = player.getPosition();
    IPortalCache cache = PortalCache.get(player);
    PatternHelper pattern = portal.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 ? player.posZ : player.posX;
    d1 = Math.abs(MathHelper.pct(d1 - (pattern.getForwards().rotateY().getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? 1 : 0), d0, d0 - pattern.getWidth()));
    double d2 = MathHelper.pct(player.posY - 1.0D, pattern.getFrontTopLeft().getY(), pattern.getFrontTopLeft().getY() - pattern.getHeight());
    cache.setLastPortalVec(new Vec3d(d1, d2, 0.0D));
    cache.setTeleportDirection(pattern.getForwards());
    player.timeUntilPortal = player.getPortalCooldown();
    portal.getTeleporter(world).placeInPortal(player, player.rotationYaw);
    FIRST_PLAYERS.remove(event.player.getCachedUniqueIdString());
    DimensionType type = portal.getDimension();
    if (type == CaveDimensions.CAVERN) {
        PlayerHelper.grantCriterion(player, "root", "entered_cavern");
    } else {
        String name = type.getName();
        PlayerHelper.grantCriterion(player, "enter_the_" + name, "entered_" + name);
    }
    pos = player.getPosition();
    for (BlockPos blockpos : BlockPos.getAllInBoxMutable(pos.add(-1, -1, -1), pos.add(1, 1, 1))) {
        if (world.getBlockState(blockpos).getBlock() == portal) {
            world.setBlockToAir(blockpos);
            break;
        }
    }
    double x = player.posX;
    double y = player.posY + 0.25D;
    double z = player.posZ;
    world.playSound(null, x, y, z, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.BLOCKS, 1.0F, 0.65F);
    for (ItemMeta itemMeta : GeneralConfig.cavebornBonusItems.getItems()) {
        ItemStack stack = itemMeta.getItemStack();
        if (stack.isStackable()) {
            stack = itemMeta.getItemStack(MathHelper.getInt(CaveEventHooks.RANDOM, 4, 16));
        }
        InventoryHelper.spawnItemStack(world, x, y, z, stack);
    }
}
Also used : DimensionType(net.minecraft.world.DimensionType) PatternHelper(net.minecraft.block.state.pattern.BlockPattern.PatternHelper) ConfigCaveborn(cavern.config.property.ConfigCaveborn) WorldServer(net.minecraft.world.WorldServer) Vec3d(net.minecraft.util.math.Vec3d) IPortalCache(cavern.api.IPortalCache) BlockPortalCavern(cavern.block.BlockPortalCavern) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemMeta(cavern.util.ItemMeta) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 23 with DimensionType

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

the class ItemMagicBook method addInformation.

@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
    switch(EnumType.byItemStack(stack)) {
        case STORAGE:
            IInventory inventory = InventoryMagicStorage.get(stack).getInventory();
            if (inventory == null) {
                break;
            }
            int count = 0;
            Set<String> names = Sets.newTreeSet();
            for (int i = 0; i < inventory.getSizeInventory() && count < 5; ++i) {
                ItemStack item = inventory.getStackInSlot(i);
                if (!item.isEmpty() && names.add(item.getDisplayName())) {
                    ++count;
                }
            }
            for (String name : names) {
                tooltip.add(TextFormatting.ITALIC + name + TextFormatting.RESET);
            }
            break;
        case WARP:
            Pair<BlockPos, DimensionType> warpPoint = MagicWarp.getWarpPoint(stack);
            if (warpPoint == null) {
                break;
            }
            BlockPos pos = warpPoint.getLeft();
            DimensionType type = warpPoint.getRight();
            tooltip.add(String.format("%s: %d, %d, %d", type.getName(), pos.getX(), pos.getY(), pos.getZ()));
            break;
        default:
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) DimensionType(net.minecraft.world.DimensionType) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 24 with DimensionType

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

the class MagicWarp method getWarpPoint.

@Nullable
public static Pair<BlockPos, DimensionType> getWarpPoint(ItemStack stack) {
    if (!hasWarpPoint(stack)) {
        return null;
    }
    NBTTagCompound nbt = stack.getTagCompound();
    NBTTagCompound compound = nbt.getCompoundTag("WarpPoint");
    BlockPos pos = NBTUtil.getPosFromTag(compound);
    DimensionType type;
    try {
        type = DimensionType.getById(compound.getInteger("Dim"));
    } catch (IllegalArgumentException e) {
        nbt.removeTag("WarpPoint");
        return null;
    }
    return Pair.of(pos, type);
}
Also used : DimensionType(net.minecraft.world.DimensionType) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) Nullable(javax.annotation.Nullable)

Example 25 with DimensionType

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

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