Added the ability to filter inputs on a slot so it only accepts valid items
This commit is contained in:
parent
751746df6f
commit
3b69a1a143
3 changed files with 26 additions and 2 deletions
|
@ -48,6 +48,9 @@ public class CheckBoxElement extends ElementBase {
|
|||
if(type.equalsIgnoreCase("output")){
|
||||
return machineBase.slotConfiguration.getSlotDetails(slotID).autoOutput();
|
||||
}
|
||||
if(type.equalsIgnoreCase("filter")){
|
||||
return machineBase.slotConfiguration.getSlotDetails(slotID).filter();
|
||||
}
|
||||
return machineBase.slotConfiguration.getSlotDetails(slotID).autoInput();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,14 @@ import net.minecraft.client.renderer.RenderHelper;
|
|||
import net.minecraft.client.renderer.RenderItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import reborncore.api.recipe.IRecipeCrafterProvider;
|
||||
import reborncore.common.recipes.RecipeCrafter;
|
||||
import reborncore.common.tile.SlotConfiguration;
|
||||
import techreborn.client.gui.GuiBase;
|
||||
import techreborn.client.gui.slot.GuiSlotConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigSlotElement extends ElementBase {
|
||||
|
@ -18,6 +21,7 @@ public class ConfigSlotElement extends ElementBase {
|
|||
IInventory inventory;
|
||||
int id;
|
||||
public List<ElementBase> elements = new ArrayList<>();
|
||||
boolean filter = false;
|
||||
|
||||
|
||||
public ConfigSlotElement(IInventory slotInventory, int slotId, SlotType type, int x, int y, GuiBase gui) {
|
||||
|
@ -44,6 +48,18 @@ public class ConfigSlotElement extends ElementBase {
|
|||
popupElement.updateCheckBox((CheckBoxElement) element, "output", gui13);
|
||||
return true;
|
||||
}));
|
||||
|
||||
if(gui.getMachine() instanceof IRecipeCrafterProvider){
|
||||
RecipeCrafter recipeCrafter = ((IRecipeCrafterProvider) gui.getMachine()).getRecipeCrafter();
|
||||
if(Arrays.stream(recipeCrafter.inputSlots).anyMatch(value -> value == slotId)){
|
||||
elements.add(new CheckBoxElement("Filter Inputs", 0xFFFFFFFF, x - 26, y + 72,"filter", slotId, Sprite.LIGHT_CHECK_BOX, gui.getMachine()).addPressAction((element, gui13, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "filter", gui13);
|
||||
return true;
|
||||
}));
|
||||
filter = true;
|
||||
popupElement.filter = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.awt.*;
|
|||
|
||||
public class SlotConfigPopupElement extends ElementBase {
|
||||
int id;
|
||||
public boolean filter = false;
|
||||
|
||||
ConfigSlotElement slotElement;
|
||||
|
||||
|
@ -35,7 +36,7 @@ public class SlotConfigPopupElement extends ElementBase {
|
|||
|
||||
@Override
|
||||
public void draw(GuiBase gui) {
|
||||
drawDefaultBackground(gui, adjustX(gui, getX() -8), adjustY(gui, getY() - 7), 84, 105);
|
||||
drawDefaultBackground(gui, adjustX(gui, getX() -8), adjustY(gui, getY() - 7), 84, 105 + (filter ? 15 : 0));
|
||||
super.draw(gui);
|
||||
|
||||
TileLegacyMachineBase machine = ((TileLegacyMachineBase) gui.tile);
|
||||
|
@ -95,14 +96,18 @@ public class SlotConfigPopupElement extends ElementBase {
|
|||
SlotConfiguration.SlotConfigHolder configHolder = guiBase.getMachine().slotConfiguration.getSlotDetails(id);
|
||||
boolean input = configHolder.autoInput();
|
||||
boolean output = configHolder.autoOutput();
|
||||
boolean filter = configHolder.filter();
|
||||
if(type.equalsIgnoreCase("input")){
|
||||
input = !configHolder.autoInput();
|
||||
}
|
||||
if(type.equalsIgnoreCase("output")){
|
||||
output = !configHolder.autoOutput();
|
||||
}
|
||||
if(type.equalsIgnoreCase("filter")){
|
||||
filter = !configHolder.filter();
|
||||
}
|
||||
|
||||
PacketIOSave packetSlotSave = new PacketIOSave(guiBase.tile.getPos(), id, input, output);
|
||||
PacketIOSave packetSlotSave = new PacketIOSave(guiBase.tile.getPos(), id, input, output, filter);
|
||||
NetworkManager.sendToServer(packetSlotSave);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue