Search in sources :

Example 1 with RecipeData

use of top.theillusivec4.polymorph.api.common.component.RecipeData in project Polymorph by TheIllusiveC4.

the class AbstractBlockEntityRecipeData method getListeners.

@Override
public Set<ServerPlayer> getListeners() {
    Level world = this.getOwner().getLevel();
    Set<ServerPlayer> players = new HashSet<>();
    if (world instanceof ServerLevel) {
        for (ServerPlayer player : ((ServerLevel) world).getPlayers((serverPlayer -> true))) {
            PolymorphApi.common().getRecipeDataFromTileEntity(player.containerMenu).ifPresent(recipeData -> {
                if (recipeData == this) {
                    players.add(player);
                }
            });
        }
    }
    return players;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) SortedSet(java.util.SortedSet) Set(java.util.Set) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) ServerLevel(net.minecraft.server.level.ServerLevel) Pair(com.mojang.datafixers.util.Pair) HashSet(java.util.HashSet) IBlockEntityRecipeData(top.theillusivec4.polymorph.api.common.capability.IBlockEntityRecipeData) ServerPlayer(net.minecraft.server.level.ServerPlayer) Container(net.minecraft.world.Container) IRecipePair(top.theillusivec4.polymorph.api.common.base.IRecipePair) NonNullList(net.minecraft.core.NonNullList) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) PolymorphApi(top.theillusivec4.polymorph.api.PolymorphApi) ServerLevel(net.minecraft.server.level.ServerLevel) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) HashSet(java.util.HashSet)

Example 2 with RecipeData

use of top.theillusivec4.polymorph.api.common.component.RecipeData 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 3 with RecipeData

use of top.theillusivec4.polymorph.api.common.component.RecipeData in project Polymorph by TheIllusiveC4.

the class PlayerRecipesWidget method selectRecipe.

@Override
public void selectRecipe(ResourceLocation pResourceLocation) {
    IPolymorphCommon commonApi = PolymorphApi.common();
    Player player = Minecraft.getInstance().player;
    if (player != null) {
        player.level.getRecipeManager().byKey(pResourceLocation).ifPresent(recipe -> commonApi.getRecipeData(player).ifPresent(recipeData -> recipeData.selectRecipe(recipe)));
    }
    commonApi.getPacketDistributor().sendPlayerRecipeSelectionC2S(pResourceLocation);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Slot(net.minecraft.world.inventory.Slot) AbstractRecipesWidget(top.theillusivec4.polymorph.api.client.widget.AbstractRecipesWidget) Minecraft(net.minecraft.client.Minecraft) AbstractContainerScreen(net.minecraft.client.gui.screens.inventory.AbstractContainerScreen) PolymorphApi(top.theillusivec4.polymorph.api.PolymorphApi) IPolymorphCommon(top.theillusivec4.polymorph.api.common.base.IPolymorphCommon) Player(net.minecraft.world.entity.player.Player) Player(net.minecraft.world.entity.player.Player) IPolymorphCommon(top.theillusivec4.polymorph.api.common.base.IPolymorphCommon)

Example 4 with RecipeData

use of top.theillusivec4.polymorph.api.common.component.RecipeData 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 5 with RecipeData

use of top.theillusivec4.polymorph.api.common.component.RecipeData 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)

Aggregations

AbstractCompatibilityModule (top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule)7 Identifier (net.minecraft.util.Identifier)6 ServerPlayer (net.minecraft.server.level.ServerPlayer)5 ScreenHandler (net.minecraft.screen.ScreenHandler)4 HashSet (java.util.HashSet)3 ForgingScreenHandler (net.minecraft.screen.ForgingScreenHandler)3 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)3 Level (net.minecraft.world.level.Level)3 PolymorphApi (top.theillusivec4.polymorph.api.PolymorphApi)3 PolymorphCommon (top.theillusivec4.polymorph.api.common.base.PolymorphCommon)3 SortedSet (java.util.SortedSet)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 World (net.minecraft.world.World)2 AbstractRecipesWidget (top.theillusivec4.polymorph.api.client.widget.AbstractRecipesWidget)2 IPolymorphCommon (top.theillusivec4.polymorph.api.common.base.IPolymorphCommon)2 Pair (com.mojang.datafixers.util.Pair)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Minecraft (net.minecraft.client.Minecraft)1 MinecraftClient (net.minecraft.client.MinecraftClient)1