Java Code Examples for net.minecraft.command.ICommandSender#getEntityWorld()

The following examples show how to use net.minecraft.command.ICommandSender#getEntityWorld() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Returns the given ICommandSender as a EntityPlayer or throw an exception.
 */
public static TileEntity getCommandSenderAsTileEntity(ICommandSender sender) {
	try {
		World world = sender.getEntityWorld();
		ChunkCoordinates coords = sender.getPlayerCoordinates();
		return world.getTileEntity(coords.posX, coords.posY, coords.posZ);
	} catch (Exception e) {
		throw new CommandException("Could not get tile entity");
	}
}
 
Example 2
@Override
public void processCommand(ICommandSender sender, String[] args) {
	World world = sender.getEntityWorld();
	if (!world.isRemote) {
		if (args.length > 0) {
			sender.addChatMessage(new ChatComponentText("This command takes no arguments"));
			return;
		}
		
		Dungeon dungeon = BurlapCraft.currentDungeon;
		
		if (dungeon == null) {
			sender.addChatMessage(new ChatComponentText("You are not inside a dungeon"));
			return;
		}


		Thread btread = new Thread(new Runnable() {
			@Override
			public void run() {
				MinecraftSolver.learn();
			}
		});
		btread.start();

	}
}
 
Example 3
@Override
public void processCommand(ICommandSender sender, String[] args) {
	World world = sender.getEntityWorld();
	if (!world.isRemote) {
		if (args.length > 1) {
			sender.addChatMessage(new ChatComponentText("This command takes only 1 optional argument: the gamma factor"));
			return;
		}
		
		Dungeon dungeon = BurlapCraft.currentDungeon;

		
		if (dungeon == null) {
			sender.addChatMessage(new ChatComponentText("You are not inside a dungeon"));
			return;
		}

		
		
		double gamma = 0.99;
		if(args.length == 1){
			gamma = new Double(args[0]);
		}
		
		final double fgamma = gamma;

		Thread bthread = new Thread(new Runnable() {
			@Override
			public void run() {
				MinecraftSolver.stocasticPlan(fgamma);
			}
		});

		bthread.start();

	}
}
 
Example 4
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length != 2)
        throw new WrongUsageException(getUsage(sender));

    EntityPlayer player = getPlayer(server, sender, args[1]);

    if (player != null)
    {
        PlacementSettings settings = new PlacementSettings();
        WorldServer world = (WorldServer) sender.getEntityWorld();

        int platformNumber = SpawnPlatformSavedData.get(world).addAndGetPlatformNumber();
        BlockPos pos = getPositionOfPlatform(world, platformNumber);

        Template temp = StructureUtil.loadTemplate(new ResourceLocation(args[0]), world, true);
        BlockPos spawn = StructureUtil.findSpawn(temp, settings);
        spawn = spawn == null ? pos : spawn.add(pos);

        sender.sendMessage(new TextComponentString("Building \"" + args[0] + "\" at " + pos.toString()));
        temp.addBlocksToWorld(world, pos, settings, 2); //Push to world, with no neighbor notifications!
        world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall!

        if (player instanceof EntityPlayerMP) {
            ((EntityPlayerMP) player).setPositionAndUpdate(spawn.getX() + 0.5, spawn.getY() + 1.6, spawn.getZ() + 0.5);
        }

        player.setSpawnChunk(spawn, true, world.provider.getDimension());
    }
    else
    {
        throw new WrongUsageException(getUsage(sender));
    }
}
 
Example 5
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args)
    throws CommandException {
  World world = sender.getEntityWorld();
  if (!world.isRemote) {
    if (args.length == 0) {
      showUsage(sender);
      return;
    }

    if (args[0].equalsIgnoreCase("start")) {
      YouTubeConfiguration configuration = YouTubeConfiguration.getInstance();
      String clientSecret = configuration.getClientSecret();
      if (clientSecret == null || clientSecret.isEmpty()) {
        showMessage("No client secret configurated", sender);
        return;
      }
      service.start(configuration.getVideoId(), clientSecret, sender);
    } else if (args[0].equalsIgnoreCase("stop")) {
      service.stop(sender);
    } else if (args[0].equalsIgnoreCase("logout")) {
      service.stop(sender);
      try {
        Auth.clearCredentials();
      } catch(IOException e) {
        showMessage(e.getMessage(), sender);
      }
    } else {
      if (args[0].equalsIgnoreCase("echoStart")) {
        if (!service.isInitialized()) {
          showMessage("Service is not initialized", sender);
          showUsage(sender);
        } else {
          service.subscribe(this);
        }
      } else if (args[0].equalsIgnoreCase("echoStop")) {
        service.unsubscribe(this);
      } else {
        showUsage(sender);
      }
    }
  }
}
 
