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;
}
}
}
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;
});
}
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;
}
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);
}
Aggregations