Search in sources :

Example 1 with PolymorphCommon

use of top.theillusivec4.polymorph.api.common.base.PolymorphCommon 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 2 with PolymorphCommon

use of top.theillusivec4.polymorph.api.common.base.PolymorphCommon in project Polymorph by TheIllusiveC4.

the class PolymorphMod method onInitialize.

@Override
public void onInitialize() {
    PolymorphNetwork.setup();
    PolymorphCommands.setup();
    CommonEventsListener.setup();
    PolymorphIntegrations.init();
    PolymorphIntegrations.setup();
    PolymorphCommon commonApi = PolymorphApi.common();
    commonApi.registerBlockEntity2RecipeData(AbstractFurnaceBlockEntity.class, blockEntity -> new FurnaceRecipeData((AbstractFurnaceBlockEntity) blockEntity));
    commonApi.registerScreenHandler2BlockEntity(container -> {
        for (Slot inventorySlot : container.slots) {
            Inventory inventory = inventorySlot.inventory;
            if (inventory instanceof BlockEntity) {
                return (BlockEntity) inventory;
            }
        }
        return null;
    });
}
Also used : AbstractFurnaceBlockEntity(net.minecraft.block.entity.AbstractFurnaceBlockEntity) FurnaceRecipeData(top.theillusivec4.polymorph.common.component.FurnaceRecipeData) Slot(net.minecraft.screen.slot.Slot) PolymorphCommon(top.theillusivec4.polymorph.api.common.base.PolymorphCommon) Inventory(net.minecraft.inventory.Inventory) BlockEntity(net.minecraft.block.entity.BlockEntity) AbstractFurnaceBlockEntity(net.minecraft.block.entity.AbstractFurnaceBlockEntity)

Example 3 with PolymorphCommon

use of top.theillusivec4.polymorph.api.common.base.PolymorphCommon in project Polymorph by TheIllusiveC4.

the class StackRecipeDataImpl method getListeners.

@Override
public Set<ServerPlayerEntity> getListeners() {
    Set<ServerPlayerEntity> players = new HashSet<>();
    PolymorphCommon commonApi = PolymorphApi.common();
    commonApi.getServer().ifPresent(server -> {
        for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
            commonApi.getRecipeDataFromItemStack(player.currentScreenHandler).ifPresent(recipeData -> {
                if (recipeData == this) {
                    players.add(player);
                }
            });
        }
    });
    return players;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) PolymorphCommon(top.theillusivec4.polymorph.api.common.base.PolymorphCommon) HashSet(java.util.HashSet)

Example 4 with PolymorphCommon

use of top.theillusivec4.polymorph.api.common.base.PolymorphCommon in project Polymorph by TheIllusiveC4.

the class PlayerRecipesWidget method selectRecipe.

@Override
public void selectRecipe(Identifier pIdentifier) {
    PolymorphCommon commonApi = PolymorphApi.common();
    PlayerEntity player = MinecraftClient.getInstance().player;
    if (player != null) {
        player.world.getRecipeManager().get(pIdentifier).ifPresent(recipe -> commonApi.getRecipeData(player).ifPresent(recipeData -> recipeData.selectRecipe(recipe)));
    }
    commonApi.getPacketDistributor().sendPlayerRecipeSelectionC2S(pIdentifier);
}
Also used : AbstractRecipesWidget(top.theillusivec4.polymorph.api.client.widget.AbstractRecipesWidget) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) PolymorphApi(top.theillusivec4.polymorph.api.PolymorphApi) Slot(net.minecraft.screen.slot.Slot) PolymorphCommon(top.theillusivec4.polymorph.api.common.base.PolymorphCommon) HandledScreen(net.minecraft.client.gui.screen.ingame.HandledScreen) PolymorphCommon(top.theillusivec4.polymorph.api.common.base.PolymorphCommon) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

PolymorphCommon (top.theillusivec4.polymorph.api.common.base.PolymorphCommon)4 Slot (net.minecraft.screen.slot.Slot)2 Identifier (net.minecraft.util.Identifier)2 HashSet (java.util.HashSet)1 SortedSet (java.util.SortedSet)1 AbstractFurnaceBlockEntity (net.minecraft.block.entity.AbstractFurnaceBlockEntity)1 BlockEntity (net.minecraft.block.entity.BlockEntity)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 HandledScreen (net.minecraft.client.gui.screen.ingame.HandledScreen)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 Inventory (net.minecraft.inventory.Inventory)1 ScreenHandler (net.minecraft.screen.ScreenHandler)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 PolymorphApi (top.theillusivec4.polymorph.api.PolymorphApi)1 AbstractRecipesWidget (top.theillusivec4.polymorph.api.client.widget.AbstractRecipesWidget)1 PolymorphPacketDistributor (top.theillusivec4.polymorph.api.common.base.PolymorphPacketDistributor)1 FurnaceRecipeData (top.theillusivec4.polymorph.common.component.FurnaceRecipeData)1 AbstractCompatibilityModule (top.theillusivec4.polymorph.common.integration.AbstractCompatibilityModule)1