本文整理汇总了Java中cpw.mods.fml.common.network.PacketDispatcher.sendPacketToPlayer方法的典型用法代码示例。如果您正苦于以下问题:Java PacketDispatcher.sendPacketToPlayer方法的具体用法?Java PacketDispatcher.sendPacketToPlayer怎么用?Java PacketDispatcher.sendPacketToPlayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cpw.mods.fml.common.network.PacketDispatcher
的用法示例。
在下文中一共展示了PacketDispatcher.sendPacketToPlayer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LifePacketSender
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
public static void LifePacketSender(double radiation, String name) {
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try {
outputStream.writeDouble(radiation);
} catch (Exception ex) {
ex.printStackTrace();
}
Packet250CustomPayload packet_sender = new Packet250CustomPayload();
packet_sender.channel = "Apocalyptic-rad";
packet_sender.data = bos.toByteArray();
packet_sender.length = bos.size();
if (side == Side.SERVER) {
PacketDispatcher.sendPacketToPlayer(packet_sender, getPlayer(name));
}
}
示例2: sendCarvingData
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
public void sendCarvingData(byte[] carvingData, Player player)
{
try
{
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(17);
DataOutputStream dataStream = new DataOutputStream(byteStream);
dataStream.writeByte(PacketHandler.CARVING_DATA);
dataStream.writeInt(this.entityId);
dataStream.writeInt(carvingData.length);
dataStream.write(carvingData);
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = PacketHandler.CHANNEL_NAME;
packet.data = byteStream.toByteArray();
packet.length = packet.data.length;
PacketDispatcher.sendPacketToPlayer(packet, player);
}
catch(Throwable tt)
{
tt.printStackTrace();
}
}
示例3: processCommand
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void processCommand(final ICommandSender icommandsender,
final String[] astring) {
try {
PacketCommandBase p = null;
if (astring.length == 1) {
p = createPacket(astring[0]);
}
if (p != null) {
PacketDispatcher.sendPacketToPlayer(p.write(),
(Player) getCommandSenderAsPlayer(icommandsender));
}
} catch (final Exception e) {
FMLLog.log(VoiceChat.MOD_ID, Level.SEVERE, e, "");
}
}
示例4: doSpellCasterEffect
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
@Override
public void doSpellCasterEffect(EntityPlayer caster)
{
caster.worldObj.playSoundAtEntity(caster, "mob.enderdragon.wings", 1.0F, 1.0F);
if (caster.onGround)
{
caster.motionY += 1.0D;
}
caster.fallDistance = 0;
caster.capabilities.allowFlying = true;
caster.capabilities.isFlying = true;
SpellboundCore.getInstance().addActiveSpellToEntity(caster, this, 400);
PacketDispatcher.sendPacketToPlayer(PacketHandler.createFlightPacket(true), (Player) caster);
}
示例5: interactEvent
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
/**
* For catching interactions with the Undertaker
*/
@ForgeSubscribe
public void interactEvent(EntityInteractEvent event)
{
if (event.target instanceof EntityVillager && ((EntityVillager) event.target).getProfession() == BurialServices.getConfig().villagerID)
{
if (FMLCommonHandler.instance().getSide().isServer())
{
PacketDispatcher.sendPacketToPlayer(NetworkHelper.makeNBTPacket(BSConstants.CHANNEL_GRAVE_UPGRADE, MiscHelper.getPersistentDataTag(event.entityPlayer, BSConstants.NBT_PLAYER_GRAVE_DATA)), (Player) event.entityPlayer);
}
event.setCanceled(MinecraftServer.getServer().isSinglePlayer());
FMLNetworkHandler.openGui(event.entityPlayer, BurialServices.instance, GuiHandler.undertakerID, event.entityPlayer.worldObj, 0, 0, 0);
}
}
示例6: serverSendPacket
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
@Deprecated
public static void serverSendPacket(NetServerHandler handler, Packet packet)
{
if (handler != null)
{
PacketDispatcher.sendPacketToPlayer(packet, (Player)handler.getPlayer());
}
}
示例7: playerLoggedIn
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
@Override
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
{
Packet250CustomPayload[] fluidPackets = ForgePacket.makePacketSet(new FluidIdMapPacket());
for (int i = 0; i < fluidPackets.length; i++) {
PacketDispatcher.sendPacketToPlayer(fluidPackets[i], player);
}
}
示例8: onBlockActivated
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
@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;
}
示例9: onPlayerLogin
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
@Override
public void onPlayerLogin(EntityPlayer player)
{
try
{
//Setup a stream for the new packet
ByteArrayOutputStream streambyte = new ByteArrayOutputStream();
DataOutputStream stream = new DataOutputStream(streambyte);
try
{
//add the serverKey to validate
stream.writeUTF("VALIDATE");
}
finally
{
//close our streams
stream.close();
streambyte.close();
}
//send the packet
PacketDispatcher.sendPacketToPlayer(new Packet250CustomPayload(Strings.packetChannel, streambyte.toByteArray()), (Player)player);
}
//catch ALL exceptions
catch (Exception e)
{
e.printStackTrace();
}
}
示例10: sendBarsPacket
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
public static void sendBarsPacket(EntityPlayer player)
{
float[] essenceValues = EssenceBar.bars().ratios.get(player.username);
float[] essenceDefaults = EssenceBar.bars().defaultRatios.get(player.username);
float essenceLevel = EssenceBar.bars().levels.get(player.username);
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try
{
outputStream.writeUTF(player.username);
for(int i = 0; i < 5; i++)
outputStream.writeFloat(essenceValues[i]);
for(int i = 0; i < 5; i++)
outputStream.writeFloat(essenceDefaults[i]);
outputStream.writeFloat(essenceLevel);
}
catch (Exception ex)
{
ex.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "Essence";
packet.data = bos.toByteArray();
packet.length = bos.size();
PacketDispatcher.sendPacketToPlayer(packet, (Player)player);
}
示例11: updateGuiTile
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
public void updateGuiTile(String playername)
{
Player player = (Player) worldObj.getPlayerEntityByName(playername);
if (!worldObj.isRemote)
PacketDispatcher.sendPacketToPlayer(getDescriptionPacket(), player);
}
示例12: sendGrenadePacket
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
public void sendGrenadePacket(World world, EntityGrenade grenade,
String var, Object arg) {
try {
ByteArrayOutputStream baout = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baout);
out.writeByte(grenadePacketID);
out.writeInt(world.provider.dimensionId);
out.writeInt(grenade.entityId);
out.writeUTF(var);
if (var.equals("parent")) {
out.writeInt(((Entity) arg).entityId);
} else if (var.equals("homing")) {
out.writeBoolean((Boolean) arg);
}
out.close();
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "bl2";
packet.isChunkDataPacket = false;
packet.data = baout.toByteArray();
packet.length = baout.size();
@SuppressWarnings("unchecked")
Iterator<EntityPlayer> players = world.playerEntities.iterator();
while (players.hasNext()) {
EntityPlayer player = players.next();
if (player.getDistanceSqToEntity(grenade) < 64.0D) {
PacketDispatcher
.sendPacketToPlayer(packet, (Player) player);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例13: sendJoinUpdate
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
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);
}
示例14: sync
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
public final void sync()
{
byte[] whichBytetoSend = {PacketHandler.EXTENDED_PROPERTIES, PacketHandler.EXTENDED_SPEC, PacketHandler.EXTENDED_STATS, PacketHandler.EXTENDED_CHAIN};
float currentStats[] = this.getStats();
for(int i=0; i<whichBytetoSend.length;i++){
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try {
switch(i){
case 0:
outputStream.writeByte(whichBytetoSend[i]);
outputStream.writeInt(this.currentJob);
break;
case 1:
outputStream.writeByte(whichBytetoSend[i]);
outputStream.writeInt(this.currentSpecialization);
break;
case 2:
outputStream.writeByte(whichBytetoSend[i]);
for(int j=0;j<4;j++){
outputStream.writeFloat(currentStats[j]);
}
outputStream.writeInt(this.levelUpPoints);
outputStream.writeInt(this.level);
outputStream.writeInt(this.level);
outputStream.writeInt(this.currentMateriaSelected);
break;
case 3:
outputStream.writeByte(whichBytetoSend[i]);
outputStream.writeInt(this.chainLevel);
outputStream.writeChars(this.lastEntityKilled);
break;
default: break;
}
} catch (Exception ex) {
ex.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload("GenericClass", bos.toByteArray());
// We only want to send from the server to the client
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
EntityPlayerMP player1 = (EntityPlayerMP) player;
PacketDispatcher.sendPacketToPlayer(packet, (Player) player1);
}
}
}
示例15: updateEntity
import cpw.mods.fml.common.network.PacketDispatcher; //导入方法依赖的package包/类
@Override
public void updateEntity()
{
super.updateEntity();
if (worldObj.isRemote) return;
debug(this);
// Initialize code
if (craftSlot == null)
{
internalPlayer = new InternalPlayer();
craftSlot = new SlotCrafting(internalPlayer, inventoryIn, inventoryOut, xCoord, yCoord, zCoord);
}
boolean willCraft = true;
// Lower tick rate
tick++;
if (AutoCrafter2000.getConfig().craftDelay != 0 && tick % AutoCrafter2000.getConfig().craftDelay != 0) willCraft = false;
else tick = 0;
debug("tickDelay", willCraft);
// Redstone things
boolean powered = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
if (redstoneMode == 0 && powered) willCraft = false;
if (redstoneMode == 1 && !powered) willCraft = false;
debug("powered", powered);
// Deal with overflow. If we couldn't empty, don't make new stuff.
emptyOverflow();
if (!overflow.isEmpty()) willCraft = false;
debug("overflow.isEmpty", overflow.isEmpty());
debug("recipe", recipe);
ItemStack result = null;
if (willCraft && recipe == null) willCraft = false;
if (willCraft && !recipe.matches(inventoryIn, worldObj)) willCraft = false;
debug("matches", willCraft);
if (willCraft && (result = recipe.getCraftingResult(inventoryIn)) == null) willCraft = false;
debug("result", result);
if (willCraft && !InventoryHelper.hasSpaceFor(inventoryOut, result)) willCraft = false;
debug("spacefor", willCraft);
if (willCraft)
{
crafts++;
result = result.copy(); // Won't be null cause then willCraft would have been false.
if (AutoCrafter2000.getConfig().updateCraftCountLive) for (EntityPlayer player : players)
PacketDispatcher.sendPacketToPlayer(PacketDispatcher.getPacket(CHANNEL_RMU, Joiner.on(";").join(this.xCoord, this.yCoord, this.zCoord, this.redstoneMode, this.crafts).getBytes()), (cpw.mods.fml.common.network.Player) player);
// Craft!
craftSlot.onPickupFromSlot(internalPlayer, result);
// Overflow handling
ItemStack stack = InventoryHelper.addToInventory(inventoryOut, result);
if (stack != null) overflow.add(stack);
debug("overflowFromCrafting", stack);
for (int i = 0; i < internalPlayer.inventory.getSizeInventory(); i++)
{
stack = InventoryHelper.addToInventory(inventoryOut, internalPlayer.inventory.getStackInSlotOnClosing(i));
if (stack != null) overflow.add(stack);
}
debug("overflow.size", overflow.size());
}
else reBalanceSlots(); // If we can't / won't craft, we rebalanced 1 slot.
if (debugTicks > 0) debugTicks --;
debug("debugTicks", debugTicks);
}