Search in sources :

Example 1 with SyncMaterialCraftingItemsPacket

use of net.silentchaos512.gear.network.SyncMaterialCraftingItemsPacket in project Silent-Gear by SilentChaos512.

the class SyncMaterialCraftingItemsPacket method decode.

public static SyncMaterialCraftingItemsPacket decode(FriendlyByteBuf buffer) {
    SyncMaterialCraftingItemsPacket packet = new SyncMaterialCraftingItemsPacket();
    int count = buffer.readVarInt();
    for (int i = 0; i < count; ++i) {
        packet.craftingItems.put(buffer.readResourceLocation(), Ingredient.fromNetwork(buffer));
    }
    int subCount = buffer.readVarInt();
    for (int i = 0; i < subCount; ++i) {
        Map<PartType, Ingredient> map = new HashMap<>();
        ResourceLocation id = buffer.readResourceLocation();
        int mapCount = buffer.readByte();
        for (int j = 0; j < mapCount; ++j) {
            PartType type = PartType.get(buffer.readResourceLocation());
            Ingredient ingredient = Ingredient.fromNetwork(buffer);
            map.put(type, ingredient);
        }
        packet.partSubs.put(id, map);
    }
    return packet;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) Ingredient(net.minecraft.world.item.crafting.Ingredient) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 2 with SyncMaterialCraftingItemsPacket

use of net.silentchaos512.gear.network.SyncMaterialCraftingItemsPacket in project Silent-Gear by SilentChaos512.

the class ServerEvents method onPlayerJoinServer.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onPlayerJoinServer(PlayerEvent.PlayerLoggedInEvent event) {
    Player player = event.getPlayer();
    if (!(player instanceof ServerPlayer))
        return;
    ServerPlayer playerMP = (ServerPlayer) player;
    // Send crafting items packets to correct for registry changes
    SilentGear.LOGGER.debug("Sending materials crafting item correction packet");
    Network.channel.sendTo(new SyncMaterialCraftingItemsPacket(MaterialManager.getValues()), playerMP.connection.connection, NetworkDirection.PLAY_TO_CLIENT);
    SilentGear.LOGGER.debug("Sending parts crafting item correction packet");
    Network.channel.sendTo(new SyncGearCraftingItemsPacket(), playerMP.connection.connection, NetworkDirection.PLAY_TO_CLIENT);
    TraitManager.getErrorMessages(playerMP).forEach(text -> playerMP.sendMessage(text, Util.NIL_UUID));
    MaterialManager.getErrorMessages(playerMP).forEach(text -> playerMP.sendMessage(text, Util.NIL_UUID));
    PartManager.getErrorMessages(playerMP).forEach(text -> playerMP.sendMessage(text, Util.NIL_UUID));
}
Also used : Player(net.minecraft.world.entity.player.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) SyncGearCraftingItemsPacket(net.silentchaos512.gear.network.SyncGearCraftingItemsPacket) ServerPlayer(net.minecraft.server.level.ServerPlayer) SyncMaterialCraftingItemsPacket(net.silentchaos512.gear.network.SyncMaterialCraftingItemsPacket) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

ResourceLocation (net.minecraft.resources.ResourceLocation)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 Player (net.minecraft.world.entity.player.Player)1 Ingredient (net.minecraft.world.item.crafting.Ingredient)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 PartType (net.silentchaos512.gear.api.part.PartType)1 SyncGearCraftingItemsPacket (net.silentchaos512.gear.network.SyncGearCraftingItemsPacket)1 SyncMaterialCraftingItemsPacket (net.silentchaos512.gear.network.SyncMaterialCraftingItemsPacket)1