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

实现ME库存监听来通知机器检查配方 #11

Merged
merged 2 commits into from
Jun 7, 2024
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
14 changes: 11 additions & 3 deletions src/generated/resources/assets/gregiceng/lang/en_ud.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"block.gregiceng.adv_stocking_bus": "snᗺ ʇnduI buıʞɔoʇS pǝɔuɐʌpⱯ ƎW",
"block.gregiceng.adv_stocking_bus.desc.0": "sǝɹnʇɔnɹʇs ʞɔoןq ıʇןnɯ oʇ sɯǝʇı ǝpıʌoɹd oʇ ʞɹoʍʇǝu ƎW ǝɥʇ uı sɯǝʇı buıs∩",
"block.gregiceng.adv_stocking_bus.desc.1": "ǝpoɯ ןןnd ɔıʇɐɯoʇnⱯ sɐH",
"block.gregiceng.adv_stocking_hatch": "ɥɔʇɐH ʇnduI buıʞɔoʇS pǝɔuɐʌpⱯ ƎW",
"block.gregiceng.adv_stocking_hatch.desc.0": "sǝɹnʇɔnɹʇs ʞɔoןq ıʇןnɯ oʇ spınןɟ ǝpıʌoɹd oʇ ʞɹoʍʇǝu ƎW ǝɥʇ uı spınןɟ buıs∩",
"block.gregiceng.adv_stocking_hatch.desc.1": "ǝpoɯ ןןnd ɔıʇɐɯoʇnⱯ sɐH",
"block.gregiceng.crafting_io_buffer": "ɹǝɟɟnᗺ OI buıʇɟɐɹƆ ƎW",
"block.gregiceng.crafting_io_buffer.desc.0": "",
"block.gregiceng.crafting_io_buffer.desc.0": "uǝʇʇɐd ㄣϛ uıɐʇuoɔ uɐɔ puɐ ʞɹoʍʇǝu ƎW ǝɥʇ oʇ pǝʇɔǝuuoɔ ǝq ʇsnW",
"block.gregiceng.crafting_io_buffer.desc.1": "sʇoןs ʇsʎןɐʇɐɔ pınןɟ puɐ sɯǝʇı 6 buıʌɐH",
"block.gregiceng.crafting_io_buffer.desc.2": "ʞɹoʍʇǝu ǝɥʇ oʇ ʞɔɐq ʍoןɟ ʍoןןⱯ",
"block.gregiceng.crafting_io_slave": "ǝʌɐןS OI buıʇɟɐɹƆ ƎW",
"block.gregiceng.crafting_io_slave.desc.0": "",
"block.gregiceng.ev_input_buffer": "ɹǝɟɟnᗺ ʇnduI ΛƎϛ§",
Expand All @@ -18,7 +24,9 @@
"block.gregiceng.opv_output_buffer": "ɹǝɟɟnᗺ ʇndʇnO ΛdOן§6§",
"block.gregiceng.output_buffer.desc": "sʞɔoןqıʇןnW ɹoɟ ʇndʇnO pınןℲ puɐ ɯǝʇI",
"block.gregiceng.stocking_bus": "snᗺ ʇnduI buıʞɔoʇS ƎW",
"block.gregiceng.stocking_bus.desc.0": "sǝɹnʇɔnɹʇs ʞɔoןq ıʇןnɯ oʇ sɯǝʇı ǝpıʌoɹd oʇ ʞɹoʍʇǝu ƎW ǝɥʇ uı sɯǝʇı buıs∩",
"block.gregiceng.stocking_hatch": "ɥɔʇɐH ʇnduI buıʞɔoʇS ƎW",
"block.gregiceng.stocking_hatch.desc.0": "sǝɹnʇɔnɹʇs ʞɔoןq ıʇןnɯ oʇ spınןɟ ǝpıʌoɹd oʇ ʞɹoʍʇǝu ƎW ǝɥʇ uı spınןɟ buıs∩",
"block.gregiceng.uev_input_buffer": "ɹǝɟɟnᗺ ʇnduI ΛƎ∩ɐ§",
"block.gregiceng.uev_output_buffer": "ɹǝɟɟnᗺ ʇndʇnO ΛƎ∩ɐ§",
"block.gregiceng.uhv_input_buffer": "ɹǝɟɟnᗺ ʇnduI ΛH∩ㄣ§",
Expand All @@ -33,8 +41,8 @@
"block.gregiceng.zpm_output_buffer": "ɹǝɟɟnᗺ ʇndʇnO WԀZɔ§",
"config.gregiceng.option.enableMoreAbility": "ǝʌɐןS/ɹǝɟɟnᗺ OI buıʇɟɐɹƆ ɹoɟ ʎʇıןıqⱯ ǝɹoW ǝןqɐuƎ",
"config.jade.plugin_gregiceng.crafting_io_buffer": "ɹǝɟɟnᗺ OI buıʇɟɐɹƆ",
"gui.gregiceng.auto_pull_me.desc.disabled": "pǝןqɐsıp sı uɹnʇǝᴚ ɔıʇɐɯoʇnⱯ",
"gui.gregiceng.auto_pull_me.desc.enabled": "uo sı uɹnʇǝᴚ ɔıʇɐɯoʇnⱯ",
"gui.gregiceng.auto_pull_me.desc.disabled": "pǝןqɐsıp sı ןןnd ɔıʇɐɯoʇnⱯ",
"gui.gregiceng.auto_pull_me.desc.enabled": "uo sı ןןnd ɔıʇɐɯoʇnⱯ",
"gui.gregiceng.automatic_return.desc.disabled": "pǝןqɐsıp sı uɹnʇǝᴚ ɔıʇɐɯoʇnⱯ",
"gui.gregiceng.automatic_return.desc.enabled": "uo sı uɹnʇǝᴚ ɔıʇɐɯoʇnⱯ",
"gui.gregiceng.refund_all.desc": "ןןnɟ uı sןɐıɹǝʇɐɯ ʍɐɹ punɟǝᴚ",
Expand Down
14 changes: 11 additions & 3 deletions src/generated/resources/assets/gregiceng/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"block.gregiceng.adv_stocking_bus": "ME Advanced Stocking Input Bus",
"block.gregiceng.adv_stocking_bus.desc.0": "Using items in the ME network to provide items to multi block structures",
"block.gregiceng.adv_stocking_bus.desc.1": "Has Automatic pull mode",
"block.gregiceng.adv_stocking_hatch": "ME Advanced Stocking Input Hatch",
"block.gregiceng.adv_stocking_hatch.desc.0": "Using fluids in the ME network to provide fluids to multi block structures",
"block.gregiceng.adv_stocking_hatch.desc.1": "Has Automatic pull mode",
"block.gregiceng.crafting_io_buffer": "ME Crafting IO Buffer",
"block.gregiceng.crafting_io_buffer.desc.0": "",
"block.gregiceng.crafting_io_buffer.desc.0": "Must be connected to the ME network and can contain 54 patten",
"block.gregiceng.crafting_io_buffer.desc.1": "Having 9 items and fluid catalyst slots",
"block.gregiceng.crafting_io_buffer.desc.2": "Allow flow back to the network",
"block.gregiceng.crafting_io_slave": "ME Crafting IO Slave",
"block.gregiceng.crafting_io_slave.desc.0": "",
"block.gregiceng.ev_input_buffer": "§5EV Input Buffer",
Expand All @@ -18,7 +24,9 @@
"block.gregiceng.opv_output_buffer": "§9§lOpV Output Buffer",
"block.gregiceng.output_buffer.desc": "Item and Fluid Output for Multiblocks",
"block.gregiceng.stocking_bus": "ME Stocking Input Bus",
"block.gregiceng.stocking_bus.desc.0": "Using items in the ME network to provide items to multi block structures",
"block.gregiceng.stocking_hatch": "ME Stocking Input Hatch",
"block.gregiceng.stocking_hatch.desc.0": "Using fluids in the ME network to provide fluids to multi block structures",
"block.gregiceng.uev_input_buffer": "§aUEV Input Buffer",
"block.gregiceng.uev_output_buffer": "§aUEV Output Buffer",
"block.gregiceng.uhv_input_buffer": "§4UHV Input Buffer",
Expand All @@ -33,8 +41,8 @@
"block.gregiceng.zpm_output_buffer": "§cZPM Output Buffer",
"config.gregiceng.option.enableMoreAbility": "Enable More Ability for Crafting IO Buffer/Slave",
"config.jade.plugin_gregiceng.crafting_io_buffer": "Crafting IO Buffer",
"gui.gregiceng.auto_pull_me.desc.disabled": "Automatic Return is disabled",
"gui.gregiceng.auto_pull_me.desc.enabled": "Automatic Return is on",
"gui.gregiceng.auto_pull_me.desc.disabled": "Automatic pull is disabled",
"gui.gregiceng.auto_pull_me.desc.enabled": "Automatic pull is on",
"gui.gregiceng.automatic_return.desc.disabled": "Automatic Return is disabled",
"gui.gregiceng.automatic_return.desc.enabled": "Automatic Return is on",
"gui.gregiceng.refund_all.desc": "Refund raw materials in full",
Expand Down
16 changes: 11 additions & 5 deletions src/generated/resources/assets/gregiceng/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"block.gregiceng.adv_stocking_bus": "ME进阶存储输入总线",
"block.gregiceng.adv_stocking_bus.desc.0": "使用ME网络中的物品向多方块结构提供物品",
"block.gregiceng.adv_stocking_bus.desc.1": "拥有自动拉取功能",
"block.gregiceng.adv_stocking_hatch": "ME进阶存储输入仓",
"block.gregiceng.adv_stocking_hatch.desc.0": "使用ME网络中的流体向多方块结构提供流体",
"block.gregiceng.adv_stocking_hatch.desc.1": "拥有自动拉取功能",
"block.gregiceng.crafting_io_buffer": "ME样板IO总成",
"block.gregiceng.crafting_io_buffer.desc.0": "需与ME网络连接,可容纳54个样板,支持流体与物品的处理样板",
"block.gregiceng.crafting_io_buffer.desc.1": "分别拥有9个物品和流体的不消耗品槽",
"block.gregiceng.crafting_io_buffer.desc.2": "允许产物直接回流至网络",
"block.gregiceng.crafting_io_buffer.desc.0": "需与ME网络连接,可容纳54个样板",
"block.gregiceng.crafting_io_buffer.desc.1": "拥有9个物品和流体催化剂槽",
"block.gregiceng.crafting_io_buffer.desc.2": "允许回流至网络",
"block.gregiceng.crafting_io_slave": "ME样板IO镜像",
"block.gregiceng.crafting_io_slave.desc.0": "无需与ME网络连接,ME样板IO总成的镜像端",
"block.gregiceng.crafting_io_slave.desc.1": "拥有被复制ME样板IO总成的所有配置,包括不消耗品和处理样板",
Expand All @@ -23,7 +27,9 @@
"block.gregiceng.opv_output_buffer": "§9§lOpV§r输出总成",
"block.gregiceng.output_buffer.desc": "为多方块结构输出物品和流体",
"block.gregiceng.stocking_bus": "ME存储输入总线",
"block.gregiceng.stocking_bus.desc.0": "使用ME网络中的物品向多方块结构提供物品",
"block.gregiceng.stocking_hatch": "ME存储输入仓",
"block.gregiceng.stocking_hatch.desc.0": "使用ME网络中的流体向多方块结构提供流体",
"block.gregiceng.uev_input_buffer": "§aUEV§r输入总成",
"block.gregiceng.uev_output_buffer": "§aUEV§r输出总成",
"block.gregiceng.uhv_input_buffer": "§4UHV§r输入总成",
Expand All @@ -38,8 +44,8 @@
"block.gregiceng.zpm_output_buffer": "§cZPM§r输出总成",
"config.gregiceng.option.enableMoreAbility": "为样板IO总成/镜像启用更多能力",
"config.jade.plugin_gregiceng.crafting_io_buffer": "样板IO总成",
"gui.gregiceng.auto_pull_me.desc.disabled": "自动回流已禁用",
"gui.gregiceng.auto_pull_me.desc.enabled": "自动回流已开启",
"gui.gregiceng.auto_pull_me.desc.disabled": "自动拉取已禁用",
"gui.gregiceng.auto_pull_me.desc.enabled": "自动拉取已开启",
"gui.gregiceng.automatic_return.desc.disabled": "自动回流已禁用",
"gui.gregiceng.automatic_return.desc.enabled": "自动回流已开启",
"gui.gregiceng.refund_all.desc": "退回所有材料",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@
import appeng.api.stacks.AEKey;
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.Set;

