net.minecraft.command.NumberInvalidException Java Examples

The following examples show how to use net.minecraft.command.NumberInvalidException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommandBaseAdv.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public static double handleRelativeNumber(ICommandSender par1ICommandSender, double origin, String arg, int min, int max) {
	boolean relative = arg.startsWith("~");
	boolean random = arg.startsWith("?");
	if (random) relative = true;
	double d1 = relative ? origin : 0.0D;

	if (!relative || arg.length() > 1) {
		boolean flag1 = arg.contains(".");

		if (relative) {
			arg = arg.substring(1);
		}

		double d2 = parseDouble(par1ICommandSender, arg);
		if (random) {
			Random rand = new Random();
			d1 += (rand.nextDouble() * 2 - 1) * d2;
		} else {
			d1 += d2;
		}

		if (!flag1 && !relative) {
			d1 += 0.5D;
		}
	}

	if (min != 0 || max != 0) {
		if (d1 < min) { throw new NumberInvalidException("commands.generic.double.tooSmall", new Object[] { Double.valueOf(d1), Integer.valueOf(min) }); }

		if (d1 > max) { throw new NumberInvalidException("commands.generic.double.tooBig", new Object[] { Double.valueOf(d1), Integer.valueOf(max) }); }
	}

	return d1;
}
 
Example #2
Source File: CommandBaseAdv.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public static float parseFloat(ICommandSender par0ICommandSender, String par1Str) {
	try {
		return Float.parseFloat(par1Str);
	} catch (NumberFormatException numberformatexception) {
		throw new NumberInvalidException("commands.generic.num.invalid", new Object[] { par1Str });
	}
}
 
Example #3
Source File: CommandRouteBiome.java    From minecraft-roguelike with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(ICommandContext context, List<String> args) {
	
	ArgumentParser ap = new ArgumentParser(args);
	
	IWorldEditor editor = context.createEditor();
	Coord pos;
	if(!ap.hasEntry(0)){
		pos = context.getPos();
	} else {
		int x; int z;
		try {
			x = CommandBase.parseInt(ap.get(0));
			z = CommandBase.parseInt(ap.get(1));
		} catch (NumberInvalidException e) {
			context.sendMessage("Failure: Invalid Coords: X Z", MessageType.ERROR);
			return;
		}
		pos = new Coord(x, 0, z);
	}
	
	context.sendMessage("Biome Information for " + pos.toString(), MessageType.SPECIAL);
	
	Biome biome = editor.getInfo(pos).getBiome();
	context.sendMessage(biome.getBiomeName(), MessageType.SPECIAL);
	
	Set<BiomeDictionary.Type> biomeTypes = BiomeDictionary.getTypes(biome);
	String types = "";
	for(BiomeDictionary.Type type : biomeTypes){
		types += type.getName() + " ";
	}
	
	context.sendMessage(types, MessageType.SPECIAL);
	return;
}
 
Example #4
Source File: CommandRouteDungeon.java    From minecraft-roguelike with GNU General Public License v3.0 5 votes vote down vote up
public static Coord getLocation(ICommandContext context, List<String> args) throws NumberInvalidException, PlayerNotFoundException{
	ArgumentParser ap = new ArgumentParser(args);

	Coord pos = context.getPos();
	
	if(ap.match(0, "here") || ap.match(0, "nearby")){
		return new Coord((int) pos.getX(), 0, (int) pos.getZ());
	} else {
		try {
			int x = CommandBase.parseInt(ap.get(0));
			int z = CommandBase.parseInt(ap.get(1));
			return new Coord(x, 0, z);
		} catch (NumberInvalidException e) {
			context.sendMessage("Failure: Invalid Coords: X Z", MessageType.ERROR);
			throw(e);
		}
	}
}
 
Example #5
Source File: CommandDisassembleNear.java    From archimedes-ships with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void processCommand(ICommandSender icommandsender, String[] astring)
{
	if (icommandsender instanceof Entity)
	{
		double range = 16D;
		if (astring != null && astring.length > 0)
		{
			try
			{
				range = Integer.parseInt(astring[0]);
			} catch (NumberFormatException e)
			{
				throw new NumberInvalidException();
			}
		}
		double rangesqrd = range * range;
		
		Entity player = (Entity) icommandsender;
		EntityShip ne = null;
		if (player.ridingEntity instanceof EntityShip)
		{
			ne = (EntityShip) player.ridingEntity;
		} else
		{
			double nd = 0D;
			double d;
			for (Entity entity : (List<Entity>) player.worldObj.getLoadedEntityList())
			{
				if (entity instanceof EntityShip)
				{
					d = player.getDistanceSqToEntity(entity);
					if (d < rangesqrd && (ne == null || d < nd))
					{
						ne = (EntityShip) entity;
						nd = d;
					}
				}
			}
		}
		
		if (ne == null)
		{
			icommandsender.addChatMessage(new ChatComponentText("No ship in a " + ((int) range) + " blocks' range"));
			return;
		}
		if (!ne.disassemble(false))
		{
			icommandsender.addChatMessage(new ChatComponentText("Failed to disassemble ship; dropping to items"));
			ne.dropAsItems();
		}
		ne.setDead();
	}
}