-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: ghost ingredients
- Loading branch information
Showing
37 changed files
with
612 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...m/refinedmods/refinedstorage2/platform/api/integration/recipemod/IngredientConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package com.refinedmods.refinedstorage2.platform.api.integration.recipemod; | ||
|
||
import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; | ||
|
||
import java.util.Optional; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.5") | ||
public interface IngredientConverter { | ||
Optional<Object> convertToResource(Object ingredient); | ||
Optional<ResourceTemplate<?>> convertToResource(Object ingredient); | ||
|
||
Optional<Object> convertToIngredient(Object resource); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...ods/refinedstorage2/platform/common/integration/recipemod/jei/GhostIngredientHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.refinedmods.refinedstorage2.platform.common.integration.recipemod.jei; | ||
|
||
import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; | ||
import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; | ||
import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; | ||
import com.refinedmods.refinedstorage2.platform.common.Platform; | ||
import com.refinedmods.refinedstorage2.platform.common.containermenu.AbstractResourceContainerMenu; | ||
import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ResourceSlot; | ||
import com.refinedmods.refinedstorage2.platform.common.screen.AbstractBaseScreen; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import mezz.jei.api.gui.handlers.IGhostIngredientHandler; | ||
import mezz.jei.api.ingredients.ITypedIngredient; | ||
import net.minecraft.client.renderer.Rect2i; | ||
|
||
@SuppressWarnings("rawtypes") | ||
public class GhostIngredientHandler implements IGhostIngredientHandler<AbstractBaseScreen> { | ||
private final IngredientConverter ingredientConverter; | ||
|
||
public GhostIngredientHandler(final IngredientConverter ingredientConverter) { | ||
this.ingredientConverter = ingredientConverter; | ||
} | ||
|
||
@Override | ||
public <I> List<Target<I>> getTargetsTyped(final AbstractBaseScreen screen, | ||
final ITypedIngredient<I> ingredient, | ||
final boolean doStart) { | ||
if (screen.getMenu() instanceof AbstractResourceContainerMenu 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 List<Target<I>> targets = new ArrayList<>(); | ||
ingredientConverter.convertToResource(ingredient).ifPresent(resource -> { | ||
for (final ResourceSlot slot : menu.getResourceSlots()) { | ||
if (slot.isFilter() && slot.isValid(resource.resource())) { | ||
final Rect2i bounds = getBounds(screen, slot); | ||
targets.add(new TargetImpl<>(bounds, slot.index)); | ||
} | ||
} | ||
}); | ||
return targets; | ||
} | ||
|
||
private Rect2i getBounds(final AbstractBaseScreen screen, final ResourceSlot slot) { | ||
return new Rect2i(screen.getLeftPos() + slot.x, screen.getTopPos() + slot.y, 17, 17); | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
// no op | ||
} | ||
|
||
private class TargetImpl<I> implements Target<I> { | ||
private final Rect2i area; | ||
private final int slotIndex; | ||
|
||
TargetImpl(final Rect2i area, final int slotIndex) { | ||
this.area = area; | ||
this.slotIndex = slotIndex; | ||
} | ||
|
||
@Override | ||
public Rect2i getArea() { | ||
return area; | ||
} | ||
|
||
@Override | ||
public void accept(final I ingredient) { | ||
ingredientConverter.convertToResource(ingredient).ifPresent(this::accept); | ||
} | ||
|
||
private <T> void accept(final ResourceTemplate<T> resource) { | ||
Platform.INSTANCE.getClientToServerCommunications().sendResourceFilterSlotChange( | ||
(PlatformStorageChannelType<T>) resource.storageChannelType(), | ||
resource.resource(), | ||
slotIndex | ||
); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.