public interface IConfigurableAESlotList<K extends AEKey> {
IConfigurableAESlot<K> getAESlot(int index);
int getSlots();
boolean hasConfig(@Nullable K key);
void clearConfig();
default Set<K> getAEKeySet() {
Set<K> keys = new HashSet<>();
for (int i = 0; i < getSlots(); i++) {
var key = getAESlot(i).getConfig();
if (key != null) {
keys.add(key);
}
}
return keys;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,21 @@ public class GEMachines {
.rotationState(RotationState.ALL)
.abilities(PartAbility.IMPORT_ITEMS)
.overlayTieredHullRenderer("adv_stocking_bus")
.tooltips(Component.translatable("block.gregiceng.adv_stocking_bus.desc.0"))
.tooltips(
Component.translatable("block.gregiceng.adv_stocking_bus.desc.0"),
Component.translatable("block.gregiceng.adv_stocking_bus.desc.1")
)
.register();

public static final MachineDefinition ADV_STOCKING_HATCH = registrate().machine("adv_stocking_hatch", AdvStockingHatchPartMachine::new)
.tier(IV)
.rotationState(RotationState.ALL)
.abilities(PartAbility.IMPORT_FLUIDS)
.overlayTieredHullRenderer("adv_stocking_hatch")
.tooltips(Component.translatable("block.gregiceng.adv_stocking_hatch.desc.0"))
.tooltips(
Component.translatable("block.gregiceng.adv_stocking_hatch.desc.0"),
Component.translatable("block.gregiceng.adv_stocking_hatch.desc.1")
)
.register();

public static final MachineDefinition CRAFTING_IO_BUFFER = registrate().machine("crafting_io_buffer", CraftingIOBufferPartMachine::new)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.epimorphismmc.gregiceng.common.machine.multiblock.part.appeng;

import appeng.api.networking.IGridNodeListener;
import appeng.api.networking.IStackWatcher;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IStorageWatcherNode;
import appeng.api.stacks.AEItemKey;
import appeng.api.stacks.AEKey;
import appeng.me.ManagedGridNode;
import com.epimorphismmc.gregiceng.api.machine.feature.multiblock.IMEStockingBus;
import com.epimorphismmc.gregiceng.api.misc.ConfigurableAESlot;
Expand Down Expand Up @@ -179,6 +182,20 @@ protected class ExportOnlyAEItemList extends NotifiableRecipeHandlerTrait<Ingred
@Persisted
ItemTransferList inventory;

private IStackWatcher storageWatcher;
private final IStorageWatcherNode stackWatcherNode = new IStorageWatcherNode() {
@Override
public void updateWatcher(IStackWatcher newWatcher) {
storageWatcher = newWatcher;
configureWatchers();
}

@Override
public void onStackChange(AEKey what, long amount) {
notifyListeners();
}
};

public ExportOnlyAEItemList(MetaMachine holder, int slots) {
super(holder);
var transfers = new ExportOnlyAEItem[slots];
Expand All @@ -187,6 +204,15 @@ public ExportOnlyAEItemList(MetaMachine holder, int slots) {
transfers[i].setOnContentsChanged(this::onChanged);
}
this.inventory = new SerializableItemTransferList(transfers);

getMainNode().addService(IStorageWatcherNode.class, stackWatcherNode);
}

@Override
public void onChanged() {
super.onChanged();
notifyListeners();
configureWatchers();
}

@Override
Expand Down Expand Up @@ -266,6 +292,15 @@ public IO getHandlerIO() {
public ManagedFieldHolder getFieldHolder() {
return MANAGED_FIELD_HOLDER;
}

private void configureWatchers() {
if (storageWatcher != null) {
storageWatcher.reset();
for (AEItemKey aeItemKey : getAEKeySet()) {
storageWatcher.add(aeItemKey);
}
}
}
}

protected class ExportOnlyAEItem extends ConfigurableAESlot<AEItemKey> implements IItemTransfer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.epimorphismmc.gregiceng.common.machine.multiblock.part.appeng;

import appeng.api.networking.IGridNodeListener;
import appeng.api.networking.IStackWatcher;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IStorageWatcherNode;
import appeng.api.stacks.AEFluidKey;
import appeng.api.stacks.AEKey;
import appeng.me.ManagedGridNode;
import com.epimorphismmc.gregiceng.api.machine.feature.multiblock.IMEStockingHatch;
import com.epimorphismmc.gregiceng.api.misc.ConfigurableAESlot;
Expand Down Expand Up @@ -124,6 +127,20 @@ protected class ExportOnlyAEFluidList extends NotifiableRecipeHandlerTrait<Fluid
private final SerializableFluidTransferList tanks;
private FluidStorage[] fluidStorages;

private IStackWatcher storageWatcher;
private final IStorageWatcherNode stackWatcherNode = new IStorageWatcherNode() {
@Override
public void updateWatcher(IStackWatcher newWatcher) {
storageWatcher = newWatcher;
configureWatchers();
}

@Override
public void onStackChange(AEKey what, long amount) {
notifyListeners();
}
};

public ExportOnlyAEFluidList(MetaMachine machine, int slots) {
super(machine);
var storages = new ExportOnlyAEFluid[slots];
Expand All @@ -133,6 +150,15 @@ public ExportOnlyAEFluidList(MetaMachine machine, int slots) {
}
this.tanks = new SerializableFluidTransferList(storages);
this.fluidStorages = null;

getMainNode().addService(IStorageWatcherNode.class, stackWatcherNode);
}

@Override
public void onChanged() {
super.onChanged();
notifyListeners();
configureWatchers();
}

@Override
Expand Down Expand Up @@ -211,6 +237,15 @@ public ManagedFieldHolder getFieldHolder() {
return MANAGED_FIELD_HOLDER;
}

private void configureWatchers() {
if (storageWatcher != null) {
storageWatcher.reset();
for (AEFluidKey aeItemKey : getAEKeySet()) {
storageWatcher.add(aeItemKey);
}
}
}

private static class WrappedFluidStorage extends FluidStorage {

private final ExportOnlyAEFluid fluid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ public static void init(MOLangProvider provider) {
"ME Crafting IO Buffer",
"ME样板IO总成",
List.of(
""
"Must be connected to the ME network and can contain 54 patten",
"Having 9 items and fluid catalyst slots",
"Allow flow back to the network"
),
List.of(
"需与ME网络连接,可容纳54个样板,支持流体与物品的处理样板",
"分别拥有9个物品和流体的不消耗品槽",
"允许产物直接回流至网络"
"需与ME网络连接,可容纳54个样板",
"拥有9个物品和流体催化剂槽",
"允许回流至网络"
));

provider.addBlockWithTooltip(CRAFTING_IO_SLAVE::getBlock,
Expand All @@ -41,40 +43,44 @@ public static void init(MOLangProvider provider) {
"ME Stocking Input Bus",
"ME存储输入总线",
List.of(

"Using items in the ME network to provide items to multi block structures"
),
List.of(

"使用ME网络中的物品向多方块结构提供物品"
));

provider.addBlockWithTooltip(STOCKING_HATCH::getBlock,
"ME Stocking Input Hatch",
"ME存储输入仓",
List.of(

"Using fluids in the ME network to provide fluids to multi block structures"
),
List.of(

"使用ME网络中的流体向多方块结构提供流体"
));

provider.addBlockWithTooltip(ADV_STOCKING_BUS::getBlock,
"ME Advanced Stocking Input Bus",
"ME进阶存储输入总线",
List.of(

"Using items in the ME network to provide items to multi block structures",
"Has Automatic pull mode"
),
List.of(

"使用ME网络中的物品向多方块结构提供物品",
"拥有自动拉取功能"
));

provider.addBlockWithTooltip(ADV_STOCKING_HATCH::getBlock,
"ME Advanced Stocking Input Hatch",
"ME进阶存储输入仓",
List.of(

"Using fluids in the ME network to provide fluids to multi block structures",
"Has Automatic pull mode"
),
List.of(

"使用ME网络中的流体向多方块结构提供流体",
"拥有自动拉取功能"
));

provider.addTieredMachineName("input_buffer", "输入总成", MULTI_HATCH_TIERS);
Expand Down Expand Up @@ -113,11 +119,11 @@ public static void init(MOLangProvider provider) {
"自动回流已禁用");

provider.add("gui.gregiceng.auto_pull_me.desc.enabled",
"Automatic Return is on",
"自动回流已开启");
"Automatic pull is on",
"自动拉取已开启");
provider.add("gui.gregiceng.auto_pull_me.desc.disabled",
"Automatic Return is disabled",
"自动回流已禁用");
"Automatic pull is disabled",
"自动拉取已禁用");

provider.add("gui.gregiceng.rename.desc",
"Rename",
Expand Down