cpw.mods.fml.common.network.Player Java Examples

The following examples show how to use cpw.mods.fml.common.network.Player. 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: MoCServerPacketHandler.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
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);

}
 
Example #2
Source File: MoCServerPacketHandler.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 
 * @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);
}
 
Example #3
Source File: MoCServerPacketHandler.java    From mocreaturesdev with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: CapeHandler.java    From HexxitGear with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #5
Source File: BlockLevelEmitterFluid.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@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;
}
 
Example #6
Source File: BlockInterFaceFluid.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@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;
}
 
Example #7
Source File: TileEntityMEBattery.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public void updateGuiTile(String playername)
{
	Player player = (Player) worldObj.getPlayerEntityByName(playername);

	if (!worldObj.isRemote)
		PacketDispatcher.sendPacketToPlayer(getDescriptionPacket(), player);
}
 
Example #8
Source File: BlockBusFluidStorage.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@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;
}
 
Example #9
Source File: IWirelessTermHandler.java    From ExtraCells1 with MIT License 2 votes vote down vote up
/**
 * 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 );
 
Example #10
Source File: IWirelessTermHandler.java    From ExtraCells1 with MIT License 2 votes vote down vote up
/**
 * gets the power status of the item.
 * @param is
 * @return returns true if there is any power left.
 */
boolean hasPower( Player player, ItemStack is );