Example 6
ShipNameAutocompleter(ICommandSender sender) {
    World world = sender.getEntityWorld();
    this.data = QueryableShipData.get(world).stream().map(ShipData::getName).iterator();
}
 
Example 7
public static Integer getSenderDimension(ICommandSender sender) {
	World w = sender.getEntityWorld();
	if (w == null) throw new CommandException("You must specify a dimension to use this command from the commandline");
	return w.provider.dimensionId;
}
 
Example 8
@Override
public void processCommand(ICommandSender sender, String[] args) {
	World world = sender.getEntityWorld();
	if (!world.isRemote) {
		if (args.length > 2) {
			sender.addChatMessage(new ChatComponentText("This command takes only 2 optional arguments: closed or open as the first, and all or noplace as the second."));
			return;
		}
		
		Dungeon dungeon = BurlapCraft.currentDungeon;

		
		if (dungeon == null) {
			sender.addChatMessage(new ChatComponentText("You are not inside a dungeon"));
			return;
		}

		
		
		boolean closed = true;
		boolean place = true;
		if(args.length == 1){
			if(args[0].equals("open")){
				closed = false;
			}
		}
		
		if(args.length == 2){
			if(args[0].equals("open")){
				closed = false;
			}
			if(args[1].equals("noplace")){
				place = false;
			}
		}

		final boolean fclosed = closed;
		final boolean fplace = place;

		Thread bthread = new Thread(new Runnable() {
			@Override
			public void run() {
				MinecraftSolver.plan(1, fclosed, fplace);
			}
		});

		bthread.start();


	}
}
 
Example 9
@Override
public void processCommand(ICommandSender sender, String[] args) {
	World world = sender.getEntityWorld();
	if (!world.isRemote) {
		if (args.length > 2) {
			sender.addChatMessage(new ChatComponentText("This command takes only 2 optional arguments: closed or open as the first, and all or noplace as the second."));
			return;
		}
		
		Dungeon dungeon = BurlapCraft.currentDungeon;
		
		if (dungeon == null) {
			sender.addChatMessage(new ChatComponentText("You are not inside a dungeon"));
			return;
		}


		boolean closed = true;
		boolean place = true;
		if(args.length == 1){
			if(args[0].equals("open")){
				closed = false;
			}
		}
		
		if(args.length == 2){
			if(args[0].equals("open")){
				closed = false;
			}
			if(args[1].equals("noplace")){
				place = false;
			}
		}

		final boolean fclosed = closed;
		final boolean fplace = place;

		Thread bthread = new Thread(new Runnable() {
			@Override
			public void run() {
				MinecraftSolver.plan(0, fclosed, fplace);
			}
		});

		bthread.start();


	}
}
 
