Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.4.0 #23

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.4.0] - 2024-08-08

### Added

- Recipe transfer support for the Pattern Grid.

### Fixed

- Recipe transfer not prioritizing displayed item.

## [0.3.2] - 2024-07-26

### Fixed
Expand Down Expand Up @@ -50,7 +60,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Recipe transfer integration for the Crafting Grid.
- Grid / JEI search box synchronization options.

[Unreleased]: https://github.com/refinedmods/refinedstorage-jei-integration/compare/v0.3.2...HEAD
[Unreleased]: https://github.com/refinedmods/refinedstorage-jei-integration/compare/v0.4.0...HEAD

[0.4.0]: https://github.com/refinedmods/refinedstorage-jei-integration/compare/v0.3.2...v0.4.0

[0.3.2]: https://github.com/refinedmods/refinedstorage-jei-integration/compare/v0.3.1...v0.3.2

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Adds support for:
- Exclusion zones
- Ghost ingredient dragging
- Using the R/U keys on Grid slots and filtering slots
- Recipe transfer integration for the Crafting Grid
- Recipe transfer integration for the Crafting Grid and Pattern Grid
- Grid / JEI search box synchronization

## Links
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
refinedarchitectVersion=0.16.9
refinedstorageVersion=2.0.0-milestone.4.5
refinedstorageVersion=2.0.0-milestone.4.6
jeiVersion=19.4.0.28
minecraftVersion=1.21
# Gradle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

import mezz.jei.api.constants.RecipeTypes;
Expand Down Expand Up @@ -58,7 +57,7 @@ public IRecipeTransferError transferRecipe(final CraftingGridContainerMenu conta
}

private void doTransfer(final IRecipeSlotsView recipeSlots, final CraftingGridContainerMenu containerMenu) {
final List<List<ItemResource>> inputs = getInputs(recipeSlots);
final List<List<ItemResource>> inputs = SlotUtil.getItems(recipeSlots, RecipeIngredientRole.INPUT);
containerMenu.transferRecipe(inputs);
}

Expand All @@ -81,23 +80,4 @@ private boolean isAvailable(final ResourceList available, final IRecipeSlotView
}
return false;
}

private List<List<ItemResource>> getInputs(final IRecipeSlotsView recipeSlots) {
return recipeSlots.getSlotViews(RecipeIngredientRole.INPUT).stream().map(slotView -> {
final List<ItemStack> stacks = slotView.getItemStacks().collect(Collectors.toList());
prioritizeDisplayedStack(slotView, stacks);
return stacks.stream().map(ItemResource::ofItemStack).collect(Collectors.toList());
}).toList();
}

