Search in sources :

Example 1 with NumberInvalidException

use of net.minecraft.command.NumberInvalidException in project BiomesOPlenty by Glitchfiend.

the class BOPCommand method teleportFoundBiome.

private void teleportFoundBiome(ICommandSender sender, String[] args) throws CommandException {
    if (args.length < 2) {
        throw new WrongUsageException("commands.biomesoplenty.tpbiome.usage");
    }
    // Parse args[1] to find the biome to search for - search for a string matching the biome identifier, or an integer matching the biome id
    Biome biomeToFind = null;
    if (biomeToFind == null) {
        try {
            int biomeId = parseInt(args[1], 0, 255);
            biomeToFind = Biome.getBiome(biomeId);
        } catch (NumberInvalidException e) {
            biomeToFind = BiomeUtils.getBiomeForLoc(new ResourceLocation(args[1]));
        }
    }
    EntityPlayerMP player = getCommandSenderAsPlayer(sender);
    World world = player.world;
    BlockPos closestBiomePos = biomeToFind == null ? null : BiomeUtils.spiralOutwardsLookingForBiome(world, biomeToFind, player.posX, player.posZ);
    String biomeName = biomeToFind != null && FMLCommonHandler.instance().getSide() == Side.CLIENT ? biomeToFind.getBiomeName() : "Undefined";
    if (closestBiomePos != null) {
        double x = (double) closestBiomePos.getX();
        double y = (double) world.getTopSolidOrLiquidBlock(closestBiomePos).getY();
        double z = (double) closestBiomePos.getZ();
        player.connection.setPlayerLocation(x, y, z, player.rotationYaw, player.rotationPitch);
        sender.sendMessage(new TextComponentTranslation("commands.biomesoplenty.tpbiome.success", player.getName(), biomeName, x, y, z));
    } else {
        sender.sendMessage(new TextComponentTranslation("commands.biomesoplenty.tpbiome.error", biomeName));
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Biome(net.minecraft.world.biome.Biome) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) NumberInvalidException(net.minecraft.command.NumberInvalidException) World(net.minecraft.world.World)

Aggregations

NumberInvalidException (net.minecraft.command.NumberInvalidException)1 WrongUsageException (net.minecraft.command.WrongUsageException)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 World (net.minecraft.world.World)1 Biome (net.minecraft.world.biome.Biome)1