Search in sources :

Example 1 with RecipesWidget

use of top.theillusivec4.polymorph.api.client.base.RecipesWidget in project Polymorph by TheIllusiveC4.

the class PolymorphClientNetwork method sendRecipesList.

private static void sendRecipesList(MinecraftClient pClient, ClientPlayNetworkHandler pHandler, PacketByteBuf pBuf, PacketSender pSender) {
    SortedSet<RecipePair> recipeDataset = new TreeSet<>();
    Identifier selected = null;
    if (pBuf.isReadable()) {
        int size = pBuf.readInt();
        for (int i = 0; i < size; i++) {
            recipeDataset.add(new RecipePairImpl(pBuf.readIdentifier(), pBuf.readItemStack()));
        }
        if (pBuf.isReadable()) {
            selected = pBuf.readIdentifier();
        }
    }
    Identifier finalSelected = selected;
    pClient.execute(() -> {
        ClientPlayerEntity player = pClient.player;
        if (player != null) {
            Optional<RecipesWidget> maybeWidget = RecipesWidgetControl.get();
            maybeWidget.ifPresent(widget -> widget.setRecipesList(recipeDataset, finalSelected));
            if (!maybeWidget.isPresent()) {
                RecipesWidgetControl.enqueueRecipesList(recipeDataset, finalSelected);
            }
        }
    });
}
Also used : Identifier(net.minecraft.util.Identifier) RecipePair(top.theillusivec4.polymorph.api.common.base.RecipePair) TreeSet(java.util.TreeSet) RecipePairImpl(top.theillusivec4.polymorph.common.impl.RecipePairImpl) RecipesWidget(top.theillusivec4.polymorph.api.client.base.RecipesWidget) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity)

Aggregations

TreeSet (java.util.TreeSet)1 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)1 Identifier (net.minecraft.util.Identifier)1 RecipesWidget (top.theillusivec4.polymorph.api.client.base.RecipesWidget)1 RecipePair (top.theillusivec4.polymorph.api.common.base.RecipePair)1 RecipePairImpl (top.theillusivec4.polymorph.common.impl.RecipePairImpl)1