private void prioritizeDisplayedStack(final IRecipeSlotView slotView, final List<ItemStack> stacks) {
slotView.getDisplayedItemStack().ifPresent(displayed -> {
final int index = stacks.indexOf(displayed);
if (index > 0) {
return;
}
stacks.remove(index);
stacks.add(0, displayed);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.refinedmods.refinedstorage.jei.common;

import com.refinedmods.refinedstorage.common.api.RefinedStorageApi;
import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey;
import com.refinedmods.refinedstorage.common.support.AbstractBaseContainerMenu;
import com.refinedmods.refinedstorage.common.support.AbstractBaseScreen;
import com.refinedmods.refinedstorage.common.support.containermenu.AbstractResourceContainerMenu;
import com.refinedmods.refinedstorage.common.support.containermenu.FilterSlot;
import com.refinedmods.refinedstorage.common.support.containermenu.ResourceSlot;
import com.refinedmods.refinedstorage.common.support.packet.c2s.C2SPackets;

Expand All @@ -14,35 +15,61 @@
import mezz.jei.api.gui.handlers.IGhostIngredientHandler;
import mezz.jei.api.ingredients.ITypedIngredient;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

@SuppressWarnings("rawtypes")
class GhostIngredientHandler implements IGhostIngredientHandler<AbstractBaseScreen> {
@Override
public <I> List<Target<I>> getTargetsTyped(final AbstractBaseScreen screen,
final ITypedIngredient<I> ingredient,
final boolean doStart) {
if (screen.getMenu() instanceof AbstractResourceContainerMenu menu) {
if (screen.getMenu() instanceof AbstractBaseContainerMenu menu) {
return getTargets(screen, ingredient.getIngredient(), menu);
}
return Collections.emptyList();
}

private <I> List<Target<I>> getTargets(final AbstractBaseScreen screen,
final I ingredient,
final AbstractResourceContainerMenu menu) {
final AbstractBaseContainerMenu menu) {
final List<Target<I>> targets = new ArrayList<>();
RefinedStorageApi.INSTANCE.getIngredientConverter().convertToResource(ingredient).ifPresent(resource -> {
for (final ResourceSlot slot : menu.getResourceSlots()) {
if (slot.isFilter() && slot.isValid(resource)) {
final Rect2i bounds = getBounds(screen, slot);
targets.add(new TargetImpl<>(bounds, slot.index));
addResourceTargets(screen, ingredient, menu, targets);
addFilterTargets(screen, ingredient, menu, targets);
return targets;
}

private <I> void addResourceTargets(final AbstractBaseScreen screen,
final I ingredient,
final AbstractBaseContainerMenu menu,
final List<Target<I>> targets) {
if (menu instanceof AbstractResourceContainerMenu resourceMenu) {
RefinedStorageApi.INSTANCE.getIngredientConverter().convertToResource(ingredient).ifPresent(resource -> {
for (final ResourceSlot slot : resourceMenu.getResourceSlots()) {
if (slot.isActive() && slot.isFilter() && slot.isValid(resource)) {
final Rect2i bounds = getBounds(screen, slot);
targets.add(new TargetImpl<>(bounds, slot.index, true));
}
}
});
}
}

private <I> void addFilterTargets(final AbstractBaseScreen screen,
final I ingredient,
final AbstractBaseContainerMenu menu,
final List<Target<I>> targets) {
if (ingredient instanceof ItemStack stack) {
for (final Slot slot : menu.slots) {
if (slot instanceof FilterSlot filterSlot && filterSlot.isActive() && filterSlot.mayPlace(stack)) {
final Rect2i bounds = getBounds(screen, filterSlot);
targets.add(new TargetImpl<>(bounds, filterSlot.index, false));
}
}
});
return targets;
}
}

private Rect2i getBounds(final AbstractBaseScreen screen, final ResourceSlot slot) {
private Rect2i getBounds(final AbstractBaseScreen screen, final Slot slot) {
return new Rect2i(screen.getLeftPos() + slot.x, screen.getTopPos() + slot.y, 17, 17);
}

Expand All @@ -54,10 +81,12 @@ public void onComplete() {
private static class TargetImpl<I> implements Target<I> {
private final Rect2i area;
private final int slotIndex;
private final boolean resource;

TargetImpl(final Rect2i area, final int slotIndex) {
TargetImpl(final Rect2i area, final int slotIndex, final boolean resource) {
this.area = area;
this.slotIndex = slotIndex;
this.resource = resource;
}

@Override
Expand All @@ -67,11 +96,13 @@ public Rect2i getArea() {

@Override
public void accept(final I ingredient) {
RefinedStorageApi.INSTANCE.getIngredientConverter().convertToResource(ingredient).ifPresent(this::accept);
}

private void accept(final PlatformResourceKey resource) {
C2SPackets.sendResourceFilterSlotChange(resource, slotIndex);
if (resource) {
RefinedStorageApi.INSTANCE.getIngredientConverter().convertToResource(ingredient).ifPresent(
convertedResource -> C2SPackets.sendResourceFilterSlotChange(convertedResource, slotIndex)
);
} else if (ingredient instanceof ItemStack stack) {
C2SPackets.sendFilterSlotChange(stack, slotIndex);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Optional<IClickableIngredient<?>> getClickableIngredientUnderMouse(
if (resource == null) {
return Optional.empty();
}
final PlatformResourceKey underlyingResource = resource.getUnderlyingResource();
final PlatformResourceKey underlyingResource = resource.getResourceForRecipeMods();
if (underlyingResource == null) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.refinedmods.refinedstorage.jei.common;

import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey;
import com.refinedmods.refinedstorage.common.api.support.resource.RecipeModIngredientConverter;
import com.refinedmods.refinedstorage.common.support.resource.FluidResource;
Expand All @@ -24,6 +25,18 @@ public Optional<PlatformResourceKey> convertToResource(final Object ingredient)
return Optional.empty();
}

@Override
public Optional<ResourceAmount> convertToResourceAmount(final Object ingredient) {
final var fluid = Common.getPlatform().convertJeiIngredientToFluidAmount(ingredient);
if (fluid.isPresent()) {
return fluid;
}
if (ingredient instanceof ItemStack itemStack) {
return Optional.of(new ResourceAmount(ItemResource.ofItemStack(itemStack), itemStack.getCount()));
}
return Optional.empty();
}

@Override
@SuppressWarnings("deprecation")
public Optional<Object> convertToIngredient(final PlatformResourceKey resource) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.refinedmods.refinedstorage.jei.common;

import com.refinedmods.refinedstorage.common.autocrafting.PatternGridContainerMenu;
import com.refinedmods.refinedstorage.common.content.Menus;
import com.refinedmods.refinedstorage.common.support.resource.ItemResource;

import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;

import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;

class PatternGridCraftingRecipeTransferHandler implements
IRecipeTransferHandler<PatternGridContainerMenu, RecipeHolder<CraftingRecipe>> {
@Override
public Class<? extends PatternGridContainerMenu> getContainerClass() {
return PatternGridContainerMenu.class;
}

@Override
public Optional<MenuType<PatternGridContainerMenu>> getMenuType() {
return Optional.of(Menus.INSTANCE.getPatternGrid());
}

@Override
public RecipeType<RecipeHolder<CraftingRecipe>> getRecipeType() {
return RecipeTypes.CRAFTING;
}

@Override
@Nullable
public IRecipeTransferError transferRecipe(final PatternGridContainerMenu containerMenu,
final RecipeHolder<CraftingRecipe> recipe,
final IRecipeSlotsView recipeSlots,
final Player player,
final boolean maxTransfer,
final boolean doTransfer) {
if (doTransfer) {
final List<List<ItemResource>> inputs = SlotUtil.getItems(recipeSlots, RecipeIngredientRole.INPUT);
containerMenu.transferCraftingRecipe(inputs);
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.refinedmods.refinedstorage.jei.common;

import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.common.autocrafting.PatternGridContainerMenu;
import com.refinedmods.refinedstorage.common.content.Menus;

import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;

import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.crafting.RecipeHolder;

class PatternGridProcessingRecipeTransferHandler implements
IRecipeTransferHandler<PatternGridContainerMenu, RecipeHolder<?>> {
@Override
public Class<? extends PatternGridContainerMenu> getContainerClass() {
return PatternGridContainerMenu.class;
}

@Override
public Optional<MenuType<PatternGridContainerMenu>> getMenuType() {
return Optional.of(Menus.INSTANCE.getPatternGrid());
}

@Override
@SuppressWarnings({"DataFlowIssue"})
public RecipeType<RecipeHolder<?>> getRecipeType() {
return null; // universal transfer handler makes this null safe
}

@Override
@Nullable
public IRecipeTransferError transferRecipe(final PatternGridContainerMenu containerMenu,
final RecipeHolder<?> recipe,
final IRecipeSlotsView recipeSlots,
final Player player,
final boolean maxTransfer,
final boolean doTransfer) {
if (doTransfer) {
final List<List<ResourceAmount>> inputs = SlotUtil.getResources(recipeSlots, RecipeIngredientRole.INPUT);
final List<List<ResourceAmount>> outputs = SlotUtil.getResources(recipeSlots, RecipeIngredientRole.OUTPUT);
containerMenu.transferProcessingRecipe(inputs, outputs);
}
return null;
}
}
Loading
Loading