Search in sources :

Example 1 with ConfigSyncMessage

use of com.wuest.prefab.proxy.messages.ConfigSyncMessage in project MC-Prefab by Brian-Wuest.

the class ModEventHandler method onPlayerLoginEvent.

/**
 * This event occurs when a player logs in. This is used to send server configuration to the client.
 * @param event The event object.
 */
@SubscribeEvent
public static void onPlayerLoginEvent(PlayerLoggedInEvent event) {
    if (!event.player.world.isRemote) {
        NBTTagCompound tag = Prefab.proxy.proxyConfiguration.ToNBTTagCompound();
        Prefab.network.sendTo(new ConfigSyncMessage(tag), (EntityPlayerMP) event.player);
        System.out.println("Sent config to '" + event.player.getDisplayNameString() + ".'");
    }
}
Also used : ConfigSyncMessage(com.wuest.prefab.Proxy.Messages.ConfigSyncMessage) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with ConfigSyncMessage

use of com.wuest.prefab.proxy.messages.ConfigSyncMessage in project MC-Prefab by Brian-Wuest.

the class ModEventHandler method onPlayerLoginEvent.

/**
 * This event occurs when a player logs in. This is used to send server configuration to the client.
 *
 * @param event The event object.
 */
@SubscribeEvent
public static void onPlayerLoginEvent(PlayerLoggedInEvent event) {
    if (!event.getPlayer().level.isClientSide) {
        CompoundTag tag = CommonProxy.proxyConfiguration.serverConfiguration.ToNBTTagCompound();
        Prefab.network.sendTo(new ConfigSyncMessage(tag), ((ServerPlayer) event.getPlayer()).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
        Prefab.LOGGER.info("Sent config to '" + event.getPlayer().getDisplayName().getString() + "'.");
    }
}
Also used : ConfigSyncMessage(com.wuest.prefab.proxy.messages.ConfigSyncMessage) ServerPlayer(net.minecraft.server.level.ServerPlayer) CompoundTag(net.minecraft.nbt.CompoundTag) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with ConfigSyncMessage

use of com.wuest.prefab.proxy.messages.ConfigSyncMessage in project MC-Prefab by Brian-Wuest.

the class ModRegistry method RegisterMessages.

/**
 * This is where the mod messages are registered.
 */
public static void RegisterMessages() {
    AtomicInteger index = new AtomicInteger();
    Prefab.network.messageBuilder(ConfigSyncMessage.class, index.getAndIncrement()).encoder(ConfigSyncMessage::encode).decoder(ConfigSyncMessage::decode).consumer(ConfigSyncHandler::handle).add();
    Prefab.network.messageBuilder(PlayerEntityTagMessage.class, index.getAndIncrement()).encoder(PlayerEntityTagMessage::encode).decoder(PlayerEntityTagMessage::decode).consumer(PlayerEntityHandler::handle).add();
    Prefab.network.messageBuilder(StructureTagMessage.class, index.getAndIncrement()).encoder(StructureTagMessage::encode).decoder(StructureTagMessage::decode).consumer(StructureHandler::handle).add();
    Prefab.network.messageBuilder(StructureScannerActionMessage.class, index.getAndIncrement()).encoder(StructureScannerActionMessage::encode).decoder(StructureScannerActionMessage::decode).consumer(StructureScannerActionHandler::handle).add();
    Prefab.network.messageBuilder(StructureScannerSyncMessage.class, index.getAndIncrement()).encoder(StructureScannerSyncMessage::encode).decoder(StructureScannerSyncMessage::decode).consumer(StructureScannerSyncHandler::handle).add();
}
Also used : PlayerEntityTagMessage(com.wuest.prefab.proxy.messages.PlayerEntityTagMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConfigSyncMessage(com.wuest.prefab.proxy.messages.ConfigSyncMessage)

Aggregations

ConfigSyncMessage (com.wuest.prefab.proxy.messages.ConfigSyncMessage)2 ConfigSyncMessage (com.wuest.prefab.Proxy.Messages.ConfigSyncMessage)1 PlayerEntityTagMessage (com.wuest.prefab.proxy.messages.PlayerEntityTagMessage)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1