Example 10
@Override
public void processCommand(ICommandSender sender, String[] args) {
	
	if (!HandlerDungeonGeneration.dungeonsCreated) {
		sender.addChatMessage(new ChatComponentText("Dungeons aren't yet created."));
		return;
	}
	World world = sender.getEntityWorld();
	if (!world.isRemote) {
		if (args.length == 0) {
			sender.addChatMessage(new ChatComponentText("Invalid argument"));
			return;
		}
		
		if (args.length != 1 && args.length != 3) {
			sender.addChatMessage(new ChatComponentText("This command takes just one argument, or 3 integers for pose"));
			return;
		}
		EntityPlayer player = HandlerEvents.player;
		if (args.length == 3) {
			int x = Integer.valueOf(args[0]);
			int y = Integer.valueOf(args[1])	;
			int z = Integer.valueOf(args[2]);	
			Pose newp= Pose.fromXyz(x, y, z);
			HelperActions.setPlayerPosition(player, newp);
			
		}
		
		String dungeonName = args[0];

		
		if (dungeonName.equals("out")) {
			Pose spawnPoint = Pose.fromXyz(HandlerDungeonGeneration.playerSpawnPose.getX(), HandlerDungeonGeneration.playerSpawnPose.getY(), HandlerDungeonGeneration.playerSpawnPose.getZ());
			HelperActions.setPlayerPosition(player, spawnPoint);
			return;
		} 
		
		Dungeon d = BurlapCraft.dungeonMap.get(dungeonName);
		if (d == null) {
			ArrayList dungeonNames = new ArrayList(BurlapCraft.dungeonMap.keySet());
			Collections.sort(dungeonNames);
			sender.addChatMessage(new ChatComponentText("No dungeon '" + dungeonName + "'.  Dungeons are: "  + dungeonNames));
			return;
		}

		MinecraftStateGeneratorHelper.blockNameMap.clear();
		MinecraftStateGeneratorHelper.invBlockNameMap.clear();
		Pose offset = d.getPlayerStartOffset();
		Pose playerPose = d.getPose().add(offset);
		HelperActions.setPlayerPosition(player, playerPose);

		BurlapCraft.currentDungeon = d;
	}
	
}
 
Example 11
Source Project: YUNoMakeGoodMap   File: PlatformCommand.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
        throw new WrongUsageException(getUsage(sender));

    String cmd = args[0].toLowerCase(Locale.ENGLISH);
    if ("list".equals(cmd))
    {
        sender.sendMessage(new TextComponentString("Known Platforms:"));
        for (ResourceLocation rl : getPlatforms())
        {
            sender.sendMessage(new TextComponentString("  " + rl.toString()));
        }
    }
    else if ("spawn".equals(cmd) || "preview".equals(cmd))
    {
        if (args.length < 2)
            throw new WrongUsageException(getUsage(sender));

        Entity ent = sender.getCommandSenderEntity();
        PlacementSettings settings = new PlacementSettings();
        WorldServer world = (WorldServer)sender.getEntityWorld();

        if (args.length >= 3)
        {
            //TODO: Preview doesnt quite work correctly with rotations....
            String rot = args[2].toLowerCase(Locale.ENGLISH);
            if ("0".equals(rot) || "none".equals(rot))
                settings.setRotation(Rotation.NONE);
            else if ("90".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_90);
            else if ("180".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_180);
            else if ("270".equals(rot))
                settings.setRotation(Rotation.COUNTERCLOCKWISE_90);
            else
                throw new WrongUsageException("Only rotations none, 0, 90, 180, and 270 allowed.");
        }

        BlockPos pos;
        if (args.length >= 6)
            pos = CommandBase.parseBlockPos(sender, args, 3, false);
        else if (ent != null)
            pos = ent.getPosition();
        else
            throw new WrongUsageException("Must specify a position if the command sender is not an entity");

        Template temp = StructureUtil.loadTemplate(new ResourceLocation(args[1]), world, true);

        BlockPos spawn = StructureUtil.findSpawn(temp, settings);
        if (spawn != null)
            pos = pos.subtract(spawn);

        if ("spawn".equals(cmd))
        {
            sender.sendMessage(new TextComponentString("Building \"" + args[1] +"\" at " + pos.toString()));
            temp.addBlocksToWorld(world, pos, settings, 2); //Push to world, with no neighbor notifications!
            world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall!
        }
        else
        {
            BlockPos tpos = pos.down();
            if (spawn != null)
                tpos = tpos.add(spawn);
            sender.sendMessage(new TextComponentString("Previewing \"" + args[1] +"\" at " + pos.toString()));
            world.setBlockState(tpos, Blocks.STRUCTURE_BLOCK.getDefaultState().withProperty(BlockStructure.MODE, TileEntityStructure.Mode.LOAD));
            TileEntityStructure te = (TileEntityStructure)world.getTileEntity(tpos);
            if (spawn != null)
                te.setPosition(te.getPosition().subtract(spawn));
            te.setSize(temp.getSize());
            te.setMode(Mode.LOAD);
            te.markDirty();
        }
    }
    else
        throw new WrongUsageException(getUsage(sender));
}