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));
}
}
Aggregations