net.minecraftforge.fml.network.NetworkEvent Java Examples
The following examples show how to use
net.minecraftforge.fml.network.NetworkEvent.
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: PacketExtractUpgrade.java From MiningGadgets with MIT License | 6 votes |
public static void handle(PacketExtractUpgrade msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; World world = player.world; BlockPos pos = msg.pos; TileEntity te = world.getTileEntity(pos); if (!(te instanceof ModificationTableTileEntity)) return; ModificationTableContainer container = ((ModificationTableTileEntity) te).getContainer(player); ModificationTableCommands.extractButton(container, player, msg.upgrade); }); ctx.get().setPacketHandled(true); }
Example #2
Source File: PacketChangeColor.java From MiningGadgets with MIT License | 6 votes |
public static void handle(PacketChangeColor msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); MiningProperties.setColor(stack, msg.red, MiningProperties.COLOR_RED); MiningProperties.setColor(stack, msg.green, MiningProperties.COLOR_GREEN); MiningProperties.setColor(stack, msg.blue, MiningProperties.COLOR_BLUE); MiningProperties.setColor(stack, msg.red_inner, MiningProperties.COLOR_RED_INNER); MiningProperties.setColor(stack, msg.green_inner, MiningProperties.COLOR_GREEN_INNER); MiningProperties.setColor(stack, msg.blue_inner, MiningProperties.COLOR_BLUE_INNER); }); ctx.get().setPacketHandled(true); }
Example #3
Source File: IndexedMessageCodec.java From patchwork-api with GNU Lesser General Public License v2.1 | 6 votes |
void consume(PacketByteBuf payload, int payloadIndex, NetworkEvent.Context context) { if (payload == null) { LOGGER.error(SIMPLENET, "Received empty payload on channel {}", channelName); return; } short discriminator = payload.readUnsignedByte(); final MessageHandler<?> messageHandler = indices.get(discriminator); if (messageHandler == null) { LOGGER.error(SIMPLENET, "Received invalid discriminator byte {} on channel {}", discriminator, channelName); return; } tryDecode(payload, context, payloadIndex, messageHandler); }
Example #4
Source File: PacketGhostSlot.java From MiningGadgets with MIT License | 6 votes |
public static void handle(PacketGhostSlot msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity sender = ctx.get().getSender(); if (sender == null) return; Container container = sender.openContainer; if (container == null) return; Slot slot = container.inventorySlots.get(msg.slotNumber); if (slot instanceof GhostSlot) slot.putStack(msg.stack); }); ctx.get().setPacketHandled(true); }
Example #5
Source File: PacketUpdateUpgrade.java From MiningGadgets with MIT License | 6 votes |
public static void handle(PacketUpdateUpgrade msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; Upgrade upgrade = UpgradeTools.getUpgradeByName(msg.upgrade); if( upgrade == null ) return; ItemStack stack = MiningGadget.getGadget(player); UpgradeTools.updateUpgrade(stack, upgrade); //todo: change. }); ctx.get().setPacketHandled(true); }
Example #6
Source File: SimpleChannel.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
/** * Function returning a boolean "packet handled" indication, for simpler channel building. * @param handler a handler * @return this */ public MessageBuilder<M> consumer(ToBooleanBiFunction<M, Supplier<NetworkEvent.Context>> handler) { this.consumer = (message, context) -> { boolean handled = handler.applyAsBool(message, context); context.get().setPacketHandled(handled); }; return this; }
Example #7
Source File: PacketOpenFilterContainer.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketOpenFilterContainer msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity sender = ctx.get().getSender(); if (sender == null) return; Container container = sender.openContainer; if (container == null) return; ItemStack stack = MiningGadget.getGadget(sender); if( stack.isEmpty() ) return; ItemStackHandler ghostInventory = new ItemStackHandler(30) { @Override protected void onContentsChanged(int slot) { stack.getOrCreateTag().put(MiningProperties.KEY_FILTERS, serializeNBT()); } }; ghostInventory.deserializeNBT(stack.getOrCreateChildTag(MiningProperties.KEY_FILTERS)); sender.openContainer(new SimpleNamedContainerProvider( (windowId, playerInventory, playerEntity) -> new FilterContainer(windowId, playerInventory, ghostInventory), new StringTextComponent("") )); }); ctx.get().setPacketHandled(true); }
Example #8
Source File: PacketChangeMiningSize.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketChangeMiningSize msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); MiningGadget.changeRange(stack); }); ctx.get().setPacketHandled(true); }
Example #9
Source File: PacketChangeVolume.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketChangeVolume msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); // Active toggle feature MiningProperties.setVolume(stack, msg.volume); }); ctx.get().setPacketHandled(true); }
Example #10
Source File: PacketChangeFreezeDelay.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketChangeFreezeDelay msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); // Active toggle feature MiningProperties.setFreezeDelay(stack, msg.freezeDelay); }); ctx.get().setPacketHandled(true); }
Example #11
Source File: PacketChangeBreakType.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketChangeBreakType msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); MiningProperties.nextBreakType(stack); }); ctx.get().setPacketHandled(true); }
Example #12
Source File: PacketChangeRange.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketChangeRange msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); MiningProperties.setBeamRange(stack, msg.range); }); ctx.get().setPacketHandled(true); }
Example #13
Source File: PacketToggleFilters.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketToggleFilters msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); // Active toggle feature MiningProperties.setWhitelist(stack, !MiningProperties.getWhiteList(stack)); }); ctx.get().setPacketHandled(true); }
Example #14
Source File: PacketTogglePrecision.java From MiningGadgets with MIT License | 5 votes |
public static void handle(PacketTogglePrecision msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity player = ctx.get().getSender(); if (player == null) return; ItemStack stack = MiningGadget.getGadget(player); // Active toggle feature MiningProperties.setPrecisionMode(stack, !MiningProperties.getPrecisionMode(stack)); }); ctx.get().setPacketHandled(true); }
Example #15
Source File: LoginPacketHandler.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void handleLoginPacket(PacketCustom packet, Minecraft mc, IClientLoginNetHandler handler, NetworkEvent.Context context) { switch (packet.getType()) { case L_CONFIG_SYNC: { ConfigSyncManager.readSyncPacket(packet); break; } } }
Example #16
Source File: PacketCustomChannelBuilder.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@SubscribeEvent public void onClientPayload(NetworkEvent.ServerCustomPayloadEvent event) { if (event instanceof NetworkEvent.ServerCustomPayloadLoginEvent) { return; } PacketCustom packet = new PacketCustom(event.getPayload()); NetworkEvent.Context ctx = event.getSource().get(); INetHandler netHandler = ctx.getNetworkManager().getNetHandler(); ctx.setPacketHandled(true); if (netHandler instanceof ClientPlayNetHandler) { ClientPlayNetHandler nh = (ClientPlayNetHandler) netHandler; ctx.enqueueWork(() -> packetHandler.handlePacket(packet, Minecraft.getInstance(), nh)); } }
Example #17
Source File: IndexedMessageCodec.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
MessageHandler(int index, Class<M> messageType, BiConsumer<M, PacketByteBuf> encoder, Function<PacketByteBuf, M> decoder, BiConsumer<M, Supplier<NetworkEvent.Context>> messageConsumer) { this.index = index; this.messageType = messageType; this.encoder = encoder; this.decoder = decoder; this.messageConsumer = messageConsumer; this.loginIndexGetter = null; this.loginIndexSetter = null; indices.put((short) (index & 0xff), this); types.put(messageType, this); }
Example #18
Source File: PacketCustomChannelBuilder.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@SubscribeEvent public void onServerPayload(NetworkEvent.ClientCustomPayloadEvent event) { PacketCustom packet = new PacketCustom(event.getPayload()); NetworkEvent.Context ctx = event.getSource().get(); INetHandler netHandler = ctx.getNetworkManager().getNetHandler(); ctx.setPacketHandled(true); if (netHandler instanceof ServerPlayNetHandler) { ServerPlayNetHandler nh = (ServerPlayNetHandler) netHandler; ctx.enqueueWork(() -> packetHandler.handlePacket(packet, nh.player, nh)); } }
Example #19
Source File: PacketCustomChannelBuilder.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@SubscribeEvent public void onGatherLoginPayloads(NetworkEvent.GatherLoginPayloadsEvent event) { packetHandler.gatherLoginPackets((ctx, packetSupplier) -> { PacketCustom packet = packetSupplier.get(); event.add(packet.toPacketBuffer(), packet.getChannel(), ctx); }); }
Example #20
Source File: PacketCustomChannelBuilder.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@SubscribeEvent public void onClientPayload(NetworkEvent.LoginPayloadEvent event) { PacketCustom packet = new PacketCustom(event.getPayload()); NetworkEvent.Context ctx = event.getSource().get(); INetHandler netHandler = ctx.getNetworkManager().getNetHandler(); ctx.setPacketHandled(true); if (netHandler instanceof ClientLoginNetHandler) { ClientLoginNetHandler nh = (ClientLoginNetHandler) netHandler; packetHandler.handleLoginPacket(packet, Minecraft.getInstance(), nh, ctx); //For _some_ reason sending this response packet in FML is private. So just spoof the packet :D ctx.getPacketDispatcher().sendPacket(new ResourceLocation("fml:handshake"), new PacketBuffer(Unpooled.buffer().writeByte(99))); } }
Example #21
Source File: ScrapingMessage.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void handle(Supplier<NetworkEvent.Context> ctx) { ClientEvents.handleScrapingMessage(this); }
Example #22
Source File: PacketDurabilitySync.java From MiningGadgets with MIT License | 4 votes |
public static void handle(PacketDurabilitySync msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> clientPacketHandler(msg))); ctx.get().setPacketHandled(true); }
Example #23
Source File: EventNetworkChannel.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void onPacket(final ICustomPacket<?> packet, final NetworkEvent.Context context) { this.networkEventBus.post(packet.getDirection().getEvent(packet, () -> context)); }
Example #24
Source File: PacketHandler.java From MiningGadgets with MIT License | 4 votes |
private static <MSG> void registerMessage(Class<MSG> messageType, BiConsumer<MSG, PacketBuffer> encoder, Function<PacketBuffer, MSG> decoder, BiConsumer<MSG, Supplier<NetworkEvent.Context>> messageConsumer) { HANDLER.registerMessage(index, messageType, encoder, decoder, messageConsumer); index++; if (index > 0xFF) throw new RuntimeException("Too many messages!"); }
Example #25
Source File: SimpleChannel.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
public <M> void reply(M msgToReply, NetworkEvent.Context context) { context.getPacketDispatcher().sendPacket(channelName, toBuffer(msgToReply).getLeft()); }
Example #26
Source File: SimpleChannel.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
public <M> IndexedMessageCodec.MessageHandler<M> registerMessage(int index, Class<M> messageType, BiConsumer<M, PacketByteBuf> encoder, Function<PacketByteBuf, M> decoder, BiConsumer<M, Supplier<NetworkEvent.Context>> messageConsumer) { return this.indexedCodec.addCodecIndex(index, messageType, encoder, decoder, messageConsumer); }
Example #27
Source File: SimpleChannel.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void onRegistrationChange(NetworkEvent.ChannelRegistrationChangeEvent event) { // No-op }
Example #28
Source File: SimpleChannel.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void onPacket(ICustomPacket<?> packet, NetworkEvent.Context context) { this.indexedCodec.consume(packet.getInternalData(), packet.getIndex(), context); }
Example #29
Source File: IndexedMessageCodec.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
<M> MessageHandler<M> addCodecIndex(int index, Class<M> messageType, BiConsumer<M, PacketByteBuf> encoder, Function<PacketByteBuf, M> decoder, BiConsumer<M, Supplier<NetworkEvent.Context>> messageConsumer) { return new MessageHandler<>(index, messageType, encoder, decoder, messageConsumer); }
Example #30
Source File: EventNetworkChannel.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
public <T extends NetworkEvent> void addListener(Consumer<T> eventListener) { this.networkEventBus.addListener(eventListener); }