Search in sources :

Example 11 with DimensionType

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

the class MagicWarp method fireMagic.

@Override
public ActionResult<ITextComponent> fireMagic() {
    if (!world.isRemote) {
        ItemStack stack = getHeldItem();
        DimensionType type = world.provider.getDimensionType();
        Pair<BlockPos, DimensionType> warpPoint = getWarpPoint(stack);
        if (warpPoint == null) {
            setWarpPoint(stack, player.getPosition(), type);
            return new ActionResult<>(EnumActionResult.SUCCESS, new TextComponentTranslation("item.magicBook.warp.set"));
        }
        BlockPos pos = warpPoint.getLeft();
        if (type != warpPoint.getRight()) {
            return new ActionResult<>(EnumActionResult.FAIL, new TextComponentTranslation("item.magicBook.warp.far"));
        }
        distance = Math.sqrt(player.getDistanceSqToCenter(pos));
        int mana = getMana();
        if (mana < 5 && distance > 100.0D * mana) {
            return new ActionResult<>(EnumActionResult.FAIL, new TextComponentTranslation("item.magicBook.warp.far"));
        }
        if (!player.attemptTeleport(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D)) {
            return new ActionResult<>(EnumActionResult.FAIL, null);
        }
        warp = true;
        setWarpPoint(stack, null, type);
        return new ActionResult<>(EnumActionResult.SUCCESS, null);
    }
    return new ActionResult<>(EnumActionResult.PASS, null);
}
Also used : DimensionType(net.minecraft.world.DimensionType) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 12 with DimensionType

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

the class CaveEventHooks method onPlayerChangedDimension.

@SubscribeEvent
public void onPlayerChangedDimension(PlayerChangedDimensionEvent event) {
    if (!(event.player instanceof EntityPlayerMP)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) event.player;
    if (CavernAPI.dimension.isInCaves(player)) {
        WorldServer world = player.getServerWorld();
        DimensionType type = world.provider.getDimensionType();
        if (type != CaveDimensions.CAVERN) {
            String name = type.getName();
            PlayerHelper.grantCriterion(player, "enter_the_" + name, "entered_" + name);
        }
    }
    MinerStats.adjustData(player);
}
Also used : DimensionType(net.minecraft.world.DimensionType) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 13 with DimensionType

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

the class ItemMirageBook method attemptToLastPos.

protected boolean attemptToLastPos(World world, Entity entity) {
    IPortalCache cache = PortalCache.get(entity);
    ResourceLocation key = CaveUtils.getKey("mirage_worlds");
    DimensionType type = world.provider.getDimensionType();
    if (cache.hasLastPos(key, type)) {
        BlockPos pos = cache.getLastPos(key, type);
        if (world.getBlockState(pos.down()).getMaterial().isSolid() && world.getBlockState(pos).getBlock().canSpawnInBlock() && world.getBlockState(pos.up()).getBlock().canSpawnInBlock()) {
            entity.moveToBlockPosAndAngles(pos, entity.rotationYaw, entity.rotationPitch);
            return true;
        }
        cache.setLastPos(key, type, null);
    }
    return false;
}
Also used : DimensionType(net.minecraft.world.DimensionType) IPortalCache(cavern.api.IPortalCache) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos)

Example 14 with DimensionType

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

the class ItemMirageBook method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    DimensionType type = EnumType.byItemStack(stack).getDimension();
    if (type == null) {
        return new ActionResult<>(EnumActionResult.PASS, stack);
    }
    if (world.provider.getDimensionType() == type) {
        if (!world.isRemote) {
            PlayerData.get(player).setLastTeleportTime(type, world.getTotalWorldTime());
            transferTo(null, player);
        }
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    }
    if (world.isRemote) {
        if (CavernAPI.dimension.isInMirageWorlds(player)) {
            player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".fail"), true);
        } else {
            player.sendStatusMessage(new TextComponentTranslation(getUnlocalizedName() + ".portal"), true);
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, stack);
}
Also used : DimensionType(net.minecraft.world.DimensionType) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack)

Example 15 with DimensionType

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

the class BlockPortalMirageWorlds method openRegeneration.

@SideOnly(Side.CLIENT)
@Override
public void openRegeneration(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side) {
    GuiRegeneration regeneration = new GuiRegeneration();
    DimensionType type = getDimension(player.getHeldItem(hand));
    if (type != null) {
        regeneration.dimensions.add(type);
    }
    FMLClientHandler.instance().showGuiScreen(regeneration);
}
Also used : DimensionType(net.minecraft.world.DimensionType) GuiRegeneration(cavern.client.gui.GuiRegeneration) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

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