Java源码示例:cpw.mods.fml.common.network.Player

示例1
public static void sendStateInfo(EntityPlayer player, int state)
{
    // server sending state info. first packet int: 1 then int state

    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(bytes);
    try
    {
        data.writeInt(Integer.valueOf(1));
        data.writeInt(Integer.valueOf(state));
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }

    Packet250CustomPayload packet = new Packet250CustomPayload();
    packet.channel = "MoCreatures";
    packet.data = bytes.toByteArray();
    packet.length = packet.data.length;
    PacketDispatcher.sendPacketToPlayer(packet, (Player) player);

}
 
示例2
/**
 * 
 * @param player
 * @param entityId
 */
public static void sendNameGUI(EntityPlayerMP player, int entityId)
{
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(bytes);
    try
    {
        data.writeInt(Integer.valueOf(7));
        data.writeInt(Integer.valueOf(entityId));
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    Packet250CustomPayload packet = new Packet250CustomPayload();
    packet.channel = "MoCreatures";
    packet.data = bytes.toByteArray();
    packet.length = packet.data.length;

    PacketDispatcher.sendPacketToPlayer(packet, (Player) player);
}
 
示例3
/**
 * Sends message to player
 * 
 * @param player
 * @param message
 */
public static void sendMsgToPlayer(EntityPlayerMP player, String message)
{
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(bytes);
    try
    {
        data.writeInt(Integer.valueOf(15));
        data.writeUTF(message);
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    Packet250CustomPayload packet = new Packet250CustomPayload();
    packet.channel = "MoCreatures";
    packet.data = bytes.toByteArray();
    packet.length = packet.data.length;

    PacketDispatcher.sendPacketToPlayer(packet, (Player) player);
}
 
示例4
public static void sendJoinUpdate(EntityPlayer player) {
    List<Object> tempList = new ArrayList<Object>();

    tempList.add(0, (byte) capes.size());

    for (String playerName : capes.keySet()) {
        tempList.add(playerName);
        tempList.add(capes.get(playerName));
    }

    PacketDispatcher.sendPacketToPlayer(PacketWrapper.createPacket(HexxitGear.modNetworkChannel, Packets.CapeJoin, tempList.toArray()), (Player) player);
}
 
示例5
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float offsetX, float offsetY, float offsetZ)
{
	if (!world.isRemote)
	{
		if (world.getBlockTileEntity(x, y, z) == null || player.isSneaking())
		{
			return false;
		}
		PacketDispatcher.sendPacketToPlayer(world.getBlockTileEntity(x, y, z).getDescriptionPacket(), (Player) player);
		player.openGui(Extracells.instance, 6, world, x, y, z);
	}
	return true;
}
 
示例6
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float offsetX, float offsetY, float offsetZ)
{
	if (!world.isRemote)
	{
		if (world.getBlockTileEntity(x, y, z) == null || player.isSneaking())
		{
			return false;
		}
		PacketDispatcher.sendPacketToPlayer(world.getBlockTileEntity(x, y, z).getDescriptionPacket(), (Player) player);
		player.openGui(Extracells.instance, 7, world, x, y, z);
	}
	return true;
}
 
示例7
public void updateGuiTile(String playername)
{
	Player player = (Player) worldObj.getPlayerEntityByName(playername);

	if (!worldObj.isRemote)
		PacketDispatcher.sendPacketToPlayer(getDescriptionPacket(), player);
}
 
示例8
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float offsetX, float offsetY, float offsetZ)
{
	if (!world.isRemote)
	{
		ItemStack currentItem = player.inventory.getCurrentItem();
		if (currentItem != null)
		{
			IMemoryCard card = Util.getAppEngApi().getMemoryCardHandler();
			TileEntity blockTE = world.getBlockTileEntity(x, y, z);

			if (card.isMemoryCard(currentItem))
			{
				if (player.isSneaking())
				{
					NBTTagCompound nbt = new NBTTagCompound();
					blockTE.writeToNBT(nbt);
					nbt.removeTag("x");
					nbt.removeTag("y");
					nbt.removeTag("z");
					blockTE.readFromNBT(nbt);
					card.setMemoryCardContents(currentItem, getUnlocalizedName() + ".name", nbt);
					player.sendChatToPlayer(new ChatMessageComponent().addText(StatCollector.translateToLocal("ChatMsg.SettingsSaved")));
					return true;
				} else if (card.getSettingsName(currentItem).equals(getUnlocalizedName() + ".name") || card.getSettingsName(currentItem).equals("AppEng.GuiITooltip.Blank"))
				{
					blockTE.readFromNBT(card.getData(currentItem));
					Packet description = blockTE.getDescriptionPacket();
					if (description != null)
						PacketDispatcher.sendPacketToAllPlayers(description);
					player.sendChatToPlayer(new ChatMessageComponent().addText(StatCollector.translateToLocal("ChatMsg.SettingsLoaded")));
					return true;
				} else
				{
					player.sendChatToPlayer(new ChatMessageComponent().addText(StatCollector.translateToLocal("ChatMsg.IncorrectDevice")));
					return true;
				}
			}
		}
		if (world.getBlockTileEntity(x, y, z) == null || player.isSneaking())
		{
			return false;
		}
		PacketDispatcher.sendPacketToPlayer(world.getBlockTileEntity(x, y, z).getDescriptionPacket(), (Player) player);
		player.openGui(Extracells.instance, 2, world, x, y, z);
	}
	return true;
}
 
示例9
/**
 * use an amount of power, in AE units
 * @param amount is in AE units ( 5 per MJ ), if you return false, the item should be dead and return false for hasPower
 * @param is 
 * @return
 */
boolean usePower( Player player, float amount, ItemStack is );
 
示例10
/**
 * gets the power status of the item.
 * @param is
 * @return returns true if there is any power left.
 */
boolean hasPower( Player player, ItemStack is );