-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also adds support for ghost dragging the new filter slots.
- Loading branch information
1 parent
eb9465f
commit 5057d39
Showing
11 changed files
with
261 additions
and
18 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
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
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 | ||
emiVersion=1.1.10+1.21 | ||
# Gradle | ||
org.gradle.jvmargs=-Xmx1G |
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
92 changes: 92 additions & 0 deletions
92
...mon/src/main/java/com/refinedmods/refinedstorage/emi/common/FilterEmiDragDropHandler.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,92 @@ | ||
package com.refinedmods.refinedstorage.emi.common; | ||
|
||
import com.refinedmods.refinedstorage.common.support.AbstractBaseContainerMenu; | ||
import com.refinedmods.refinedstorage.common.support.AbstractBaseScreen; | ||
import com.refinedmods.refinedstorage.common.support.containermenu.FilterSlot; | ||
import com.refinedmods.refinedstorage.common.support.packet.c2s.C2SPackets; | ||
|
||
import dev.emi.emi.api.EmiDragDropHandler; | ||
import dev.emi.emi.api.stack.EmiIngredient; | ||
import dev.emi.emi.api.stack.ItemEmiStack; | ||
import dev.emi.emi.runtime.EmiDrawContext; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraft.world.inventory.Slot; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
class FilterEmiDragDropHandler implements EmiDragDropHandler<Screen> { | ||
@Override | ||
public boolean dropStack(final Screen screen, final EmiIngredient stack, final int x, final int y) { | ||
if (!(screen instanceof AbstractBaseScreen<?> baseScreen)) { | ||
return false; | ||
} | ||
if (!(baseScreen.getMenu() instanceof AbstractBaseContainerMenu menu)) { | ||
return false; | ||
} | ||
if (!(stack instanceof ItemEmiStack emiStack)) { | ||
return false; | ||
} | ||
return dropStack(menu, baseScreen, emiStack.getItemStack(), x, y); | ||
} | ||
|
||
private boolean dropStack(final AbstractBaseContainerMenu menu, | ||
final AbstractBaseScreen<?> baseScreen, | ||
final ItemStack stack, | ||
final int x, | ||
final int y) { | ||
for (final Slot slot : menu.slots) { | ||
if (slot instanceof FilterSlot filterSlot && dropStack(stack, filterSlot, x, y, baseScreen)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private boolean dropStack(final ItemStack stack, | ||
final FilterSlot slot, | ||
final int x, | ||
final int y, | ||
final AbstractBaseScreen<?> baseScreen) { | ||
if (!isSlotValid(stack, slot)) { | ||
return false; | ||
} | ||
final int slotX = baseScreen.getLeftPos() + slot.x; | ||
final int slotY = baseScreen.getTopPos() + slot.y; | ||
if (x < slotX || y < slotY || x > slotX + 16 || y > slotY + 16) { | ||
return false; | ||
} | ||
C2SPackets.sendFilterSlotChange(stack, slot.index); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void render(final Screen screen, | ||
final EmiIngredient dragged, | ||
final GuiGraphics draw, | ||
final int mouseX, | ||
final int mouseY, | ||
final float delta) { | ||
if (!(screen instanceof AbstractBaseScreen<?> baseScreen)) { | ||
return; | ||
} | ||
if (!(baseScreen.getMenu() instanceof AbstractBaseContainerMenu menu)) { | ||
return; | ||
} | ||
if (dragged.isEmpty() || !(dragged.getEmiStacks().getFirst() instanceof ItemEmiStack emiStack)) { | ||
return; | ||
} | ||
final ItemStack stack = emiStack.getItemStack(); | ||
final EmiDrawContext context = EmiDrawContext.wrap(draw); | ||
for (final Slot slot : menu.slots) { | ||
if (!(slot instanceof FilterSlot filterSlot) || !isSlotValid(stack, filterSlot)) { | ||
continue; | ||
} | ||
context.fill(baseScreen.getLeftPos() + slot.x, baseScreen.getTopPos() + slot.y, 17, 17, 0x8822BB33); | ||
} | ||
} | ||
|
||
private static boolean isSlotValid(final ItemStack stack, final FilterSlot slot) { | ||
return slot.isActive() && slot.mayPlace(stack); | ||
} | ||
} | ||
|
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
122 changes: 122 additions & 0 deletions
122
.../src/main/java/com/refinedmods/refinedstorage/emi/common/PatternGridEmiRecipeHandler.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,122 @@ | ||
package com.refinedmods.refinedstorage.emi.common; | ||
|
||
import com.refinedmods.refinedstorage.api.resource.ResourceAmount; | ||
import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; | ||
import com.refinedmods.refinedstorage.common.autocrafting.PatternGridContainerMenu; | ||
import com.refinedmods.refinedstorage.common.support.resource.ItemResource; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import dev.emi.emi.api.recipe.EmiPlayerInventory; | ||
import dev.emi.emi.api.recipe.EmiRecipe; | ||
import dev.emi.emi.api.recipe.VanillaEmiRecipeCategories; | ||
import dev.emi.emi.api.recipe.handler.EmiCraftContext; | ||
import dev.emi.emi.api.recipe.handler.EmiRecipeHandler; | ||
import dev.emi.emi.api.stack.EmiIngredient; | ||
import dev.emi.emi.api.stack.EmiStack; | ||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; | ||
|
||
class PatternGridEmiRecipeHandler implements EmiRecipeHandler<PatternGridContainerMenu> { | ||
@Override | ||
public EmiPlayerInventory getInventory(final AbstractContainerScreen<PatternGridContainerMenu> screen) { | ||
return new EmiPlayerInventory(List.of()); | ||
} | ||
|
||
@Override | ||
public boolean supportsRecipe(final EmiRecipe recipe) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean canCraft(final EmiRecipe recipe, final EmiCraftContext<PatternGridContainerMenu> context) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean craft(final EmiRecipe recipe, final EmiCraftContext<PatternGridContainerMenu> context) { | ||
if (recipe.getCategory() == VanillaEmiRecipeCategories.CRAFTING) { | ||
transferCraftingRecipe(recipe, context); | ||
} else if (recipe.getCategory() == VanillaEmiRecipeCategories.STONECUTTING) { | ||
transferStonecutterRecipe(recipe, context); | ||
} else if (recipe.getCategory() == VanillaEmiRecipeCategories.SMITHING) { | ||
transferSmithingTableRecipe(recipe, context); | ||
} else { | ||
transferProcessingRecipe(recipe, context); | ||
} | ||
return true; | ||
} | ||
|
||
private void transferCraftingRecipe(final EmiRecipe recipe, | ||
final EmiCraftContext<PatternGridContainerMenu> context) { | ||
final List<List<ItemResource>> inputs = recipe.getInputs() | ||
.stream() | ||
.map(this::getItems) | ||
.toList(); | ||
context.getScreenHandler().transferCraftingRecipe(inputs); | ||
} | ||
|
||
private void transferStonecutterRecipe(final EmiRecipe recipe, | ||
final EmiCraftContext<PatternGridContainerMenu> context) { | ||
final List<List<ItemResource>> inputs = recipe.getInputs() | ||
.stream() | ||
.map(this::getItems) | ||
.toList(); | ||
final List<List<ItemResource>> outputs = recipe.getOutputs() | ||
.stream() | ||
.map(this::getItems) | ||
.toList(); | ||
if (!inputs.isEmpty() && !outputs.isEmpty() && !inputs.getFirst().isEmpty() && !outputs.getFirst().isEmpty()) { | ||
context.getScreenHandler().transferStonecutterRecipe( | ||
inputs.getFirst().getFirst(), | ||
outputs.getFirst().getFirst() | ||
); | ||
} | ||
} | ||
|
||
private void transferSmithingTableRecipe(final EmiRecipe recipe, | ||
final EmiCraftContext<PatternGridContainerMenu> context) { | ||
final List<List<ItemResource>> inputs = recipe.getInputs() | ||
.stream() | ||
.map(this::getItems) | ||
.toList(); | ||
if (inputs.size() == 3) { | ||
context.getScreenHandler().transferSmithingTableRecipe( | ||
inputs.getFirst(), | ||
inputs.get(1), | ||
inputs.get(2) | ||
); | ||
} | ||
} | ||
|
||
private List<ItemResource> getItems(final EmiIngredient ingredient) { | ||
return ingredient.getEmiStacks() | ||
.stream() | ||
.map(EmiStack::getItemStack) | ||
.filter(stack -> !stack.isEmpty()) | ||
.map(ItemResource::ofItemStack) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private void transferProcessingRecipe(final EmiRecipe recipe, | ||
final EmiCraftContext<PatternGridContainerMenu> context) { | ||
final List<List<ResourceAmount>> inputs = recipe.getInputs() | ||
.stream() | ||
.map(this::getResources) | ||
.toList(); | ||
final List<List<ResourceAmount>> outputs = recipe.getOutputs() | ||
.stream() | ||
.map(this::getResources) | ||
.toList(); | ||
context.getScreenHandler().transferProcessingRecipe(inputs, outputs); | ||
} | ||
|
||
|
||
private List<ResourceAmount> getResources(final EmiIngredient ingredient) { | ||
return ingredient.getEmiStacks() | ||
.stream() | ||
.flatMap(emiStack -> RefinedStorageApi.INSTANCE.getIngredientConverter().convertToResourceAmount(emiStack) | ||
.stream()) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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