Java Code Examples for net.minecraft.entity.player.EntityPlayerMP#sendContainerToPlayer()

The following examples show how to use net.minecraft.entity.player.EntityPlayerMP#sendContainerToPlayer() . 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: EntityEnderPearlReusable.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Tries to return the pearl back to the thrower's inventory.
 * @return false if adding the item to the player's inventory failed and dropAsItem should be called. true if the entity can just be killed now.
 */
public boolean returnToPlayersInventory()
{
    if (this.canPickUp == false || this.getEntityWorld().isRemote)
    {
        return true;
    }

    Entity thrower = this.getThrower();
    int damage = (this.isElite ? 1 : 0);

    if (thrower instanceof EntityPlayerMP && ((EntityPlayerMP) thrower).isEntityAlive())
    {
        EntityPlayerMP player = (EntityPlayerMP) thrower;

        // Tried to, but failed to add the pearl straight back to the thrower's inventory
        if (player.inventory.addItemStackToInventory(new ItemStack(EnderUtilitiesItems.ENDER_PEARL_REUSABLE, 1, damage)) == false)
        {
            return false;
        }

        // This fixes the otherwise one behind lagging count on the hotbar... wtf?!
        player.sendContainerToPlayer(player.openContainer);
        return true;
    }

    return false;
}
 
Example 2
Source File: EntityNBTPacket.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleServerSide(EntityPlayerMP player) {
	Entity e = player.worldObj.getEntityByID(entityID);
	if (e != null) {
		try {
			GameType preGameType = player.theItemInWorldManager.getGameType();
			e.readFromNBT(tag);
			NBTEdit.log(Level.FINE, player.getCommandSenderName() + " edited a tag -- Entity ID #" + entityID);
			NBTEdit.logTag(tag);
			if (e == player) { //Update player info
				player.sendContainerToPlayer(player.inventoryContainer);
				GameType type = player.theItemInWorldManager.getGameType();
				if (preGameType != type)
					player.setGameType(type);
				player.playerNetServerHandler.sendPacket(new S06PacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
				player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
				player.sendPlayerAbilities();
			}
			sendMessageToPlayer(player, "Your changes have been saved");
		} 
		catch(Throwable t) {
			sendMessageToPlayer(player, SECTION_SIGN + "cSave Failed - Invalid NBT format for Entity");
			NBTEdit.log(Level.WARNING, player.getCommandSenderName() + " edited a tag and caused an exception");
			NBTEdit.logTag(tag);
			NBTEdit.throwing("EntityNBTPacket", "handleServerSide", t);
		}
	}
}