Skip to content

Commit b194f37

Browse files
authored
Add setting for pick block to request the item when not available (#361)
1 parent 9ecea16 commit b194f37

File tree

7 files changed

+36
-7
lines changed

7 files changed

+36
-7
lines changed

ae2wtlib_api/src/main/java/de/mari_023/ae2wtlib/api/AE2wtlibComponents.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public class AE2wtlibComponents {
5353
.persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL));
5454
public static final DataComponentType<Boolean> PICK_BLOCK = register("pick_block", builder -> builder
5555
.persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL));
56+
public static final DataComponentType<Boolean> CRAFT_IF_MISSING = register("craft_if_missing", builder -> builder
57+
.persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL));
5658

5759
public static final DataComponentType<CompoundTag> PATTERN_ENCODING_LOGIC = register("pattern_encoding_logic",
5860
COMPOUND_TAG_CODECS);

ae2wtlib_api/src/main/java/de/mari_023/ae2wtlib/api/TextConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public static Component getInsertMode(IncludeExclude includeExclude) {
9595
public static final Component TERMINAL_SETTINGS = Component
9696
.translatable("gui.ae2wtlib.wireless_terminal_settings_title");
9797
public static final Component PICK_BLOCK = Component.translatable("gui.ae2wtlib.pick_block.text");
98+
public static final Component CRAFT_IF_MISSING = Component.translatable("gui.ae2wtlib.craft_if_missing.text");
9899
public static final Component RESTOCK = Component.translatable("gui.ae2wtlib.restock.text");
99100
public static final Component MAGNET = Component.translatable("gui.ae2wtlib.magnet.text");
100101
public static final Component PICKUP_TO_ME = Component.translatable("gui.ae2wtlib.pickup_to_me.text");

src/main/java/de/mari_023/ae2wtlib/AE2wtlibEvents.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import appeng.api.config.IncludeExclude;
1616
import appeng.api.stacks.AEItemKey;
1717
import appeng.me.helpers.PlayerSource;
18+
import appeng.menu.me.crafting.CraftAmountMenu;
1819

1920
import de.mari_023.ae2wtlib.api.AE2wtlibComponents;
2021
import de.mari_023.ae2wtlib.api.AE2wtlibTags;
@@ -181,9 +182,15 @@ public static void pickBlock(ServerPlayer player, ItemStack stack) {
181182
if (insert < toReplace.getCount())
182183
return;
183184
int targetAmount = stack.getMaxStackSize();
184-
var extracted = networkInventory.extract(AEItemKey.of(stack), targetAmount, Actionable.SIMULATE, playerSource);
185-
if (extracted == 0)
185+
var what = AEItemKey.of(stack);
186+
var extracted = networkInventory.extract(what, targetAmount, Actionable.SIMULATE, playerSource);
187+
if (extracted == 0) {
188+
if (!terminal.getOrDefault(AE2wtlibComponents.CRAFT_IF_MISSING, false)
189+
|| cTHandler.getTargetGrid().getCraftingService().getCraftingFor(what).isEmpty())
190+
return;
191+
CraftAmountMenu.open(player, cTHandler.getLocator(), what, 1);
186192
return;
193+
}
187194

188195
insert = networkInventory.insert(AEItemKey.of(toReplace), toReplace.getCount(), Actionable.MODULATE,
189196
playerSource);

src/main/java/de/mari_023/ae2wtlib/networking/TerminalSettingsPacket.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import de.mari_023.ae2wtlib.wct.magnet_card.MagnetMode;
1515

1616
public record TerminalSettingsPacket(ItemMenuHostLocator terminal, boolean pickBlock, boolean restock, boolean magnet,
17-
boolean pickupToME) implements AE2wtlibPacket {
17+
boolean pickupToME, boolean craftIfMissing) implements AE2wtlibPacket {
1818

1919
public static final Type<TerminalSettingsPacket> ID = new Type<>(AE2wtlibAPI.id("terminal_settings"));
2020
public static final StreamCodec<RegistryFriendlyByteBuf, TerminalSettingsPacket> STREAM_CODEC = StreamCodec
@@ -24,11 +24,13 @@ public record TerminalSettingsPacket(ItemMenuHostLocator terminal, boolean pickB
2424
ByteBufCodecs.BOOL, TerminalSettingsPacket::restock,
2525
ByteBufCodecs.BOOL, TerminalSettingsPacket::magnet,
2626
ByteBufCodecs.BOOL, TerminalSettingsPacket::pickupToME,
27+
ByteBufCodecs.BOOL, TerminalSettingsPacket::craftIfMissing,
2728
TerminalSettingsPacket::new);
2829
@Override
2930
public void processPacketData(Player player) {
3031
var stack = terminal.locateItem(player);
3132
stack.set(AE2wtlibComponents.PICK_BLOCK, pickBlock);
33+
stack.set(AE2wtlibComponents.CRAFT_IF_MISSING, craftIfMissing);
3234
stack.set(AE2wtlibComponents.RESTOCK, restock);
3335
var magnetSettings = stack.getOrDefault(AE2wtlibAdditionalComponents.MAGNET_SETTINGS, MagnetMode.OFF);
3436
magnetSettings = magnetSettings.set(magnet, pickupToME);

src/main/java/de/mari_023/ae2wtlib/wct/WirelessTerminalSettingsScreen.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
import de.mari_023.ae2wtlib.wct.magnet_card.MagnetMode;
1919

2020
public class WirelessTerminalSettingsScreen extends AESubScreen<WCTMenu, WCTScreen> {
21-
private final AECheckbox pickBlock = widgets.addCheckbox("pickBlock", TextConstants.PICK_BLOCK, this::save);
21+
private final AECheckbox pickBlock = widgets.addCheckbox("pickBlock", TextConstants.PICK_BLOCK,
22+
this::changeVisibility);
23+
private final AECheckbox craftIfMissing = widgets.addCheckbox("craftIfMissing", TextConstants.CRAFT_IF_MISSING,
24+
this::save);
2225
private final AECheckbox restock = widgets.addCheckbox("restock", TextConstants.RESTOCK, this::save);
2326
private final AECheckbox magnet = widgets.addCheckbox("magnet", TextConstants.MAGNET, this::save);
2427
private final AECheckbox pickupToME = widgets.addCheckbox("pickupToME", TextConstants.PICKUP_TO_ME, this::save);
@@ -29,6 +32,8 @@ public WirelessTerminalSettingsScreen(WCTScreen parent) {
2932
new TabButton(Icon.BACK, menu.getHost().getMainMenuIcon().getHoverName(), btn -> returnToParent()));
3033

3134
pickBlock.setSelected(stack().getOrDefault(AE2wtlibComponents.PICK_BLOCK, false));
35+
craftIfMissing.setSelected(stack().getOrDefault(AE2wtlibComponents.CRAFT_IF_MISSING, false));
36+
craftIfMissing.active = pickBlock.isSelected();
3237
restock.setSelected(stack().getOrDefault(AE2wtlibComponents.RESTOCK, false));
3338
magnet.setSelected(stack().getOrDefault(AE2wtlibAdditionalComponents.MAGNET_SETTINGS, MagnetMode.OFF).magnet());
3439
pickupToME.setSelected(
@@ -49,11 +54,17 @@ private ItemStack stack() {
4954
return ((WTMenuHost) getMenu().getHost()).getItemStack();
5055
}
5156

57+
private void changeVisibility() {
58+
craftIfMissing.active = pickBlock.isSelected();
59+
save();
60+
}
61+
5262
private void save() {
5363
var locator = ((WTMenuHost) getMenu().getHost()).getLocator();
5464
if (locator == null)
5565
return;
5666
PacketDistributor.sendToServer(new TerminalSettingsPacket(locator,
57-
pickBlock.isSelected(), restock.isSelected(), magnet.isSelected(), pickupToME.isSelected()));
67+
pickBlock.isSelected(), restock.isSelected(), magnet.isSelected(), pickupToME.isSelected(),
68+
craftIfMissing.isSelected()));
5869
}
5970
}

src/main/resources/assets/ae2/screens/wtlib/wireless_terminal_settings.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"search_settings_title": {
1919
"position": {
2020
"left": 8,
21-
"top": 65
21+
"top": 73
2222
},
2323
"text": {
2424
"translate": "gui.ae2wtlib.magnet_settings_title"
@@ -37,11 +37,16 @@
3737
"top": 25,
3838
"width": 180
3939
},
40-
"restock": {
40+
"craftIfMissing": {
4141
"left": 10,
4242
"top": 41,
4343
"width": 180
4444
},
45+
"restock": {
46+
"left": 10,
47+
"top": 57,
48+
"width": 180
49+
},
4550
"magnet": {
4651
"left": 10,
4752
"top": 83,

src/main/resources/assets/ae2wtlib/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"gui.ae2wtlib.wireless_terminal_settings_title" : "Wireless Terminal Settings",
2525
"gui.ae2wtlib.magnet_settings_title" : "Magnet Settings",
2626
"gui.ae2wtlib.pick_block.text" : "Enable Pick Block",
27+
"gui.ae2wtlib.craft_if_missing.text": "Craft if Missing",
2728
"gui.ae2wtlib.restock.text" : "Restock",
2829
"gui.ae2wtlib.magnet.text" : "Magnet",
2930
"gui.ae2wtlib.pickup_to_me.text" : "Pickup to ME System",

0 commit comments

Comments
 (0)