diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/machines/GTAEMachines.java b/src/main/java/com/gregtechceu/gtceu/common/data/machines/GTAEMachines.java index 3267c31313..ba7a1e3652 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/machines/GTAEMachines.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/machines/GTAEMachines.java @@ -8,17 +8,20 @@ import com.gregtechceu.gtceu.integration.ae2.machine.MEOutputBusPartMachine; import com.gregtechceu.gtceu.integration.ae2.machine.MEOutputHatchPartMachine; +import com.gregtechceu.gtceu.integration.ae2.machine.MEStockingBusPartMachine; +import com.gregtechceu.gtceu.integration.ae2.machine.MEStockingHatchPartMachine; import net.minecraft.network.chat.Component; import static com.gregtechceu.gtceu.api.GTValues.EV; +import static com.gregtechceu.gtceu.api.GTValues.LuV; import static com.gregtechceu.gtceu.common.registry.GTRegistration.REGISTRATE; @SuppressWarnings("unused") public class GTAEMachines { - public final static MachineDefinition ITEM_IMPORT_BUS = REGISTRATE + public final static MachineDefinition ITEM_IMPORT_BUS_ME = REGISTRATE .machine("me_input_bus", MEInputBusPartMachine::new) - .langValue("ME Stocking Input Bus") + .langValue("ME Input Bus") .tier(EV) .rotationState(RotationState.ALL) .abilities(PartAbility.IMPORT_ITEMS) @@ -27,7 +30,18 @@ public class GTAEMachines { .compassNode("item_bus") .register(); - public final static MachineDefinition ITEM_EXPORT_BUS = REGISTRATE + public final static MachineDefinition STOCKING_IMPORT_BUS_ME = REGISTRATE + .machine("me_stocking_input_bus", MEStockingBusPartMachine::new) + .langValue("ME Stocking Input Bus") + .tier(LuV) + .rotationState(RotationState.ALL) + .abilities(PartAbility.IMPORT_ITEMS) + .overlayTieredHullRenderer("me_item_bus.import") + .tooltips(Component.translatable("gtceu.machine.item_bus.import.tooltip")) + .compassNode("item_bus") + .register(); + + public final static MachineDefinition ITEM_EXPORT_BUS_ME = REGISTRATE .machine("me_output_bus", MEOutputBusPartMachine::new) .langValue("ME Output Bus") .tier(EV) @@ -41,9 +55,9 @@ public class GTAEMachines { .compassNode("item_bus") .register(); - public final static MachineDefinition FLUID_IMPORT_HATCH = REGISTRATE + public final static MachineDefinition FLUID_IMPORT_HATCH_ME = REGISTRATE .machine("me_input_hatch", MEInputHatchPartMachine::new) - .langValue("ME Stocking Input Hatch") + .langValue("ME Input Hatch") .tier(EV) .rotationState(RotationState.ALL) .abilities(PartAbility.IMPORT_FLUIDS) @@ -52,7 +66,18 @@ public class GTAEMachines { .compassNode("fluid_hatch") .register(); - public final static MachineDefinition FLUID_EXPORT_HATCH = REGISTRATE + public final static MachineDefinition STOCKING_IMPORT_HATCH_ME = REGISTRATE + .machine("me_stocking_input_hatch", MEStockingHatchPartMachine::new) + .langValue("ME Stocking Input Hatch") + .tier(LuV) + .rotationState(RotationState.ALL) + .abilities(PartAbility.IMPORT_FLUIDS) + .overlayTieredHullRenderer("me_fluid_hatch.import") + .tooltips(Component.translatable("gtceu.machine.fluid_hatch.import.tooltip")) + .compassNode("fluid_hatch") + .register(); + + public final static MachineDefinition FLUID_EXPORT_HATCH_ME = REGISTRATE .machine("me_output_hatch", MEOutputHatchPartMachine::new) .langValue("ME Output Hatch") .tier(EV) diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/MetaTileEntityMachineRecipeLoader.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/MetaTileEntityMachineRecipeLoader.java index 3c48442d68..ac50eeebda 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/MetaTileEntityMachineRecipeLoader.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/misc/MetaTileEntityMachineRecipeLoader.java @@ -779,29 +779,47 @@ public static void init(Consumer provider) { .inputItems(FLUID_EXPORT_HATCH[EV]) .inputItems(meInterface.copy()) .inputItems(accelerationCard.copy()) - .outputItems(GTAEMachines.FLUID_EXPORT_HATCH.asStack()) + .outputItems(GTAEMachines.FLUID_EXPORT_HATCH_ME) .duration(300).EUt(VA[HV]).save(provider); ASSEMBLER_RECIPES.recipeBuilder("me_import_hatch") .inputItems(FLUID_IMPORT_HATCH[EV]) .inputItems(meInterface.copy()) .inputItems(accelerationCard.copy()) - .outputItems(GTAEMachines.FLUID_IMPORT_HATCH.asStack()) + .outputItems(GTAEMachines.FLUID_IMPORT_HATCH_ME) .duration(300).EUt(VA[HV]).save(provider); ASSEMBLER_RECIPES.recipeBuilder("me_export_bus") .inputItems(ITEM_EXPORT_BUS[EV]) .inputItems(meInterface.copy()) .inputItems(accelerationCard.copy()) - .outputItems(GTAEMachines.ITEM_EXPORT_BUS.asStack()) + .outputItems(GTAEMachines.ITEM_EXPORT_BUS_ME) .duration(300).EUt(VA[HV]).save(provider); ASSEMBLER_RECIPES.recipeBuilder("me_import_bus") .inputItems(ITEM_IMPORT_BUS[EV]) .inputItems(meInterface.copy()) .inputItems(accelerationCard.copy()) - .outputItems(GTAEMachines.ITEM_IMPORT_BUS.asStack()) + .outputItems(GTAEMachines.ITEM_IMPORT_BUS_ME) .duration(300).EUt(VA[HV]).save(provider); + + ASSEMBLER_RECIPES.recipeBuilder("me_stocking_import_bus") + .inputItems(ITEM_IMPORT_BUS[IV]) + .inputItems(meInterface.copy()) + .inputItems(CONVEYOR_MODULE_IV) + .inputItems(SENSOR_IV) + .inputItems(accelerationCard.copyWithCount(4)) + .outputItems(GTAEMachines.STOCKING_IMPORT_BUS_ME) + .duration(300).EUt(VA[IV]).save(provider); + + ASSEMBLER_RECIPES.recipeBuilder("me_stocking_import_hatch") + .inputItems(FLUID_IMPORT_HATCH[IV]) + .inputItems(meInterface.copy()) + .inputItems(ELECTRIC_PUMP_IV) + .inputItems(SENSOR_IV) + .inputItems(accelerationCard.copyWithCount(4)) + .outputItems(GTAEMachines.STOCKING_IMPORT_HATCH_ME) + .duration(300).EUt(VA[IV]).save(provider); } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidConfigWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidConfigWidget.java index 6ad4ef69f1..8ea19909be 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidConfigWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidConfigWidget.java @@ -1,14 +1,16 @@ package com.gregtechceu.gtceu.integration.ae2.gui.widget; +import com.gregtechceu.gtceu.integration.ae2.gui.widget.slot.AEFluidConfigSlotWidget; import com.gregtechceu.gtceu.integration.ae2.machine.MEInputHatchPartMachine; -import com.gregtechceu.gtceu.integration.ae2.utils.IConfigurableSlot; +import com.gregtechceu.gtceu.integration.ae2.slot.ExportOnlyAEFluidSlot; +import com.gregtechceu.gtceu.integration.ae2.slot.IConfigurableSlot; /** * @Author GlodBlock * @Description Display {@link com.lowdragmc.lowdraglib.side.fluid.FluidStack} config * @Date 2023/4/21-1:45 */ -public class AEFluidConfigWidget extends AEConfigWidget { +public class AEFluidConfigWidget extends ConfigWidget { public AEFluidConfigWidget(int x, int y, IConfigurableSlot[] config) { super(x, y, config); @@ -20,10 +22,10 @@ void init() { this.displayList = new IConfigurableSlot[this.config.length]; this.cached = new IConfigurableSlot[this.config.length]; for (int index = 0; index < this.config.length; index++) { - this.displayList[index] = new MEInputHatchPartMachine.ExportOnlyAEFluid(); - this.cached[index] = new MEInputHatchPartMachine.ExportOnlyAEFluid(); + this.displayList[index] = new ExportOnlyAEFluidSlot(); + this.cached[index] = new ExportOnlyAEFluidSlot(); line = index / 8; - this.addWidget(new AEFluidConfigSlot((index - line * 8) * 18, line * (18 * 2 + 2), this, index)); + this.addWidget(new AEFluidConfigSlotWidget((index - line * 8) * 18, line * (18 * 2 + 2), this, index)); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEItemConfigWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEItemConfigWidget.java index 2da250c3cc..0f1c4aa3ae 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEItemConfigWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEItemConfigWidget.java @@ -1,14 +1,16 @@ package com.gregtechceu.gtceu.integration.ae2.gui.widget; +import com.gregtechceu.gtceu.integration.ae2.gui.widget.slot.AEItemConfigSlotWidget; import com.gregtechceu.gtceu.integration.ae2.machine.MEInputBusPartMachine; -import com.gregtechceu.gtceu.integration.ae2.utils.IConfigurableSlot; +import com.gregtechceu.gtceu.integration.ae2.slot.ExportOnlyAEItemSlot; +import com.gregtechceu.gtceu.integration.ae2.slot.IConfigurableSlot; /** * @Author GlodBlock * @Description Display {@link net.minecraft.world.item.ItemStack} config * @Date 2023/4/22-1:02 */ -public class AEItemConfigWidget extends AEConfigWidget { +public class AEItemConfigWidget extends ConfigWidget { public AEItemConfigWidget(int x, int y, IConfigurableSlot[] config) { super(x, y, config); @@ -20,10 +22,10 @@ void init() { this.displayList = new IConfigurableSlot[this.config.length]; this.cached = new IConfigurableSlot[this.config.length]; for (int index = 0; index < this.config.length; index++) { - this.displayList[index] = new MEInputBusPartMachine.ExportOnlyAEItem(); - this.cached[index] = new MEInputBusPartMachine.ExportOnlyAEItem(); + this.displayList[index] = new ExportOnlyAEItemSlot(); + this.cached[index] = new ExportOnlyAEItemSlot(); line = index / 8; - this.addWidget(new AEItemConfigSlot((index - line * 8) * 18, line * (18 * 2 + 2), this, index)); + this.addWidget(new AEItemConfigSlotWidget((index - line * 8) * 18, line * (18 * 2 + 2), this, index)); } } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AmountSetSlot.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AmountSetWidget.java similarity index 92% rename from src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AmountSetSlot.java rename to src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AmountSetWidget.java index 7049805bdb..f927ae3e27 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AmountSetSlot.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AmountSetWidget.java @@ -1,7 +1,7 @@ package com.gregtechceu.gtceu.integration.ae2.gui.widget; import com.gregtechceu.gtceu.api.gui.GuiTextures; -import com.gregtechceu.gtceu.integration.ae2.utils.IConfigurableSlot; +import com.gregtechceu.gtceu.integration.ae2.slot.IConfigurableSlot; import com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; @@ -21,14 +21,14 @@ * @Description The amount set widget for config slot * @Date 2023/4/21-21:20 */ -public class AmountSetSlot extends Widget { +public class AmountSetWidget extends Widget { private int index = -1; @Getter private final TextFieldWidget amountText; - private final AEConfigWidget parentWidget; + private final ConfigWidget parentWidget; - public AmountSetSlot(int x, int y, AEConfigWidget widget) { + public AmountSetWidget(int x, int y, ConfigWidget widget) { super(x, y, 80, 30); this.parentWidget = widget; this.amountText = new TextFieldWidget(x + 3, y + 12, 65, 13, this::getAmountStr, this::setNewAmount) diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEConfigWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/ConfigWidget.java similarity index 91% rename from src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEConfigWidget.java rename to src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/ConfigWidget.java index 633347af7d..86bfab00f5 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEConfigWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/ConfigWidget.java @@ -1,6 +1,7 @@ package com.gregtechceu.gtceu.integration.ae2.gui.widget; -import com.gregtechceu.gtceu.integration.ae2.utils.IConfigurableSlot; +import com.gregtechceu.gtceu.integration.ae2.gui.widget.slot.AEConfigSlotWidget; +import com.gregtechceu.gtceu.integration.ae2.slot.IConfigurableSlot; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; @@ -13,20 +14,20 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -public abstract class AEConfigWidget extends WidgetGroup { +public abstract class ConfigWidget extends WidgetGroup { protected final IConfigurableSlot[] config; protected IConfigurableSlot[] cached; protected Int2ObjectMap changeMap = new Int2ObjectOpenHashMap<>(); protected IConfigurableSlot[] displayList; - protected AmountSetSlot amountSetWidget; + protected AmountSetWidget amountSetWidget; protected final static int UPDATE_ID = 1000; - public AEConfigWidget(int x, int y, IConfigurableSlot[] config) { + public ConfigWidget(int x, int y, IConfigurableSlot[] config) { super(new Position(x, y), new Size(config.length / 2 * 18, 18 * 4 + 2)); this.config = config; this.init(); - this.amountSetWidget = new AmountSetSlot(31, -50, this); + this.amountSetWidget = new AmountSetWidget(31, -50, this); this.addWidget(this.amountSetWidget); this.addWidget(this.amountSetWidget.getAmountText()); this.amountSetWidget.setVisible(false); @@ -53,7 +54,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { } } for (Widget w : this.widgets) { - if (w instanceof AEConfigSlot slot) { + if (w instanceof AEConfigSlotWidget slot) { slot.setSelect(false); } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidDisplayWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java similarity index 95% rename from src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidDisplayWidget.java rename to src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java index 46a28b1bdf..11967cd705 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidDisplayWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEFluidDisplayWidget.java @@ -1,4 +1,4 @@ -package com.gregtechceu.gtceu.integration.ae2.gui.widget; +package com.gregtechceu.gtceu.integration.ae2.gui.widget.list; import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.client.TooltipsHandler; @@ -24,7 +24,7 @@ import java.util.List; import java.util.Optional; -import static com.gregtechceu.gtceu.integration.ae2.gui.widget.AEConfigSlot.drawSelectionOverlay; +import static com.gregtechceu.gtceu.integration.ae2.gui.widget.slot.AEConfigSlotWidget.drawSelectionOverlay; import static com.lowdragmc.lowdraglib.gui.util.DrawerHelper.drawText; /** diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEItemDisplayWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEItemDisplayWidget.java similarity index 93% rename from src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEItemDisplayWidget.java rename to src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEItemDisplayWidget.java index 89bf5f0d15..ad5d565c5d 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEItemDisplayWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEItemDisplayWidget.java @@ -1,4 +1,4 @@ -package com.gregtechceu.gtceu.integration.ae2.gui.widget; +package com.gregtechceu.gtceu.integration.ae2.gui.widget.list; import com.gregtechceu.gtceu.api.gui.GuiTextures; @@ -14,7 +14,7 @@ import appeng.api.stacks.GenericStack; import org.jetbrains.annotations.NotNull; -import static com.gregtechceu.gtceu.integration.ae2.gui.widget.AEConfigSlot.drawSelectionOverlay; +import static com.gregtechceu.gtceu.integration.ae2.gui.widget.slot.AEConfigSlotWidget.drawSelectionOverlay; import static com.lowdragmc.lowdraglib.gui.util.DrawerHelper.drawItemStack; import static com.lowdragmc.lowdraglib.gui.util.DrawerHelper.drawText; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEListGridWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEListGridWidget.java similarity index 99% rename from src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEListGridWidget.java rename to src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEListGridWidget.java index 90421bb393..496e1d3d29 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEListGridWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/list/AEListGridWidget.java @@ -1,4 +1,4 @@ -package com.gregtechceu.gtceu.integration.ae2.gui.widget; +package com.gregtechceu.gtceu.integration.ae2.gui.widget.list; import com.gregtechceu.gtceu.integration.ae2.utils.KeyStorage; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEConfigSlot.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEConfigSlotWidget.java similarity index 88% rename from src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEConfigSlot.java rename to src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEConfigSlotWidget.java index ed64d39594..68d34486af 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEConfigSlot.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEConfigSlotWidget.java @@ -1,6 +1,7 @@ -package com.gregtechceu.gtceu.integration.ae2.gui.widget; +package com.gregtechceu.gtceu.integration.ae2.gui.widget.slot; -import com.gregtechceu.gtceu.integration.ae2.utils.IConfigurableSlot; +import com.gregtechceu.gtceu.integration.ae2.gui.widget.ConfigWidget; +import com.gregtechceu.gtceu.integration.ae2.slot.IConfigurableSlot; import com.lowdragmc.lowdraglib.gui.ingredient.IGhostIngredientTarget; import com.lowdragmc.lowdraglib.gui.ingredient.Target; @@ -29,9 +30,9 @@ * @Description A configurable slot * @Date 2023/4/22-0:30 */ -public class AEConfigSlot extends Widget implements IGhostIngredientTarget { +public class AEConfigSlotWidget extends Widget implements IGhostIngredientTarget { - protected AEConfigWidget parentWidget; + protected ConfigWidget parentWidget; protected int index; protected final static int REMOVE_ID = 1000; protected final static int UPDATE_ID = 1001; @@ -39,7 +40,7 @@ public class AEConfigSlot extends Widget implements IGhostIngredientTarget { protected final static int PICK_UP_ID = 1003; protected boolean select = false; - public AEConfigSlot(Position pos, Size size, AEConfigWidget widget, int index) { + public AEConfigSlotWidget(Position pos, Size size, ConfigWidget widget, int index) { super(pos, size); this.parentWidget = widget; this.index = index; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidConfigSlot.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEFluidConfigSlotWidget.java similarity index 95% rename from src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidConfigSlot.java rename to src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEFluidConfigSlotWidget.java index c11582d2a6..cc46034a3a 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEFluidConfigSlot.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEFluidConfigSlotWidget.java @@ -1,9 +1,11 @@ -package com.gregtechceu.gtceu.integration.ae2.gui.widget; +package com.gregtechceu.gtceu.integration.ae2.gui.widget.slot; import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.integration.ae2.gui.widget.ConfigWidget; import com.gregtechceu.gtceu.integration.ae2.machine.MEInputHatchPartMachine; -import com.gregtechceu.gtceu.integration.ae2.utils.ExportOnlyAESlot; -import com.gregtechceu.gtceu.integration.ae2.utils.IConfigurableSlot; +import com.gregtechceu.gtceu.integration.ae2.slot.ExportOnlyAEFluidSlot; +import com.gregtechceu.gtceu.integration.ae2.slot.ExportOnlyAESlot; +import com.gregtechceu.gtceu.integration.ae2.slot.IConfigurableSlot; import com.lowdragmc.lowdraglib.gui.ingredient.Target; import com.lowdragmc.lowdraglib.gui.util.DrawerHelper; @@ -42,11 +44,11 @@ * @Description A configurable slot for {@link com.lowdragmc.lowdraglib.side.fluid.FluidStack} * @Date 2023/4/21-0:50 */ -public class AEFluidConfigSlot extends AEConfigSlot { +public class AEFluidConfigSlotWidget extends AEConfigSlotWidget { public static final int LOAD_PHANTOM_FLUID_STACK_FROM_NBT = 13; - public AEFluidConfigSlot(int x, int y, AEConfigWidget widget, int index) { + public AEFluidConfigSlotWidget(int x, int y, ConfigWidget widget, int index) { super(new Position(x, y), new Size(18, 18 * 2), widget, index); } @@ -263,8 +265,8 @@ public boolean mouseWheelMove(double mouseX, double mouseY, double wheelDelta) { } private int tryClickContainer(boolean isShiftKeyDown) { - MEInputHatchPartMachine.ExportOnlyAEFluid fluidTank = this.parentWidget - .getConfig(this.index) instanceof MEInputHatchPartMachine.ExportOnlyAEFluid fluid ? fluid : null; + ExportOnlyAEFluidSlot fluidTank = this.parentWidget + .getConfig(this.index) instanceof ExportOnlyAEFluidSlot fluid ? fluid : null; if (fluidTank == null) return -1; Player player = gui.entityPlayer; ItemStack currentStack = gui.getModularUIContainer().getCarried(); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEItemConfigSlot.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEItemConfigSlotWidget.java similarity index 96% rename from src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEItemConfigSlot.java rename to src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEItemConfigSlotWidget.java index c50c8640c9..72a2dda225 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/AEItemConfigSlot.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/gui/widget/slot/AEItemConfigSlotWidget.java @@ -1,8 +1,9 @@ -package com.gregtechceu.gtceu.integration.ae2.gui.widget; +package com.gregtechceu.gtceu.integration.ae2.gui.widget.slot; import com.gregtechceu.gtceu.api.gui.GuiTextures; -import com.gregtechceu.gtceu.integration.ae2.utils.ExportOnlyAESlot; -import com.gregtechceu.gtceu.integration.ae2.utils.IConfigurableSlot; +import com.gregtechceu.gtceu.integration.ae2.gui.widget.ConfigWidget; +import com.gregtechceu.gtceu.integration.ae2.slot.ExportOnlyAESlot; +import com.gregtechceu.gtceu.integration.ae2.slot.IConfigurableSlot; import com.lowdragmc.lowdraglib.gui.ingredient.Target; import com.lowdragmc.lowdraglib.gui.util.TextFormattingUtil; @@ -31,9 +32,9 @@ * @Description A configurable slot for {@link ItemStack} * @Date 2023/4/22-0:48 */ -public class AEItemConfigSlot extends AEConfigSlot { +public class AEItemConfigSlotWidget extends AEConfigSlotWidget { - public AEItemConfigSlot(int x, int y, AEConfigWidget widget, int index) { + public AEItemConfigSlotWidget(int x, int y, ConfigWidget widget, int index) { super(new Position(x, y), new Size(18, 18 * 2), widget, index); } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputBusPartMachine.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputBusPartMachine.java index 991d82fe08..492a95939a 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputBusPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputBusPartMachine.java @@ -2,36 +2,20 @@ import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; -import com.gregtechceu.gtceu.api.machine.MetaMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableItemStackHandler; -import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.integration.ae2.gui.widget.AEItemConfigWidget; -import com.gregtechceu.gtceu.integration.ae2.utils.ExportOnlyAESlot; +import com.gregtechceu.gtceu.integration.ae2.slot.ExportOnlyAEItemList; +import com.gregtechceu.gtceu.integration.ae2.slot.ExportOnlyAEItemSlot; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.misc.ItemStackTransfer; -import com.lowdragmc.lowdraglib.side.item.IItemTransfer; -import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import com.lowdragmc.lowdraglib.utils.Position; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.Ingredient; - import appeng.api.config.Actionable; -import appeng.api.networking.IGrid; -import appeng.api.stacks.AEItemKey; import appeng.api.stacks.GenericStack; import appeng.api.storage.MEStorage; -import com.mojang.datafixers.util.Pair; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; -import java.util.List; public class MEInputBusPartMachine extends MEBusPartMachine { @@ -40,7 +24,6 @@ public class MEInputBusPartMachine extends MEBusPartMachine { private final static int CONFIG_SIZE = 16; private ExportOnlyAEItemList aeItemHandler; - private IGrid aeProxy; public MEInputBusPartMachine(IMachineBlockEntity holder, Object... args) { super(holder, IO.IN, args); @@ -54,13 +37,12 @@ protected NotifiableItemStackHandler createInventory(Object... args) { @Override public void autoIO() { - if (getLevel().isClientSide) return; if (!this.isWorkingEnabled()) return; if (!this.shouldSyncME()) return; if (this.updateMEStatus()) { MEStorage aeNetwork = this.getMainNode().getGrid().getStorageService().getInventory(); - for (ExportOnlyAEItem aeSlot : this.aeItemHandler.inventory) { + for (ExportOnlyAEItemSlot aeSlot : this.aeItemHandler.inventory) { // Try to clear the wrong item GenericStack exceedItem = aeSlot.exceedStack(); if (exceedItem != null) { @@ -106,208 +88,4 @@ public Widget createUIWidget() { public ManagedFieldHolder getFieldHolder() { return MANAGED_FIELD_HOLDER; } - - private static class ExportOnlyAEItemList extends NotifiableItemStackHandler { - - public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(ExportOnlyAEItemList.class, - NotifiableItemStackHandler.MANAGED_FIELD_HOLDER); - - @Persisted - ExportOnlyAEItem[] inventory; - - public ExportOnlyAEItemList(MetaMachine holder, int slots) { - super(holder, slots, IO.IN); - this.inventory = new ExportOnlyAEItem[CONFIG_SIZE]; - for (int i = 0; i < CONFIG_SIZE; i++) { - this.inventory[i] = new ExportOnlyAEItem(null, null); - } - for (ExportOnlyAEItem slot : this.inventory) { - slot.setOnContentsChanged(this::onContentsChanged); - } - } - - @Override - public void onContentsChanged() { - super.onContentsChanged(); - this.machine.onChanged(); - } - - @Override - public List handleRecipeInner(IO io, GTRecipe recipe, List left, - @Nullable String slotName, boolean simulate) { - return handleIngredient(io, recipe, left, simulate, this.handlerIO, - new ItemStackTransfer(NonNullList.of(ItemStack.EMPTY, - Arrays.stream(inventory).map(item -> item.getStackInSlot(0)).toArray(ItemStack[]::new))) { - - @NotNull - @Override - public ItemStack extractItem(int slot, int amount, boolean simulate, boolean notifyChanges) { - ItemStack extracted = super.extractItem(slot, amount, simulate, notifyChanges); - if (!extracted.isEmpty()) { - inventory[slot].extractItem(0, amount, simulate, notifyChanges); - } - return extracted; - } - }); - } - - @Override - public void setStackInSlot(int slot, @NotNull ItemStack stack) { - // NO-OP - } - - @Override - public int getSlots() { - return MEInputBusPartMachine.CONFIG_SIZE; - } - - @NotNull - @Override - public ItemStack getStackInSlot(int slot) { - if (slot >= 0 && slot < CONFIG_SIZE) { - return this.inventory[slot].getStackInSlot(0); - } - return ItemStack.EMPTY; - } - - @NotNull - @Override - public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { - return stack; - } - - @NotNull - @Override - public ItemStack extractItem(int slot, int amount, boolean simulate) { - if (slot >= 0 && slot < CONFIG_SIZE) { - return this.inventory[slot].extractItem(0, amount, simulate); - } - return ItemStack.EMPTY; - } - - @Override - public int getSlotLimit(int slot) { - return Integer.MAX_VALUE; - } - - @Override - public ManagedFieldHolder getFieldHolder() { - return MANAGED_FIELD_HOLDER; - } - - @NotNull - @Override - public Object createSnapshot() { - return Arrays.stream(inventory).map(IItemTransfer::createSnapshot).toArray(Object[]::new); - } - - @Override - public void restoreFromSnapshot(Object snapshot) { - if (snapshot instanceof Object[] array && array.length == inventory.length) { - for (int i = 0; i < array.length; i++) { - inventory[i].restoreFromSnapshot(array[i]); - } - } - } - } - - public static class ExportOnlyAEItem extends ExportOnlyAESlot implements IItemTransfer { - - public ExportOnlyAEItem(GenericStack config, GenericStack stock) { - super(config, stock); - } - - public ExportOnlyAEItem() { - super(); - } - - @Override - public ExportOnlyAEItem copy() { - return new ExportOnlyAEItem( - this.config == null ? null : copy(this.config), - this.stock == null ? null : copy(this.stock)); - } - - @Override - public void setStackInSlot(int slot, @NotNull ItemStack stack) { - // NO-OP - } - - @NotNull - @Override - public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate, boolean notifyChanges) { - return stack; - } - - @Override - public int getSlots() { - return 1; - } - - @NotNull - @Override - public ItemStack getStackInSlot(int slot) { - if (slot == 0 && this.stock != null) { - return this.stock.what() instanceof AEItemKey itemKey ? itemKey.toStack((int) this.stock.amount()) : - ItemStack.EMPTY; - } - return ItemStack.EMPTY; - } - - @NotNull - @Override - public ItemStack extractItem(int slot, int amount, boolean simulate, boolean notifyChanges) { - if (slot == 0 && this.stock != null) { - int extracted = (int) Math.min(this.stock.amount(), amount); - ItemStack result = this.stock.what() instanceof AEItemKey itemKey ? - itemKey.toStack((int) this.stock.amount()) : ItemStack.EMPTY.copy(); - result.setCount(extracted); - if (!simulate) { - this.stock = ExportOnlyAESlot.copy(this.stock, this.stock.amount() - extracted); - if (this.stock.amount() == 0) { - this.stock = null; - } - } - if (notifyChanges && this.onContentsChanged != null) { - this.onContentsChanged.run(); - } - return result; - } - return ItemStack.EMPTY; - } - - @Override - public void addStack(GenericStack stack) { - if (this.stock == null) { - this.stock = stack; - } else { - this.stock = GenericStack.sum(this.stock, stack); - } - this.onContentsChanged.run(); - } - - @Override - public int getSlotLimit(int slot) { - return Integer.MAX_VALUE; - } - - @Override - public boolean isItemValid(int slot, @NotNull ItemStack stack) { - return false; - } - - @NotNull - @Override - public Object createSnapshot() { - return Pair.of(this.config, this.stock); - } - - @Override - public void restoreFromSnapshot(Object snapshot) { - if (snapshot instanceof Pair pair) { - this.config = (GenericStack) pair.getFirst(); - this.stock = (GenericStack) pair.getSecond(); - } - } - } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputHatchPartMachine.java index 1ffa8981fd..f3a937fbac 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEInputHatchPartMachine.java @@ -1,38 +1,23 @@ package com.gregtechceu.gtceu.integration.ae2.machine; +import appeng.api.config.Actionable; +import appeng.api.networking.IInWorldGridNodeHost; +import appeng.api.stacks.GenericStack; +import appeng.api.storage.MEStorage; +import appeng.me.helpers.IGridConnectedBlockEntity; import com.gregtechceu.gtceu.api.capability.recipe.IO; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; -import com.gregtechceu.gtceu.api.machine.MetaMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; -import com.gregtechceu.gtceu.api.recipe.GTRecipe; -import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; import com.gregtechceu.gtceu.integration.ae2.gui.widget.AEFluidConfigWidget; -import com.gregtechceu.gtceu.integration.ae2.utils.ExportOnlyAESlot; - +import com.gregtechceu.gtceu.integration.ae2.slot.ExportOnlyAEFluidList; +import com.gregtechceu.gtceu.integration.ae2.slot.ExportOnlyAEFluidSlot; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; -import com.lowdragmc.lowdraglib.misc.FluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidStorage; -import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; import com.lowdragmc.lowdraglib.utils.Position; - -import appeng.api.config.Actionable; -import appeng.api.networking.IInWorldGridNodeHost; -import appeng.api.stacks.AEFluidKey; -import appeng.api.stacks.GenericStack; -import appeng.api.storage.MEStorage; -import appeng.me.helpers.IGridConnectedBlockEntity; -import com.mojang.datafixers.util.Pair; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; -import java.util.List; -import java.util.function.Predicate; public class MEInputHatchPartMachine extends MEHatchPartMachine implements IInWorldGridNodeHost, IGridConnectedBlockEntity { @@ -77,13 +62,12 @@ public void onLoad() { @Override protected void autoIO() { - if (getLevel().isClientSide) return; if (!this.isWorkingEnabled()) return; if (!this.shouldSyncME()) return; if (this.updateMEStatus()) { MEStorage aeNetwork = this.getMainNode().getGrid().getStorageService().getInventory(); - for (ExportOnlyAEFluid aeTank : this.aeFluidTanks.tanks) { + for (ExportOnlyAEFluidSlot aeTank : this.aeFluidTanks.tanks) { // Try to clear the wrong fluid GenericStack exceedFluid = aeTank.exceedStack(); if (exceedFluid != null) { @@ -115,261 +99,4 @@ protected void autoIO() { public ManagedFieldHolder getFieldHolder() { return MANAGED_FIELD_HOLDER; } - - public static class ExportOnlyAEFluidList extends NotifiableFluidTank { - - public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder( - ExportOnlyAEFluidList.class, NotifiableFluidTank.MANAGED_FIELD_HOLDER); - - @Persisted - private final ExportOnlyAEFluid[] tanks; - private FluidStorage[] fluidStorages; - - public ExportOnlyAEFluidList(MetaMachine machine, int slots, long capacity, IO io) { - super(machine, slots, capacity, io); - this.tanks = new ExportOnlyAEFluid[slots]; - for (int i = 0; i < slots; i++) { - this.tanks[i] = new ExportOnlyAEFluid(null, null); - this.tanks[i].setOnContentsChanged(this::onContentsChanged); - } - this.fluidStorages = null; - } - - @Override - public FluidStorage[] getStorages() { - if (this.fluidStorages == null) { - this.fluidStorages = Arrays.stream(this.tanks) - .map(tank -> new WrappingFluidStorage(tank.getCapacity(), tank)).toArray(FluidStorage[]::new); - return this.fluidStorages; - } else { - return this.fluidStorages; - } - } - - @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return 0; - } - - @Override - public List handleRecipeInner(IO io, GTRecipe recipe, List left, - @Nullable String slotName, boolean simulate) { - return handleIngredient(io, recipe, left, simulate, this.handlerIO, getStorages()); - } - - public FluidStack drainInternal(long maxDrain, boolean simulate) { - if (maxDrain == 0) { - return FluidStack.empty(); - } - FluidStack totalDrained = null; - for (var tank : tanks) { - if (totalDrained == null || totalDrained.isEmpty()) { - totalDrained = tank.drain(maxDrain, simulate); - if (totalDrained.isEmpty()) { - totalDrained = null; - } else { - maxDrain -= totalDrained.getAmount(); - } - } else { - FluidStack copy = totalDrained.copy(); - copy.setAmount(maxDrain); - FluidStack drain = tank.drain(copy, simulate); - totalDrained.grow(drain.getAmount()); - maxDrain -= drain.getAmount(); - } - if (maxDrain <= 0) break; - } - return totalDrained == null ? FluidStack.empty() : totalDrained; - } - - @NotNull - @Override - public Object createSnapshot() { - return Arrays.stream(tanks).map(IFluidTransfer::createSnapshot).toArray(Object[]::new); - } - - @Override - public void restoreFromSnapshot(Object snapshot) { - if (snapshot instanceof Object[] array && array.length == tanks.length) { - for (int i = 0; i < array.length; i++) { - tanks[i].restoreFromSnapshot(array[i]); - } - } - } - - @Override - public ManagedFieldHolder getFieldHolder() { - return MANAGED_FIELD_HOLDER; - } - - private static class WrappingFluidStorage extends FluidStorage { - - private final ExportOnlyAEFluid fluid; - - public WrappingFluidStorage(long capacity, ExportOnlyAEFluid fluid) { - super(capacity); - this.fluid = fluid; - } - - public WrappingFluidStorage(long capacity, Predicate validator, ExportOnlyAEFluid fluid) { - super(capacity, validator); - this.fluid = fluid; - } - - @Override - @NotNull - public FluidStack getFluid() { - return this.fluid.getFluid(); - } - - @NotNull - @Override - public FluidStack drain(FluidStack maxDrain, boolean simulate, boolean notifyChanges) { - return fluid.drain(maxDrain, simulate, notifyChanges); - } - - @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChange) { - return fluid.fill(tank, resource, simulate, notifyChange); - } - - @Override - public FluidStorage copy() { - var storage = new WrappingFluidStorage(capacity, validator, this.fluid); - storage.setFluid(super.fluid.copy()); - return storage; - } - } - } - - public static class ExportOnlyAEFluid extends ExportOnlyAESlot implements IFluidStorage, IFluidTransfer { - - public ExportOnlyAEFluid(GenericStack config, GenericStack stock) { - super(config, stock); - } - - public ExportOnlyAEFluid() { - super(); - } - - @Override - public void addStack(GenericStack stack) { - if (this.stock == null) { - this.stock = stack; - } else { - this.stock = GenericStack.sum(this.stock, stack); - } - onContentsChanged(); - } - - @Override - @NotNull - public FluidStack getFluid() { - if (this.stock != null && this.stock.what() instanceof AEFluidKey fluidKey) { - return FluidStack.create(fluidKey.getFluid(), this.stock == null ? 0 : this.stock.amount(), - fluidKey.getTag()); - } - return FluidStack.empty(); - } - - @Override - public void setFluid(FluidStack fluid) {} - - @Override - public long getFluidAmount() { - return this.stock != null ? this.stock.amount() : 0; - } - - @Override - public long getCapacity() { - // Its capacity is always 0. - return 0; - } - - @Override - public boolean isFluidValid(FluidStack stack) { - return false; - } - - @Override - public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return 0; - } - - @Override - public boolean supportsFill(int tank) { - return false; - } - - @NotNull - @Override - public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { - return this.drain(resource, simulate, notifyChanges); - } - - @Override - public boolean supportsDrain(int tank) { - return tank == 0; - } - - @Override - public long fill(FluidStack resource, boolean doFill) { - return 0; - } - - @NotNull - @Override - public FluidStack drain(FluidStack resource, boolean doDrain, boolean notifyChanges) { - if (this.getFluid().isFluidEqual(resource)) { - return this.drain(resource.getAmount(), doDrain, notifyChanges); - } - return FluidStack.empty(); - } - - @Override - @NotNull - public FluidStack drain(long maxDrain, boolean simulate, boolean notifyChanges) { - if (this.stock == null || !(this.stock.what() instanceof AEFluidKey fluidKey)) { - return FluidStack.empty(); - } - int drained = (int) Math.min(this.stock.amount(), maxDrain); - FluidStack result = FluidStack.create(fluidKey.getFluid(), drained, fluidKey.getTag()); - if (!simulate) { - this.stock = new GenericStack(this.stock.what(), this.stock.amount() - drained); - if (this.stock.amount() == 0) { - this.stock = null; - } - if (notifyChanges) onContentsChanged(); - } - return result; - } - - @NotNull - @Override - public Object createSnapshot() { - return Pair.of(this.config, this.stock); - } - - @Override - public void restoreFromSnapshot(Object snapshot) { - if (snapshot instanceof Pair pair) { - this.config = (GenericStack) pair.getFirst(); - this.stock = (GenericStack) pair.getSecond(); - } - } - - @Override - public void onContentsChanged() { - if (onContentsChanged != null) { - onContentsChanged.run(); - } - } - - @Override - public ExportOnlyAEFluid copy() { - return new ExportOnlyAEFluid( - this.config == null ? null : ExportOnlyAESlot.copy(this.config), - this.stock == null ? null : ExportOnlyAESlot.copy(this.stock)); - } - } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputBusPartMachine.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputBusPartMachine.java index 0e48b3f132..dd120b16ec 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputBusPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputBusPartMachine.java @@ -5,7 +5,7 @@ import com.gregtechceu.gtceu.api.machine.MetaMachine; import com.gregtechceu.gtceu.api.machine.trait.NotifiableItemStackHandler; import com.gregtechceu.gtceu.api.recipe.GTRecipe; -import com.gregtechceu.gtceu.integration.ae2.gui.widget.AEListGridWidget; +import com.gregtechceu.gtceu.integration.ae2.gui.widget.list.AEListGridWidget; import com.gregtechceu.gtceu.integration.ae2.utils.KeyStorage; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; @@ -77,7 +77,7 @@ public Widget createUIWidget() { "gtceu.gui.me_network.online" : "gtceu.gui.me_network.offline")); group.addWidget(new LabelWidget(5, 10, "gtceu.gui.waiting_list")); - // Config slots + // Display group.addWidget(new AEListGridWidget.Item(5, 20, 3, this.internalBuffer)); return group; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputHatchPartMachine.java index 22057603f3..39782c9707 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEOutputHatchPartMachine.java @@ -6,7 +6,7 @@ import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; import com.gregtechceu.gtceu.api.recipe.GTRecipe; import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; -import com.gregtechceu.gtceu.integration.ae2.gui.widget.AEListGridWidget; +import com.gregtechceu.gtceu.integration.ae2.gui.widget.list.AEListGridWidget; import com.gregtechceu.gtceu.integration.ae2.utils.KeyStorage; import com.lowdragmc.lowdraglib.gui.widget.LabelWidget; @@ -78,7 +78,7 @@ public Widget createUIWidget() { "gtceu.gui.me_network.online" : "gtceu.gui.me_network.offline")); group.addWidget(new LabelWidget(5, 10, "gtceu.gui.waiting_list")); - // Config slots + // slots group.addWidget(new AEListGridWidget.Fluid(5, 20, 3, this.internalBuffer)); return group; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingBusPartMachine.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingBusPartMachine.java new file mode 100644 index 0000000000..cbf37c849d --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingBusPartMachine.java @@ -0,0 +1,11 @@ +package com.gregtechceu.gtceu.integration.ae2.machine; + +import com.gregtechceu.gtceu.api.capability.recipe.IO; +import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; + +public class MEStockingBusPartMachine extends MEBusPartMachine { + + public MEStockingBusPartMachine(IMachineBlockEntity holder, Object... args) { + super(holder, IO.IN, args); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingHatchPartMachine.java new file mode 100644 index 0000000000..81278cd72b --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEStockingHatchPartMachine.java @@ -0,0 +1,11 @@ +package com.gregtechceu.gtceu.integration.ae2.machine; + +import com.gregtechceu.gtceu.api.capability.recipe.IO; +import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; + +public class MEStockingHatchPartMachine extends MEHatchPartMachine { + + public MEStockingHatchPartMachine(IMachineBlockEntity holder, Object... args) { + super(holder, IO.IN, args); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidList.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidList.java new file mode 100644 index 0000000000..ac511b7d69 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidList.java @@ -0,0 +1,145 @@ +package com.gregtechceu.gtceu.integration.ae2.slot; + +import com.gregtechceu.gtceu.api.capability.recipe.IO; +import com.gregtechceu.gtceu.api.machine.MetaMachine; +import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank; +import com.gregtechceu.gtceu.api.recipe.GTRecipe; +import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; +import com.lowdragmc.lowdraglib.misc.FluidStorage; +import com.lowdragmc.lowdraglib.side.fluid.FluidStack; +import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; +import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; +import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; + +public class ExportOnlyAEFluidList extends NotifiableFluidTank { + + public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder( + ExportOnlyAEFluidList.class, NotifiableFluidTank.MANAGED_FIELD_HOLDER); + + @Persisted + public final ExportOnlyAEFluidSlot[] tanks; + private FluidStorage[] fluidStorages; + + public ExportOnlyAEFluidList(MetaMachine machine, int slots, long capacity, IO io) { + super(machine, slots, capacity, io); + this.tanks = new ExportOnlyAEFluidSlot[slots]; + for (int i = 0; i < slots; i++) { + this.tanks[i] = new ExportOnlyAEFluidSlot(null, null); + this.tanks[i].setOnContentsChanged(this::onContentsChanged); + } + this.fluidStorages = null; + } + + @Override + public FluidStorage[] getStorages() { + if (this.fluidStorages == null) { + this.fluidStorages = Arrays.stream(this.tanks) + .map(tank -> new FluidStorageDelegate(tank.getCapacity(), tank)).toArray(FluidStorage[]::new); + return this.fluidStorages; + } else { + return this.fluidStorages; + } + } + + @Override + public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { + return 0; + } + + @Override + public List handleRecipeInner(IO io, GTRecipe recipe, List left, + @Nullable String slotName, boolean simulate) { + return handleIngredient(io, recipe, left, simulate, this.handlerIO, getStorages()); + } + + public FluidStack drainInternal(long maxDrain, boolean simulate) { + if (maxDrain == 0) { + return FluidStack.empty(); + } + FluidStack totalDrained = null; + for (var tank : tanks) { + if (totalDrained == null || totalDrained.isEmpty()) { + totalDrained = tank.drain(maxDrain, simulate); + if (totalDrained.isEmpty()) { + totalDrained = null; + } else { + maxDrain -= totalDrained.getAmount(); + } + } else { + FluidStack copy = totalDrained.copy(); + copy.setAmount(maxDrain); + FluidStack drain = tank.drain(copy, simulate); + totalDrained.grow(drain.getAmount()); + maxDrain -= drain.getAmount(); + } + if (maxDrain <= 0) break; + } + return totalDrained == null ? FluidStack.empty() : totalDrained; + } + + @NotNull + @Override + public Object createSnapshot() { + return Arrays.stream(tanks).map(IFluidTransfer::createSnapshot).toArray(Object[]::new); + } + + @Override + public void restoreFromSnapshot(Object snapshot) { + if (snapshot instanceof Object[] array && array.length == tanks.length) { + for (int i = 0; i < array.length; i++) { + tanks[i].restoreFromSnapshot(array[i]); + } + } + } + + @Override + public ManagedFieldHolder getFieldHolder() { + return MANAGED_FIELD_HOLDER; + } + + private static class FluidStorageDelegate extends FluidStorage { + + private final ExportOnlyAEFluidSlot fluid; + + public FluidStorageDelegate(long capacity, ExportOnlyAEFluidSlot fluid) { + super(capacity); + this.fluid = fluid; + } + + public FluidStorageDelegate(long capacity, Predicate validator, ExportOnlyAEFluidSlot fluid) { + super(capacity, validator); + this.fluid = fluid; + } + + @Override + @NotNull + public FluidStack getFluid() { + return this.fluid.getFluid(); + } + + @NotNull + @Override + public FluidStack drain(FluidStack maxDrain, boolean simulate, boolean notifyChanges) { + return fluid.drain(maxDrain, simulate, notifyChanges); + } + + @Override + public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChange) { + return fluid.fill(tank, resource, simulate, notifyChange); + } + + @Override + public FluidStorage copy() { + var storage = new FluidStorageDelegate(capacity, validator, this.fluid); + storage.setFluid(super.fluid.copy()); + return storage; + } + } + +} diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidSlot.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidSlot.java new file mode 100644 index 0000000000..9a90f96e94 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEFluidSlot.java @@ -0,0 +1,143 @@ +package com.gregtechceu.gtceu.integration.ae2.slot; + +import appeng.api.stacks.AEFluidKey; +import appeng.api.stacks.GenericStack; +import com.lowdragmc.lowdraglib.side.fluid.FluidStack; +import com.lowdragmc.lowdraglib.side.fluid.IFluidStorage; +import com.mojang.datafixers.util.Pair; +import org.jetbrains.annotations.NotNull; + +public class ExportOnlyAEFluidSlot extends ExportOnlyAESlot implements IFluidStorage { + + public ExportOnlyAEFluidSlot() { + super(); + } + + public ExportOnlyAEFluidSlot(GenericStack config, GenericStack stock) { + super(config, stock); + } + + @Override + public void addStack(GenericStack stack) { + if (this.stock == null) { + this.stock = stack; + } else { + this.stock = GenericStack.sum(this.stock, stack); + } + onContentsChanged(); + } + + @Override + @NotNull + public FluidStack getFluid() { + if (this.stock != null && this.stock.what() instanceof AEFluidKey fluidKey) { + return FluidStack.create(fluidKey.getFluid(), this.stock == null ? 0 : this.stock.amount(), + fluidKey.getTag()); + } + return FluidStack.empty(); + } + + @Override + public void setFluid(FluidStack fluid) { + // NO-OP + } + + @Override + public long getFluidAmount() { + return this.stock != null ? this.stock.amount() : 0; + } + + @Override + public long getCapacity() { + // Its capacity is always 0. + return 0; + } + + @Override + public boolean isFluidValid(FluidStack stack) { + return false; + } + + @Override + public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { + return 0; + } + + @Override + public boolean supportsFill(int tank) { + return false; + } + + @NotNull + @Override + public FluidStack drain(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { + return this.drain(resource, simulate, notifyChanges); + } + + @Override + public boolean supportsDrain(int tank) { + return tank == 0; + } + + @Override + public long fill(FluidStack resource, boolean doFill) { + return 0; + } + + @NotNull + @Override + public FluidStack drain(FluidStack resource, boolean doDrain, boolean notifyChanges) { + if (this.getFluid().isFluidEqual(resource)) { + return this.drain(resource.getAmount(), doDrain, notifyChanges); + } + return FluidStack.empty(); + } + + @Override + @NotNull + public FluidStack drain(long maxDrain, boolean simulate, boolean notifyChanges) { + if (this.stock == null || !(this.stock.what() instanceof AEFluidKey fluidKey)) { + return FluidStack.empty(); + } + int drained = (int) Math.min(this.stock.amount(), maxDrain); + FluidStack result = FluidStack.create(fluidKey.getFluid(), drained, fluidKey.getTag()); + if (!simulate) { + this.stock = new GenericStack(this.stock.what(), this.stock.amount() - drained); + if (this.stock.amount() == 0) { + this.stock = null; + } + if (notifyChanges) onContentsChanged(); + } + return result; + } + + @Override + public void onContentsChanged() { + if (onContentsChanged != null) { + onContentsChanged.run(); + } + } + + @Override + public ExportOnlyAEFluidSlot copy() { + return new ExportOnlyAEFluidSlot( + this.config == null ? null : ExportOnlyAESlot.copy(this.config), + this.stock == null ? null : ExportOnlyAESlot.copy(this.stock)); + } + + @Deprecated + @NotNull + @Override + public Object createSnapshot() { + return Pair.of(this.config, this.stock); + } + + @Deprecated + @Override + public void restoreFromSnapshot(Object snapshot) { + if (snapshot instanceof Pair pair) { + this.config = (GenericStack) pair.getFirst(); + this.stock = (GenericStack) pair.getSecond(); + } + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEItemList.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEItemList.java new file mode 100644 index 0000000000..7497e5e83a --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEItemList.java @@ -0,0 +1,171 @@ +package com.gregtechceu.gtceu.integration.ae2.slot; + +import com.gregtechceu.gtceu.api.capability.recipe.IO; +import com.gregtechceu.gtceu.api.machine.MetaMachine; +import com.gregtechceu.gtceu.api.machine.trait.NotifiableItemStackHandler; +import com.gregtechceu.gtceu.api.recipe.GTRecipe; +import com.lowdragmc.lowdraglib.misc.ItemStackTransfer; +import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; +import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.List; + +public class ExportOnlyAEItemList extends NotifiableItemStackHandler { + + public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(ExportOnlyAEItemList.class, + NotifiableItemStackHandler.MANAGED_FIELD_HOLDER); + + @Persisted + public ExportOnlyAEItemSlot[] inventory; + + public ExportOnlyAEItemList(MetaMachine holder, int slots) { + super(holder, 0, IO.IN); + this.inventory = new ExportOnlyAEItemSlot[slots]; + for (int i = 0; i < slots; i++) { + this.inventory[i] = new ExportOnlyAEItemSlot(null, null); + } + for (ExportOnlyAEItemSlot slot : this.inventory) { + slot.setOnContentsChanged(this::onContentsChanged); + } + } + + @Override + public void onContentsChanged() { + super.onContentsChanged(); + this.machine.onChanged(); + } + + @Override + public List handleRecipeInner(IO io, GTRecipe recipe, List left, + @Nullable String slotName, boolean simulate) { + return handleIngredient(io, recipe, left, simulate, this.handlerIO, + new ItemStackTransfer(NonNullList.of(ItemStack.EMPTY, + Arrays.stream(inventory).map(item -> item.getStackInSlot(0)).toArray(ItemStack[]::new))) { + + @NotNull + @Override + public ItemStack extractItem(int slot, int amount, boolean simulate, boolean notifyChanges) { + ItemStack extracted = super.extractItem(slot, amount, simulate, notifyChanges); + if (!extracted.isEmpty()) { + inventory[slot].extractItem(0, amount, simulate, notifyChanges); + } + return extracted; + } + }); + } + + @Override + public void setStackInSlot(int slot, @NotNull ItemStack stack) { + // NO-OP + } + + @Override + public int getSlots() { + return inventory.length; + } + + @NotNull + @Override + public ItemStack getStackInSlot(int slot) { + if (slot >= 0 && slot < inventory.length) { + return this.inventory[slot].getStackInSlot(0); + } + return ItemStack.EMPTY; + } + + @NotNull + @Override + public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { + return stack; + } + + @NotNull + @Override + public ItemStack extractItem(int slot, int amount, boolean simulate) { + if (slot >= 0 && slot < inventory.length) { + return this.inventory[slot].extractItem(0, amount, simulate); + } + return ItemStack.EMPTY; + } + + @Override + public int getSlotLimit(int slot) { + return Integer.MAX_VALUE; + } + + @Override + public ManagedFieldHolder getFieldHolder() { + return MANAGED_FIELD_HOLDER; + } + + private static class ItemStackTransferDelegate extends ItemStackTransfer { + + private final ExportOnlyAEItemSlot[] inventory; + + public ItemStackTransferDelegate(ExportOnlyAEItemSlot[] inventory) { + super(); + this.inventory = inventory; + } + + @Override + public int getSlots() { + return inventory.length; + } + +// @Override +// public ItemStack getStackInSlot(int slot) { +// return inventory[slot].getStack(); +// } + + @Override + public void setStackInSlot(int slot, ItemStack stack) { + // NO-OP + } + + @Override + public ItemStack insertItem( + int slot, ItemStack stack, boolean simulate, boolean notifyChanges) { + return stack; + } + +// @Override +// public ItemStack extractItem(int slot, int amount, boolean simulate, boolean notifyChanges) { +// if (amount == 0) return ItemStack.EMPTY; +// validateSlotIndex(slot); +// return inventory[slot].extract(amount, simulate); +// } + + @Override + protected void validateSlotIndex(int slot) { + if (slot < 0 || slot >= getSlots()) + throw new RuntimeException( + "Slot " + slot + " not in valid range - [0," + getSlots() + ")"); + } + + @Override + public int getSlotLimit(int slot) { + return Integer.MAX_VALUE; + } + + @Override + public boolean isItemValid(int slot, ItemStack stack) { + return false; + } + +// @Override +// public ItemStackTransfer copy() { +// var copy = new BigItemStackTransfer(getSlots(), true, Integer.MAX_VALUE); +// for (int i = 0; i < inventory.length; i++) { +// copy.setStackInSlot(i, getStackInSlot(i)); +// } +// return copy; +// } + } + +} diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEItemSlot.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEItemSlot.java new file mode 100644 index 0000000000..116b260381 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAEItemSlot.java @@ -0,0 +1,110 @@ +package com.gregtechceu.gtceu.integration.ae2.slot; + +import appeng.api.stacks.AEItemKey; +import appeng.api.stacks.GenericStack; +import com.lowdragmc.lowdraglib.side.item.IItemTransfer; +import com.mojang.datafixers.util.Pair; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + +public class ExportOnlyAEItemSlot extends ExportOnlyAESlot implements IItemTransfer { + + public ExportOnlyAEItemSlot() { + super(); + } + + public ExportOnlyAEItemSlot(GenericStack config, GenericStack stock) { + super(config, stock); + } + + @Override + public ExportOnlyAEItemSlot copy() { + return new ExportOnlyAEItemSlot( + this.config == null ? null : copy(this.config), + this.stock == null ? null : copy(this.stock)); + } + + @Override + public void setStackInSlot(int slot, @NotNull ItemStack stack) { + // NO-OP + } + + @NotNull + @Override + public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate, boolean notifyChanges) { + return stack; + } + + @Override + public int getSlots() { + return 1; + } + + @NotNull + @Override + public ItemStack getStackInSlot(int slot) { + if (slot == 0 && this.stock != null) { + return this.stock.what() instanceof AEItemKey itemKey ? itemKey.toStack((int) this.stock.amount()) : + ItemStack.EMPTY; + } + return ItemStack.EMPTY; + } + + @NotNull + @Override + public ItemStack extractItem(int slot, int amount, boolean simulate, boolean notifyChanges) { + if (slot == 0 && this.stock != null) { + int extracted = (int) Math.min(this.stock.amount(), amount); + ItemStack result = this.stock.what() instanceof AEItemKey itemKey ? + itemKey.toStack((int) this.stock.amount()) : ItemStack.EMPTY.copy(); + result.setCount(extracted); + if (!simulate) { + this.stock = ExportOnlyAESlot.copy(this.stock, this.stock.amount() - extracted); + if (this.stock.amount() == 0) { + this.stock = null; + } + } + if (notifyChanges && this.onContentsChanged != null) { + this.onContentsChanged.run(); + } + return result; + } + return ItemStack.EMPTY; + } + + @Override + public void addStack(GenericStack stack) { + if (this.stock == null) { + this.stock = stack; + } else { + this.stock = GenericStack.sum(this.stock, stack); + } + this.onContentsChanged.run(); + } + + @Override + public int getSlotLimit(int slot) { + return Integer.MAX_VALUE; + } + + @Override + public boolean isItemValid(int slot, @NotNull ItemStack stack) { + return false; + } + + @Deprecated + @NotNull + @Override + public Object createSnapshot() { + return Pair.of(this.config, this.stock); + } + + @Deprecated + @Override + public void restoreFromSnapshot(Object snapshot) { + if (snapshot instanceof Pair pair) { + this.config = (GenericStack) pair.getFirst(); + this.stock = (GenericStack) pair.getSecond(); + } + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/utils/ExportOnlyAESlot.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAESlot.java similarity index 98% rename from src/main/java/com/gregtechceu/gtceu/integration/ae2/utils/ExportOnlyAESlot.java rename to src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAESlot.java index e8809e8977..e4b15c50a3 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/utils/ExportOnlyAESlot.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/ExportOnlyAESlot.java @@ -1,4 +1,4 @@ -package com.gregtechceu.gtceu.integration.ae2.utils; +package com.gregtechceu.gtceu.integration.ae2.slot; import com.lowdragmc.lowdraglib.syncdata.IContentChangeAware; import com.lowdragmc.lowdraglib.syncdata.ITagSerializable; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/utils/IConfigurableSlot.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/IConfigurableSlot.java similarity index 87% rename from src/main/java/com/gregtechceu/gtceu/integration/ae2/utils/IConfigurableSlot.java rename to src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/IConfigurableSlot.java index 65fee4e482..970779a41a 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/utils/IConfigurableSlot.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/slot/IConfigurableSlot.java @@ -1,4 +1,4 @@ -package com.gregtechceu.gtceu.integration.ae2.utils; +package com.gregtechceu.gtceu.integration.ae2.slot; import appeng.api.stacks.GenericStack;