Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -53,6 +53,8 @@ public class AE2wtlibComponents {
.persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL));
public static final DataComponentType<Boolean> PICK_BLOCK = register("pick_block", builder -> builder
.persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL));
public static final DataComponentType<Boolean> CRAFT_IF_MISSING = register("craft_if_missing", builder -> builder
.persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL));

public static final DataComponentType<CompoundTag> PATTERN_ENCODING_LOGIC = register("pattern_encoding_logic",
COMPOUND_TAG_CODECS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static Component getInsertMode(IncludeExclude includeExclude) {
public static final Component TERMINAL_SETTINGS = Component
.translatable("gui.ae2wtlib.wireless_terminal_settings_title");
public static final Component PICK_BLOCK = Component.translatable("gui.ae2wtlib.pick_block.text");
public static final Component CRAFT_IF_MISSING = Component.translatable("gui.ae2wtlib.craft_if_missing.text");
public static final Component RESTOCK = Component.translatable("gui.ae2wtlib.restock.text");
public static final Component MAGNET = Component.translatable("gui.ae2wtlib.magnet.text");
public static final Component PICKUP_TO_ME = Component.translatable("gui.ae2wtlib.pickup_to_me.text");
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/de/mari_023/ae2wtlib/AE2wtlibEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import appeng.api.config.IncludeExclude;
import appeng.api.stacks.AEItemKey;
import appeng.me.helpers.PlayerSource;
import appeng.menu.me.crafting.CraftAmountMenu;

import de.mari_023.ae2wtlib.api.AE2wtlibComponents;
import de.mari_023.ae2wtlib.api.AE2wtlibTags;
Expand Down Expand Up @@ -181,9 +182,15 @@ public static void pickBlock(ServerPlayer player, ItemStack stack) {
if (insert < toReplace.getCount())
return;
int targetAmount = stack.getMaxStackSize();
var extracted = networkInventory.extract(AEItemKey.of(stack), targetAmount, Actionable.SIMULATE, playerSource);
if (extracted == 0)
var what = AEItemKey.of(stack);
var extracted = networkInventory.extract(what, targetAmount, Actionable.SIMULATE, playerSource);
if (extracted == 0) {
if (!terminal.getOrDefault(AE2wtlibComponents.CRAFT_IF_MISSING, false)
|| cTHandler.getTargetGrid().getCraftingService().getCraftingFor(what).isEmpty())
return;
CraftAmountMenu.open(player, cTHandler.getLocator(), what, 1);
return;
}

insert = networkInventory.insert(AEItemKey.of(toReplace), toReplace.getCount(), Actionable.MODULATE,
playerSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import de.mari_023.ae2wtlib.wct.magnet_card.MagnetMode;

public record TerminalSettingsPacket(ItemMenuHostLocator terminal, boolean pickBlock, boolean restock, boolean magnet,
boolean pickupToME) implements AE2wtlibPacket {
boolean pickupToME, boolean craftIfMissing) implements AE2wtlibPacket {

public static final Type<TerminalSettingsPacket> ID = new Type<>(AE2wtlibAPI.id("terminal_settings"));
public static final StreamCodec<RegistryFriendlyByteBuf, TerminalSettingsPacket> STREAM_CODEC = StreamCodec
Expand All @@ -24,11 +24,13 @@ public record TerminalSettingsPacket(ItemMenuHostLocator terminal, boolean pickB
ByteBufCodecs.BOOL, TerminalSettingsPacket::restock,
ByteBufCodecs.BOOL, TerminalSettingsPacket::magnet,
ByteBufCodecs.BOOL, TerminalSettingsPacket::pickupToME,
ByteBufCodecs.BOOL, TerminalSettingsPacket::craftIfMissing,
TerminalSettingsPacket::new);
@Override
public void processPacketData(Player player) {
var stack = terminal.locateItem(player);
stack.set(AE2wtlibComponents.PICK_BLOCK, pickBlock);
stack.set(AE2wtlibComponents.CRAFT_IF_MISSING, craftIfMissing);
stack.set(AE2wtlibComponents.RESTOCK, restock);
var magnetSettings = stack.getOrDefault(AE2wtlibAdditionalComponents.MAGNET_SETTINGS, MagnetMode.OFF);
magnetSettings = magnetSettings.set(magnet, pickupToME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import de.mari_023.ae2wtlib.wct.magnet_card.MagnetMode;

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

pickBlock.setSelected(stack().getOrDefault(AE2wtlibComponents.PICK_BLOCK, false));
craftIfMissing.setSelected(stack().getOrDefault(AE2wtlibComponents.CRAFT_IF_MISSING, false));
craftIfMissing.active = pickBlock.isSelected();
restock.setSelected(stack().getOrDefault(AE2wtlibComponents.RESTOCK, false));
magnet.setSelected(stack().getOrDefault(AE2wtlibAdditionalComponents.MAGNET_SETTINGS, MagnetMode.OFF).magnet());
pickupToME.setSelected(
Expand All @@ -49,11 +54,17 @@ private ItemStack stack() {
return ((WTMenuHost) getMenu().getHost()).getItemStack();
}

private void changeVisibility() {
craftIfMissing.active = pickBlock.isSelected();
save();
}

private void save() {
var locator = ((WTMenuHost) getMenu().getHost()).getLocator();
if (locator == null)
return;
PacketDistributor.sendToServer(new TerminalSettingsPacket(locator,
pickBlock.isSelected(), restock.isSelected(), magnet.isSelected(), pickupToME.isSelected()));
pickBlock.isSelected(), restock.isSelected(), magnet.isSelected(), pickupToME.isSelected(),
craftIfMissing.isSelected()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"search_settings_title": {
"position": {
"left": 8,
"top": 65
"top": 73
},
"text": {
"translate": "gui.ae2wtlib.magnet_settings_title"
Expand All @@ -37,11 +37,16 @@
"top": 25,
"width": 180
},
"restock": {
"craftIfMissing": {
"left": 10,
"top": 41,
"width": 180
},
"restock": {
"left": 10,
"top": 57,
"width": 180
},
"magnet": {
"left": 10,
"top": 83,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/ae2wtlib/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"gui.ae2wtlib.wireless_terminal_settings_title" : "Wireless Terminal Settings",
"gui.ae2wtlib.magnet_settings_title" : "Magnet Settings",
"gui.ae2wtlib.pick_block.text" : "Enable Pick Block",
"gui.ae2wtlib.craft_if_missing.text": "Craft if Missing",
"gui.ae2wtlib.restock.text" : "Restock",
"gui.ae2wtlib.magnet.text" : "Magnet",
"gui.ae2wtlib.pickup_to_me.text" : "Pickup to ME System",
Expand Down
Loading