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