Skip to content

Commit

Permalink
Advanced Stocking Input Bus + Advanced Stocking Input Hatch (#2367)
Browse files Browse the repository at this point in the history
(cherry picked from commit db174d2)
  • Loading branch information
serenibyss authored and ALongStringOfNumbers committed Apr 24, 2024
1 parent 10b6d30 commit 29abb94
Show file tree
Hide file tree
Showing 41 changed files with 2,004 additions and 729 deletions.
4 changes: 4 additions & 0 deletions src/main/java/gregtech/api/capability/GregtechDataCodes.java
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));
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
8 changes: 8 additions & 0 deletions src/main/java/gregtech/client/renderer/texture/Textures.java
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
45 changes: 30 additions & 15 deletions src/main/java/gregtech/common/gui/widget/appeng/AEConfigWidget.java
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import gregtech.api.util.Position;
import gregtech.api.util.Size;
import gregtech.common.gui.widget.appeng.AEConfigWidget;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.IConfigurableSlot;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.slot.IConfigurableSlot;

import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
Expand All @@ -17,13 +17,9 @@
import java.util.Collections;
import java.util.List;

/**
* @Author GlodBlock
* @Description A configurable slot
* @Date 2023/4/22-0:30
*/
public class AEConfigSlot<T extends IAEStack<T>> extends Widget implements IGhostIngredientTarget {

protected static final int DISPLAY_X_OFFSET = 18 * 5;
protected AEConfigWidget<T> parentWidget;
protected int index;
protected final static int REMOVE_ID = 1000;
Expand All @@ -43,14 +39,24 @@ public void drawInForeground(int mouseX, int mouseY) {
IConfigurableSlot<T> slot = this.parentWidget.getDisplay(this.index);
if (slot.getConfig() == null && mouseOverConfig(mouseX, mouseY)) {
List<String> hoverStringList = new ArrayList<>();
hoverStringList.add(I18n.format("gregtech.gui.config_slot"));
hoverStringList.add(I18n.format("gregtech.gui.config_slot.set"));
hoverStringList.add(I18n.format("gregtech.gui.config_slot.scroll"));
hoverStringList.add(I18n.format("gregtech.gui.config_slot.remove"));
drawHoveringText(ItemStack.EMPTY, hoverStringList, -1, mouseX, mouseY);
addHoverText(hoverStringList);
if (!hoverStringList.isEmpty()) {
drawHoveringText(ItemStack.EMPTY, hoverStringList, -1, mouseX, mouseY);
}
}
}

protected void addHoverText(List<String> hoverText) {
hoverText.add(I18n.format("gregtech.gui.config_slot"));
if (!parentWidget.isStocking()) {
hoverText.add(I18n.format("gregtech.gui.config_slot.set"));
hoverText.add(I18n.format("gregtech.gui.config_slot.scroll"));
} else {
hoverText.add(I18n.format("gregtech.gui.config_slot.set_only"));
}
hoverText.add(I18n.format("gregtech.gui.config_slot.remove"));
}

public void setSelect(boolean val) {
this.select = val;
}
Expand All @@ -62,11 +68,15 @@ protected boolean mouseOverConfig(int mouseX, int mouseY) {

protected boolean mouseOverStock(int mouseX, int mouseY) {
Position position = getPosition();
return isMouseOver(position.x, position.y + 18, 18, 18, mouseX, mouseY);
return isMouseOver(position.x + DISPLAY_X_OFFSET, position.y, 18, 18, mouseX, mouseY);
}

@Override
public List<IGhostIngredientHandler.Target<?>> getPhantomTargets(Object ingredient) {
return Collections.emptyList();
}

public AEConfigWidget<T> getParentWidget() {
return parentWidget;
}
}
Loading

0 comments on commit 29abb94

Please sign in to comment.