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

Advanced Stocking Input Bus + Advanced Stocking Input Hatch #2367

Merged
merged 26 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 22 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
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,8 @@ public static int assignId() {
// Alarm
public static final int UPDATE_SOUND = assignId();
public static final int UPDATE_RADIUS = assignId();

// ME Parts
public static final int UPDATE_AUTO_PULL = assignId();
public static final int UPDATE_ONLINE_STATUS = assignId();
}
6 changes: 6 additions & 0 deletions src/main/java/gregtech/api/gui/GuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class GuiTextures {
public static final TextureArea FLUID_TANK_OVERLAY = TextureArea
.fullImage("textures/gui/base/fluid_tank_overlay.png");
public static final TextureArea SLOT = AdoptableTextureArea.fullImage("textures/gui/base/slot.png", 18, 18, 1, 1);
public static final TextureArea SLOT_DARK = AdoptableTextureArea.fullImage("textures/gui/base/slot_dark.png", 18,
18, 1, 1);
@Deprecated // idek what this texture is
public static final TextureArea SLOT_DARKENED = TextureArea.fullImage("textures/gui/base/darkened_slot.png");
public static final SteamTexture SLOT_STEAM = SteamTexture.fullImage("textures/gui/base/slot_%s.png");
public static final TextureArea TOGGLE_BUTTON_BACK = TextureArea
Expand Down Expand Up @@ -504,6 +507,9 @@ public class GuiTextures {
public static final TextureArea CONFIG_ARROW_DARK = TextureArea
.fullImage("textures/gui/widget/config_arrow_dark.png");
public static final TextureArea SELECT_BOX = TextureArea.fullImage("textures/gui/widget/select_box.png");
public static final TextureArea BUTTON_AUTO_PULL = TextureArea
.fullImage("textures/gui/widget/button_me_auto_pull.png");
public static final TextureArea ARROW_DOUBLE = TextureArea.fullImage("textures/gui/widget/arrow_double.png");

// Fusion Reactor custom images
public static final TextureArea FUSION_REACTOR_MK1_TITLE = TextureArea
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ public interface IMultiblockPart {
default boolean canPartShare() {
return true;
}

/** Called when distinct mode is toggled on the controller that this part is attached to */
default void onDistinctChange(boolean newValue) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ public void checkStructurePattern() {
abilityPart.registerAbilities(abilityInstancesList);
}
}
parts.forEach(part -> part.addToMultiBlock(this));
this.multiblockParts.addAll(parts);
this.multiblockAbilities.putAll(abilities);
parts.forEach(part -> part.addToMultiBlock(this));
TechLord22 marked this conversation as resolved.
Show resolved Hide resolved
this.structureFormed = true;
writeCustomData(STRUCTURE_FORMED, buf -> buf.writeBoolean(true));
formStructure(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public boolean isDistinct() {
public void setDistinct(boolean isDistinct) {
this.isDistinct = isDistinct;
recipeMapWorkable.onDistinctChanged();
getMultiblockParts().forEach(part -> part.onDistinctChange(isDistinct));
// mark buses as changed on distinct toggle
if (this.isDistinct) {
this.notifiedItemInputList.addAll(this.getAbilities(MultiblockAbility.IMPORT_ITEMS));
Expand Down
50 changes: 48 additions & 2 deletions src/main/java/gregtech/api/recipes/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,54 @@ public static Recipe trimRecipeOutputs(Recipe currentRecipe, RecipeMap<?> recipe

public final boolean matches(boolean consumeIfSuccessful, IItemHandlerModifiable inputs,
IMultipleTankHandler fluidInputs) {
return matches(consumeIfSuccessful, GTUtility.itemHandlerToList(inputs),
GTUtility.fluidHandlerToList(fluidInputs));
Pair<Boolean, int[]> fluids = null;
Pair<Boolean, int[]> items = null;

if (fluidInputs.getFluidTanks().size() > 0) {
fluids = matchesFluid(GTUtility.fluidHandlerToList(fluidInputs));
if (!fluids.getKey()) {
return false;
}
}

if (inputs.getSlots() > 0) {
items = matchesItems(GTUtility.itemHandlerToList(inputs));
if (!items.getKey()) {
return false;
}
}

if (consumeIfSuccessful) {
if (fluids != null) {
int[] fluidAmountInTank = fluids.getValue();
var backedList = fluidInputs.getFluidTanks();

for (int i = 0; i < fluidAmountInTank.length; i++) {
var tank = backedList.get(i);
FluidStack fluidStack = tank.getFluid();
int fluidAmount = fluidAmountInTank[i];

if (fluidStack == null || fluidStack.amount == fluidAmount) {
continue;
}
tank.drain(Math.abs(fluidAmount - fluidStack.amount), true);
}
}
if (items != null) {
int[] itemAmountInSlot = items.getValue();
for (int i = 0; i < itemAmountInSlot.length; i++) {
ItemStack itemInSlot = inputs.getStackInSlot(i);
int itemAmount = itemAmountInSlot[i];

if (itemInSlot.isEmpty() || itemInSlot.getCount() == itemAmount) {
continue;
}
inputs.extractItem(i, Math.abs(itemAmount - itemInSlot.getCount()), false);
}
}
}

return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,18 @@ public class Textures {

public static final SimpleOverlayRenderer ME_OUTPUT_HATCH = new SimpleOverlayRenderer(
"overlay/appeng/me_output_hatch");
public static final SimpleOverlayRenderer ME_OUTPUT_HATCH_ACTIVE = new SimpleOverlayRenderer(
"overlay/appeng/me_output_hatch_active");
public static final SimpleOverlayRenderer ME_INPUT_HATCH = new SimpleOverlayRenderer(
"overlay/appeng/me_input_hatch");
public static final SimpleOverlayRenderer ME_INPUT_HATCH_ACTIVE = new SimpleOverlayRenderer(
"overlay/appeng/me_input_hatch_active");
public static final SimpleOverlayRenderer ME_OUTPUT_BUS = new SimpleOverlayRenderer("overlay/appeng/me_output_bus");
public static final SimpleOverlayRenderer ME_OUTPUT_BUS_ACTIVE = new SimpleOverlayRenderer(
"overlay/appeng/me_output_bus_active");
public static final SimpleOverlayRenderer ME_INPUT_BUS = new SimpleOverlayRenderer("overlay/appeng/me_input_bus");
public static final SimpleOverlayRenderer ME_INPUT_BUS_ACTIVE = new SimpleOverlayRenderer(
"overlay/appeng/me_input_bus_active");

public static final ResourceLocation ACE_CAPE_TEXTURE = gregtechId("textures/capes/acecape.png");
public static final ResourceLocation AGENDER_CAPE_TEXTURE = gregtechId("textures/capes/agendercape.png");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import gregtech.api.util.Size;
import gregtech.common.gui.widget.appeng.slot.AEConfigSlot;
import gregtech.common.gui.widget.appeng.slot.AmountSetSlot;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.IConfigurableSlot;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.slot.IConfigurableSlot;

import appeng.api.storage.data.IAEStack;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
Expand All @@ -26,49 +26,64 @@ public abstract class AEConfigWidget<T extends IAEStack<T>> extends AbstractWidg
protected Int2ObjectMap<IConfigurableSlot<T>> changeMap = new Int2ObjectOpenHashMap<>();
protected IConfigurableSlot<T>[] displayList;
protected AmountSetSlot<T> amountSetWidget;
protected final boolean isStocking;
protected final static int UPDATE_ID = 1000;

public AEConfigWidget(int x, int y, IConfigurableSlot<T>[] config) {
public AEConfigWidget(int x, int y, IConfigurableSlot<T>[] config, boolean isStocking) {
super(new Position(x, y), new Size(config.length * 18, 18 * 2));
this.isStocking = isStocking;
this.config = config;
this.init();
this.amountSetWidget = new AmountSetSlot<>(80, -40, this);
this.addWidget(this.amountSetWidget);
this.addWidget(this.amountSetWidget.getText());
this.amountSetWidget.setVisible(false);
this.amountSetWidget.getText().setVisible(false);
if (!isStocking()) {
this.amountSetWidget = new AmountSetSlot<>(80, -40, this);
this.addWidget(this.amountSetWidget);
this.addWidget(this.amountSetWidget.getText());
this.amountSetWidget.setVisible(false);
this.amountSetWidget.getText().setVisible(false);
}
}

public void enableAmount(int slotIndex) {
// Only allow the amount set widget if not stocking, as amount is useless for stocking
if (isStocking()) return;
this.amountSetWidget.setSlotIndex(slotIndex);
this.amountSetWidget.setVisible(true);
this.amountSetWidget.getText().setVisible(true);
}

public void disableAmount() {
// Only allow the amount set widget if not stocking, as amount is useless for stocking
if (isStocking()) return;
this.amountSetWidget.setSlotIndex(-1);
this.amountSetWidget.setVisible(false);
this.amountSetWidget.getText().setVisible(false);
}

@Override
public boolean mouseClicked(int mouseX, int mouseY, int button) {
if (this.amountSetWidget.isVisible()) {
if (this.amountSetWidget.getText().mouseClicked(mouseX, mouseY, button)) {
return true;
// Only allow the amount set widget if not stocking, as amount is useless for stocking
if (!isStocking()) {
if (this.amountSetWidget.isVisible()) {
if (this.amountSetWidget.getText().mouseClicked(mouseX, mouseY, button)) {
return true;
}
}
}
for (Widget w : this.widgets) {
if (w instanceof AEConfigSlot<?>) {
((AEConfigSlot<?>) w).setSelect(false);
for (Widget w : this.widgets) {
if (w instanceof AEConfigSlot<?>) {
((AEConfigSlot<?>) w).setSelect(false);
}
}
this.disableAmount();
}
this.disableAmount();
return super.mouseClicked(mouseX, mouseY, button);
}

abstract void init();

public boolean isStocking() {
return isStocking;
}

@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
package gregtech.common.gui.widget.appeng;

import gregtech.common.gui.widget.appeng.slot.AEFluidConfigSlot;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.IConfigurableSlot;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.MetaTileEntityMEInputHatch;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.slot.ExportOnlyAEFluidList;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.slot.ExportOnlyAEFluidSlot;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.slot.IConfigurableSlot;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.stack.WrappedFluidStack;

import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fluids.FluidStack;

import appeng.api.storage.data.IAEFluidStack;

/**
* @Author GlodBlock
* @Description Display {@link IAEFluidStack} config
* @Date 2023/4/21-1:45
*/
public class AEFluidConfigWidget extends AEConfigWidget<IAEFluidStack> {

public AEFluidConfigWidget(int x, int y, IConfigurableSlot<IAEFluidStack>[] config) {
super(x, y, config);
final ExportOnlyAEFluidList fluidList;

public AEFluidConfigWidget(int x, int y, ExportOnlyAEFluidList fluidList) {
super(x, y, fluidList.getInventory(), fluidList.isStocking());
this.fluidList = fluidList;
}

@Override
@SuppressWarnings("unchecked")
void init() {
int line;
final int size = (int) Math.sqrt(this.config.length);
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 MetaTileEntityMEInputHatch.ExportOnlyAEFluid();
this.cached[index] = new MetaTileEntityMEInputHatch.ExportOnlyAEFluid();
line = index / 8;
this.addWidget(new AEFluidConfigSlot((index - line * 8) * 18, line * (18 * 2 + 2), this, index));
for (int h = 0; h < size; h++) {
for (int w = 0; w < size; w++) {
final int index = h * size + w;
this.displayList[index] = new ExportOnlyAEFluidSlot();
this.cached[index] = new ExportOnlyAEFluidSlot();
this.addWidget(new AEFluidConfigSlot(w * 18, h * 18, this, index));
}
}
}

public boolean hasStackInConfig(FluidStack stack) {
return fluidList.hasStackInConfig(stack, true);
}

public boolean isAutoPull() {
return fluidList.isAutoPull();
}

@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
super.readUpdateInfo(id, buffer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
package gregtech.common.gui.widget.appeng;

import gregtech.common.gui.widget.appeng.slot.AEItemConfigSlot;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.IConfigurableSlot;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.MetaTileEntityMEInputBus;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.slot.ExportOnlyAEItemList;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.slot.ExportOnlyAEItemSlot;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.slot.IConfigurableSlot;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.stack.WrappedItemStack;

import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;

import appeng.api.storage.data.IAEItemStack;

/**
* @Author GlodBlock
* @Description Display {@link IAEItemStack} config
* @Date 2023/4/22-1:02
*/
public class AEItemConfigWidget extends AEConfigWidget<IAEItemStack> {

public AEItemConfigWidget(int x, int y, IConfigurableSlot<IAEItemStack>[] config) {
super(x, y, config);
final ExportOnlyAEItemList itemList;

public AEItemConfigWidget(int x, int y, ExportOnlyAEItemList itemList) {
super(x, y, itemList.getInventory(), itemList.isStocking());
this.itemList = itemList;
}

@Override
@SuppressWarnings("unchecked")
void init() {
int line;
final int size = (int) Math.sqrt(this.config.length);
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 MetaTileEntityMEInputBus.ExportOnlyAEItem();
this.cached[index] = new MetaTileEntityMEInputBus.ExportOnlyAEItem();
line = index / 8;
this.addWidget(new AEItemConfigSlot((index - line * 8) * 18, line * (18 * 2 + 2), this, index));
for (int h = 0; h < size; h++) {
for (int w = 0; w < size; w++) {
final int index = h * size + w;
this.displayList[index] = new ExportOnlyAEItemSlot();
this.cached[index] = new ExportOnlyAEItemSlot();
this.addWidget(new AEItemConfigSlot(w * 18, h * 18, this, index));
}
}
}

public boolean hasStackInConfig(ItemStack stack) {
return itemList.hasStackInConfig(stack, true);
}

public boolean isAutoPull() {
return itemList.isAutoPull();
}

@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
super.readUpdateInfo(id, buffer);
Expand Down
Loading
Loading