Search in sources :

Example 1 with AbstractCompatibilityModule

use of top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule in project Polymorph by TheIllusiveC4.

the class PolymorphNetwork method handleStackSelect.

private static void handleStackSelect(MinecraftServer pServer, ServerPlayerEntity pPlayer, ServerPlayNetworkHandler pHandler, PacketByteBuf pBuf, PacketSender pResponseSender) {
    Identifier identifier = pBuf.readIdentifier();
    pServer.execute(() -> {
        World world = pPlayer.getEntityWorld();
        Optional<? extends Recipe<?>> maybeRecipe = world.getRecipeManager().get(identifier);
        maybeRecipe.ifPresent(recipe -> {
            ScreenHandler screenHandler = pPlayer.currentScreenHandler;
            PolymorphApi.common().getRecipeDataFromBlockEntity(screenHandler).ifPresent(recipeData -> {
                recipeData.selectRecipe(recipe);
                for (AbstractCompatibilityModule integration : PolymorphIntegrations.get()) {
                    if (integration.selectRecipe(screenHandler, recipe)) {
                        return;
                    }
                }
            });
        });
    });
}
Also used : Identifier(net.minecraft.util.Identifier) ForgingScreenHandler(net.minecraft.screen.ForgingScreenHandler) ScreenHandler(net.minecraft.screen.ScreenHandler) AbstractCompatibilityModule(top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule) World(net.minecraft.world.World)

Example 2 with AbstractCompatibilityModule

use of top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule in project Polymorph by TheIllusiveC4.

the class CommonEventsListener method openScreenHandler.

public static void openScreenHandler(ServerPlayerEntity player) {
    ScreenHandler screenHandler = player.currentScreenHandler;
    PolymorphCommon commonApi = PolymorphApi.common();
    commonApi.getRecipeDataFromBlockEntity(screenHandler).ifPresent(recipeData -> {
        PolymorphPacketDistributor packetDistributor = commonApi.getPacketDistributor();
        if (recipeData.isFailing() || recipeData.isEmpty(null)) {
            packetDistributor.sendRecipesListS2C(player);
        } else {
            Pair<SortedSet<RecipePair>, Identifier> data = recipeData.getPacketData();
            packetDistributor.sendRecipesListS2C(player, data.getLeft(), data.getRight());
        }
    });
    for (AbstractCompatibilityModule integration : PolymorphIntegrations.get()) {
        if (integration.openScreenHandler(screenHandler, player)) {
            return;
        }
    }
}
Also used : Identifier(net.minecraft.util.Identifier) PolymorphPacketDistributor(top.theillusivec4.polymorph.api.common.base.PolymorphPacketDistributor) ScreenHandler(net.minecraft.screen.ScreenHandler) AbstractCompatibilityModule(top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule) PolymorphCommon(top.theillusivec4.polymorph.api.common.base.PolymorphCommon) SortedSet(java.util.SortedSet)

Example 3 with AbstractCompatibilityModule

use of top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule in project Polymorph by TheIllusiveC4.

the class CPacketPlayerRecipeSelection method handle.

public static void handle(CPacketPlayerRecipeSelection pPacket, Supplier<NetworkEvent.Context> pContext) {
    pContext.get().enqueueWork(() -> {
        ServerPlayer sender = pContext.get().getSender();
        if (sender != null) {
            AbstractContainerMenu container = sender.containerMenu;
            sender.level.getRecipeManager().byKey(pPacket.recipe).ifPresent(recipe -> {
                PolymorphApi.common().getRecipeData(sender).ifPresent(recipeData -> recipeData.selectRecipe(recipe));
                for (AbstractCompatibilityModule integration : PolymorphIntegrations.get()) {
                    if (integration.selectRecipe(container, recipe)) {
                        return;
                    }
                }
                container.slotsChanged(sender.getInventory());
                if (container instanceof ItemCombinerMenu) {
                    ((ItemCombinerMenu) container).createResult();
                }
            });
        }
    });
    pContext.get().setPacketHandled(true);
}
Also used : AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) AbstractCompatibilityModule(top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule) ItemCombinerMenu(net.minecraft.world.inventory.ItemCombinerMenu)

Example 4 with AbstractCompatibilityModule

use of top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule in project Polymorph by TheIllusiveC4.

the class CPacketStackRecipeSelection method handle.

public static void handle(CPacketStackRecipeSelection pPacket, Supplier<NetworkEvent.Context> pContext) {
    pContext.get().enqueueWork(() -> {
        ServerPlayer sender = pContext.get().getSender();
        if (sender != null) {
            Level world = sender.getCommandSenderWorld();
            Optional<? extends Recipe<?>> maybeRecipe = world.getRecipeManager().byKey(pPacket.recipe);
            maybeRecipe.ifPresent(recipe -> {
                AbstractContainerMenu container = sender.containerMenu;
                PolymorphApi.common().getRecipeDataFromItemStack(container).ifPresent(recipeData -> {
                    recipeData.selectRecipe(recipe);
                    for (AbstractCompatibilityModule integration : PolymorphIntegrations.get()) {
                        if (integration.selectRecipe(container, recipe)) {
                            return;
                        }
                    }
                });
            });
        }
    });
    pContext.get().setPacketHandled(true);
}
Also used : AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) Level(net.minecraft.world.level.Level) AbstractCompatibilityModule(top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule)

Example 5 with AbstractCompatibilityModule

use of top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule in project Polymorph by TheIllusiveC4.

the class PolymorphNetwork method handlePersistentSelect.

private static void handlePersistentSelect(MinecraftServer pServer, ServerPlayerEntity pPlayer, ServerPlayNetworkHandler pHandler, PacketByteBuf pBuf, PacketSender pResponseSender) {
    Identifier identifier = pBuf.readIdentifier();
    pServer.execute(() -> {
        World world = pPlayer.getEntityWorld();
        Optional<? extends Recipe<?>> maybeRecipe = world.getRecipeManager().get(identifier);
        maybeRecipe.ifPresent(recipe -> {
            ScreenHandler screenHandler = pPlayer.currentScreenHandler;
            PolymorphApi.common().getRecipeDataFromBlockEntity(screenHandler).ifPresent(recipeData -> {
                recipeData.selectRecipe(recipe);
                for (AbstractCompatibilityModule integration : PolymorphIntegrations.get()) {
                    if (integration.selectRecipe(recipeData.getOwner(), recipe) || integration.selectRecipe(screenHandler, recipe)) {
                        return;
                    }
                }
            });
        });
    });
}
Also used : Identifier(net.minecraft.util.Identifier) ForgingScreenHandler(net.minecraft.screen.ForgingScreenHandler) ScreenHandler(net.minecraft.screen.ScreenHandler) AbstractCompatibilityModule(top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule) World(net.minecraft.world.World)

Aggregations

AbstractCompatibilityModule (top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule)7 ScreenHandler (net.minecraft.screen.ScreenHandler)4 Identifier (net.minecraft.util.Identifier)4 ForgingScreenHandler (net.minecraft.screen.ForgingScreenHandler)3 ServerPlayer (net.minecraft.server.level.ServerPlayer)3 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)3 World (net.minecraft.world.World)2 Level (net.minecraft.world.level.Level)2 SortedSet (java.util.SortedSet)1 ItemCombinerMenu (net.minecraft.world.inventory.ItemCombinerMenu)1 PolymorphCommon (top.theillusivec4.polymorph.api.common.base.PolymorphCommon)1 PolymorphPacketDistributor (top.theillusivec4.polymorph.api.common.base.PolymorphPacketDistributor)1