net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket Java Examples

The following examples show how to use net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket. 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: MachineHandledScreen.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private void sendSecurityUpdate(ConfigurableElectricMachineBlockEntity entity) {
    if (this.playerInventory.player.getUuid().equals(entity.getSecurity().getOwner()) || !entity.getSecurity().hasOwner()) {
        MinecraftClient.getInstance().getNetworkHandler().sendPacket(new CustomPayloadC2SPacket(new Identifier(Constants.MOD_ID, "security_update"),
                new PacketByteBuf(Unpooled.buffer())
                        .writeBlockPos(pos)
                        .writeEnumConstant(entity.getSecurity().getPublicity())
        ));
    } else {
        Galacticraft.logger.error("Tried to send security update when not the owner!");
    }
}
 
Example #2
Source File: MachineHandledScreen.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private void sendRedstoneUpdate(ConfigurableElectricMachineBlockEntity entity) {
    MinecraftClient.getInstance().getNetworkHandler().sendPacket(new CustomPayloadC2SPacket(new Identifier(Constants.MOD_ID, "redstone_update"),
            new PacketByteBuf(Unpooled.buffer())
                    .writeBlockPos(pos)
                    .writeEnumConstant(entity.getRedstoneState())
    ));
}
 
Example #3
Source File: PlayerInventoryScreenMixin.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true)
public void mouseClicked(double mouseX, double mouseY, int button, CallbackInfoReturnable<Boolean> ci) {
    if (PlayerInventoryGCScreen.isCoordinateBetween((int) Math.floor(mouseX), x + 30, x + 59)
            && PlayerInventoryGCScreen.isCoordinateBetween((int) Math.floor(mouseY), y - 26, y)) {
        this.client.getNetworkHandler().sendPacket(new CustomPayloadC2SPacket(new Identifier(Constants.MOD_ID, "open_gc_inv"), new PacketByteBuf(Unpooled.buffer(0))));
    }
}
 
Example #4
Source File: ClientNetworkHandler.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void respondHello()
{
    CarpetClient.getPlayer().networkHandler.sendPacket(new CustomPayloadC2SPacket(
            CarpetClient.CARPET_CHANNEL,
            (new PacketByteBuf(Unpooled.buffer())).writeVarInt(CarpetClient.HELLO).writeString(CarpetSettings.carpetVersion)
    ));
}
 
Example #5
Source File: ClientNetworkHandler.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void clientCommand(String command)
{
    CompoundTag tag = new CompoundTag();
    tag.putString("id", command);
    tag.putString("command", command);
    CompoundTag outer = new CompoundTag();
    outer.put("clientCommand", tag);
    CarpetClient.getPlayer().networkHandler.sendPacket(new CustomPayloadC2SPacket(
            CarpetClient.CARPET_CHANNEL,
            (new PacketByteBuf(Unpooled.buffer())).writeVarInt(CarpetClient.DATA).writeCompoundTag(outer)
    ));
}
 
Example #6
Source File: ServerPlayNetworkHandlerMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
private void onCustomCarpetPayload(CustomPayloadC2SPacket packet, CallbackInfo ci)
{
    Identifier channel = ((CustomPayloadC2SPacketInterface) packet).getPacketChannel();
    if (CarpetClient.CARPET_CHANNEL.equals(channel))
    {
        ServerNetworkHandler.handleData(((CustomPayloadC2SPacketInterface) packet).getPacketData(), player);
        ci.cancel();
    }
}
 
Example #7
Source File: MixinCustomPayload_NetworkHandler.java    From Galaxy with GNU Affero General Public License v3.0 5 votes vote down vote up
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
private void onCustomPayload(CustomPayloadC2SPacket packet, CallbackInfo info) {
    Main main = Main.Companion.getMain();
    if (main == null) return;

    Identifier channel = ((CustomPayloadC2SPacketAccessor) packet).getChannel();
    PacketByteBuf buff = ((CustomPayloadC2SPacketAccessor) packet).getData();
    main.getEventManager().emit(new PacketReceiveEvent(channel, buff, player));
}
 
Example #8
Source File: MixinServerPlayNetworkHandler.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
private void patchwork$hookCustomPayload(CustomPayloadC2SPacket packet, CallbackInfo callback) {
	if (NetworkHooks.onCustomPayload((ICustomPacket<?>) packet, getConnection())) {
		callback.cancel();
	}
}
 
Example #9
Source File: MixinCustomPayloadC2SPacket.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public CustomPayloadC2SPacket getThis() {
	return (CustomPayloadC2SPacket) (Object) this;
}
 
Example #10
Source File: CustomPayloadC2SPacketAccessor.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@SuppressWarnings("PublicStaticMixinMember")
@Invoker("<init>")
static CustomPayloadC2SPacket patchwork$create() {
	throw new AssertionError("Mixin not applied");
}