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;
}
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));
}
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));
});
}
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)));
});
}
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));
});
}
Aggregations