Search in sources :

Example 1 with Context

use of net.minecraftforge.fml.network.NetworkEvent.Context in project BetterDiving by Meldexun.

the class CPacketOpenSeamothInventory method handle.

@Override
public boolean handle(Supplier<Context> ctxSupplier) {
    ctxSupplier.get().enqueueWork(() -> {
        PlayerEntity player = ctxSupplier.get().getSender();
        Entity entity = player.getVehicle();
        if (entity instanceof EntitySeamoth) {
            player.openMenu(new SimpleNamedContainerProvider((id, playerInv, player1) -> {
                return new ContainerSeamothEntity(id, playerInv, (EntitySeamoth) entity);
            }, new TranslationTextComponent("Seamoth")));
        }
    });
    return true;
}
Also used : IPacket(meldexun.better_diving.network.packet.IPacket) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ContainerSeamothEntity(meldexun.better_diving.inventory.container.ContainerSeamothEntity) Context(net.minecraftforge.fml.network.NetworkEvent.Context) SimpleNamedContainerProvider(net.minecraft.inventory.container.SimpleNamedContainerProvider) Supplier(java.util.function.Supplier) EntitySeamoth(meldexun.better_diving.entity.EntitySeamoth) PacketBuffer(net.minecraft.network.PacketBuffer) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ContainerSeamothEntity(meldexun.better_diving.inventory.container.ContainerSeamothEntity) ContainerSeamothEntity(meldexun.better_diving.inventory.container.ContainerSeamothEntity) SimpleNamedContainerProvider(net.minecraft.inventory.container.SimpleNamedContainerProvider) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) EntitySeamoth(meldexun.better_diving.entity.EntitySeamoth) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 2 with Context

use of net.minecraftforge.fml.network.NetworkEvent.Context in project Random-Things by lumien231.

the class IRTMessage method enqueue.

public default void enqueue(Supplier<Context> sup) {
    Context ctx = sup.get();
    ctx.enqueueWork(() -> handle(ctx));
}
Also used : Context(net.minecraftforge.fml.network.NetworkEvent.Context)

Example 3 with Context

use of net.minecraftforge.fml.network.NetworkEvent.Context in project minecolonies by Minecolonies.

the class NetworkChannel method setupInternalMessages.

private void setupInternalMessages() {
    rawChannel.registerMessage(0, SplitPacketMessage.class, IMessage::toBytes, (buf) -> {
        final SplitPacketMessage msg = new SplitPacketMessage();
        msg.fromBytes(buf);
        return msg;
    }, (msg, ctxIn) -> {
        final Context ctx = ctxIn.get();
        final LogicalSide packetOrigin = ctx.getDirection().getOriginationSide();
        ctx.setPacketHandled(true);
        msg.onExecute(ctx, packetOrigin.equals(LogicalSide.CLIENT));
    });
}
Also used : SplitPacketMessage(com.minecolonies.coremod.network.messages.splitting.SplitPacketMessage) Context(net.minecraftforge.fml.network.NetworkEvent.Context) IMessage(com.minecolonies.api.network.IMessage) LogicalSide(net.minecraftforge.fml.LogicalSide)

Example 4 with Context

use of net.minecraftforge.fml.network.NetworkEvent.Context in project Structurize by ldtteam.

the class NetworkChannel method registerMessage.

/**
 * Register a message into rawChannel.
 *
 * @param <MSG>    message class type
 * @param id       network id
 * @param msgClazz message class
 */
private <MSG extends IMessage> void registerMessage(final int id, final Class<MSG> msgClazz, final Function<PacketBuffer, MSG> initializer) {
    rawChannel.registerMessage(id, msgClazz, IMessage::toBytes, initializer, (msg, ctxIn) -> {
        final Context ctx = ctxIn.get();
        final LogicalSide packetOrigin = ctx.getDirection().getOriginationSide();
        ctx.setPacketHandled(true);
        if (msg.getExecutionSide() != null && packetOrigin.equals(msg.getExecutionSide())) {
            Log.getLogger().warn("Receving {} at wrong side!", msg.getClass().getName());
            return;
        }
        // boolean param MUST equals true if packet arrived at logical server
        ctx.enqueueWork(() -> msg.onExecute(ctx, packetOrigin.equals(LogicalSide.CLIENT)));
    });
}
Also used : Context(net.minecraftforge.fml.network.NetworkEvent.Context) LogicalSide(net.minecraftforge.fml.LogicalSide)

Example 5 with Context

use of net.minecraftforge.fml.network.NetworkEvent.Context in project minecolonies by ldtteam.

the class NetworkChannel method setupInternalMessages.

private void setupInternalMessages() {
    rawChannel.registerMessage(0, SplitPacketMessage.class, IMessage::toBytes, (buf) -> {
        final SplitPacketMessage msg = new SplitPacketMessage();
        msg.fromBytes(buf);
        return msg;
    }, (msg, ctxIn) -> {
        final Context ctx = ctxIn.get();
        final LogicalSide packetOrigin = ctx.getDirection().getOriginationSide();
        ctx.setPacketHandled(true);
        msg.onExecute(ctx, packetOrigin.equals(LogicalSide.CLIENT));
    });
}
Also used : SplitPacketMessage(com.minecolonies.coremod.network.messages.splitting.SplitPacketMessage) Context(net.minecraftforge.fml.network.NetworkEvent.Context) IMessage(com.minecolonies.api.network.IMessage) LogicalSide(net.minecraftforge.fml.LogicalSide)

Aggregations

Context (net.minecraftforge.fml.network.NetworkEvent.Context)5 LogicalSide (net.minecraftforge.fml.LogicalSide)3 IMessage (com.minecolonies.api.network.IMessage)2 SplitPacketMessage (com.minecolonies.coremod.network.messages.splitting.SplitPacketMessage)2 Supplier (java.util.function.Supplier)1 EntitySeamoth (meldexun.better_diving.entity.EntitySeamoth)1 ContainerSeamothEntity (meldexun.better_diving.inventory.container.ContainerSeamothEntity)1 IPacket (meldexun.better_diving.network.packet.IPacket)1 Entity (net.minecraft.entity.Entity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 SimpleNamedContainerProvider (net.minecraft.inventory.container.SimpleNamedContainerProvider)1 PacketBuffer (net.minecraft.network.PacketBuffer)1 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1