Processing tasks.
This commit is contained in:
@@ -100,7 +100,7 @@ public interface ICraftingManager {
|
||||
/**
|
||||
* Makes the network send a crafting monitor update to all players as soon as it can.
|
||||
*/
|
||||
// TODO: rework system to be subscribed-based, per task
|
||||
// TODO: rework system to be subscribed-based
|
||||
void markCraftingMonitorForUpdate();
|
||||
|
||||
/**
|
||||
@@ -108,7 +108,7 @@ public interface ICraftingManager {
|
||||
* <p>
|
||||
* WARNING: In most cases, you should just use {@link ICraftingManager#markCraftingMonitorForUpdate()}, if not, you can get high bandwidth usage.
|
||||
*/
|
||||
// TODO: rework system to be subscribed-based, per task
|
||||
// TODO: rework system to be subscribed-based
|
||||
void sendCraftingMonitorUpdate();
|
||||
|
||||
/**
|
||||
@@ -116,6 +116,6 @@ public interface ICraftingManager {
|
||||
*
|
||||
* @param player the player
|
||||
*/
|
||||
// TODO: rework system to be subscribed-based, per task
|
||||
// TODO: rework system to be subscribed-based
|
||||
void sendCraftingMonitorUpdate(EntityPlayerMP player);
|
||||
}
|
||||
|
||||
@@ -20,13 +20,15 @@ public interface ICraftingPatternContainer {
|
||||
int getSpeedUpgradeCount();
|
||||
|
||||
/**
|
||||
* @return the inventory that this container is connected to
|
||||
* @return the inventory that this container is connected to, or null if no inventory is present
|
||||
*/
|
||||
@Nullable
|
||||
IItemHandler getConnectedInventory();
|
||||
|
||||
/**
|
||||
* @return the tile that this container is connected to
|
||||
* @return the tile that this container is connected to, or null if no tile is present
|
||||
*/
|
||||
@Nullable
|
||||
TileEntity getConnectedTile();
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,14 @@ public interface ICraftingTask {
|
||||
*/
|
||||
ItemStack getRequested();
|
||||
|
||||
/**
|
||||
* Called when a stack is inserted into the system through {@link com.raoulvdberge.refinedstorage.api.network.INetwork#insertItemTracked(ItemStack, int)}.
|
||||
*
|
||||
* @param stack the stack
|
||||
* @return the size remaining, decremented by the crafting task when it was relevant to it
|
||||
*/
|
||||
int onTrackedItemInserted(ItemStack stack, int size);
|
||||
|
||||
/**
|
||||
* Writes this task to NBT.
|
||||
*
|
||||
|
||||
@@ -148,7 +148,13 @@ public class CraftingManager implements ICraftingManager {
|
||||
|
||||
@Override
|
||||
public void track(ItemStack stack, int size) {
|
||||
// TODO
|
||||
for (ICraftingTask task : tasks) {
|
||||
size = task.onTrackedItemInserted(stack, size);
|
||||
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,10 @@ package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -28,6 +31,7 @@ public class CraftingExtractor {
|
||||
return status;
|
||||
}
|
||||
|
||||
// TODO: send crafting monitor update when this changes
|
||||
public void updateStatus() {
|
||||
for (int i = 0; i < items.size(); ++i) {
|
||||
if (status.get(i) != CraftingExtractorItemStatus.EXTRACTED) {
|
||||
@@ -52,12 +56,13 @@ public class CraftingExtractor {
|
||||
return !items.isEmpty() && status.stream().allMatch(s -> s == CraftingExtractorItemStatus.EXTRACTED);
|
||||
}
|
||||
|
||||
// TODO: send crafting monitor update when this changes
|
||||
public void extractOne() {
|
||||
for (int i = 0; i < items.size(); ++i) {
|
||||
if (status.get(i) == CraftingExtractorItemStatus.AVAILABLE) {
|
||||
ItemStack extracted = network.extractItem(items.get(i), items.get(i).getCount(), false);
|
||||
if (extracted == null) {
|
||||
throw new IllegalStateException("Did not extract anything");
|
||||
throw new IllegalStateException("Did not extract anything while available");
|
||||
}
|
||||
|
||||
status.set(i, CraftingExtractorItemStatus.EXTRACTED);
|
||||
@@ -66,4 +71,31 @@ public class CraftingExtractor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: send crafting monitor update when this changes
|
||||
public void extractOneAndInsert(@Nullable IItemHandler dest) {
|
||||
for (int i = 0; i < items.size(); ++i) {
|
||||
if (status.get(i) == CraftingExtractorItemStatus.AVAILABLE) {
|
||||
ItemStack extracted = network.extractItem(items.get(i), items.get(i).getCount(), true);
|
||||
if (extracted == null) {
|
||||
throw new IllegalStateException("Extraction simulation failed while available");
|
||||
}
|
||||
|
||||
if (dest == null) {
|
||||
status.set(i, CraftingExtractorItemStatus.MACHINE_NONE);
|
||||
} else if (ItemHandlerHelper.insertItem(dest, extracted, false).isEmpty()) {
|
||||
extracted = network.extractItem(items.get(i), items.get(i).getCount(), false);
|
||||
if (extracted == null) {
|
||||
throw new IllegalStateException("Did not extract anything while available");
|
||||
}
|
||||
|
||||
status.set(i, CraftingExtractorItemStatus.EXTRACTED);
|
||||
} else {
|
||||
status.set(i, CraftingExtractorItemStatus.MACHINE_DOES_NOT_ACCEPT);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,7 @@ package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task;
|
||||
public enum CraftingExtractorItemStatus {
|
||||
AVAILABLE,
|
||||
MISSING,
|
||||
EXTRACTED
|
||||
EXTRACTED,
|
||||
MACHINE_NONE,
|
||||
MACHINE_DOES_NOT_ACCEPT
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.Craf
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.step.CraftingStep;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.step.CraftingStepCraft;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.step.CraftingStepProcess;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
@@ -136,16 +139,18 @@ public class CraftingTask implements ICraftingTask {
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
results.add(output);
|
||||
}
|
||||
|
||||
return new CraftingStepProcess(pattern, network, new ArrayList<>(itemsToExtract.getStacks()));
|
||||
} else {
|
||||
results.add(pattern.getOutput(took));
|
||||
|
||||
for (ItemStack byproduct : pattern.getByproducts(took)) {
|
||||
results.add(byproduct);
|
||||
}
|
||||
}
|
||||
|
||||
return new CraftingStepCraft(pattern, inserter, network, new ArrayList<>(itemsToExtract.getStacks()), took);
|
||||
}
|
||||
}
|
||||
|
||||
private int getQuantityPerCraft(ICraftingPattern pattern, ItemStack requested) {
|
||||
int qty = 0;
|
||||
@@ -201,6 +206,21 @@ public class CraftingTask implements ICraftingTask {
|
||||
return requested;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onTrackedItemInserted(ItemStack stack, int size) {
|
||||
for (CraftingStep step : steps) {
|
||||
if (step instanceof CraftingStepProcess) {
|
||||
size = ((CraftingStepProcess) step).onTrackedItemInserted(stack, size);
|
||||
|
||||
if (size == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||
return tag;
|
||||
@@ -281,6 +301,40 @@ public class CraftingTask implements ICraftingTask {
|
||||
elements.commit();
|
||||
}
|
||||
|
||||
if (steps.stream().anyMatch(s -> s instanceof CraftingStepProcess && !s.isCompleted())) {
|
||||
elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_processing", 16));
|
||||
|
||||
for (CraftingStep step : steps) {
|
||||
if (step instanceof CraftingStepProcess && !step.isCompleted()) {
|
||||
CraftingExtractor extractor = ((CraftingStepProcess) step).getExtractor();
|
||||
|
||||
for (int i = 0; i < extractor.getItems().size(); ++i) {
|
||||
ItemStack item = extractor.getItems().get(i);
|
||||
CraftingExtractorItemStatus status = extractor.getStatus().get(i);
|
||||
|
||||
ICraftingMonitorElement element = new CraftingMonitorElementItemRender(
|
||||
-1,
|
||||
item,
|
||||
item.getCount(),
|
||||
32
|
||||
);
|
||||
|
||||
if (status == CraftingExtractorItemStatus.MISSING) {
|
||||
element = new CraftingMonitorElementInfo(element, "gui.refinedstorage:crafting_monitor.waiting_for_items");
|
||||
} else if (status == CraftingExtractorItemStatus.MACHINE_DOES_NOT_ACCEPT) {
|
||||
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_does_not_accept");
|
||||
} else if (status == CraftingExtractorItemStatus.MACHINE_NONE) {
|
||||
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_none");
|
||||
}
|
||||
|
||||
elements.add(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
elements.commit();
|
||||
}
|
||||
|
||||
return elements.getElements();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task;
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.step;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task;
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.step;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.CraftingExtractor;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.CraftingInserter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.step;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IStackList;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.CraftingExtractor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CraftingStepProcess extends CraftingStep {
|
||||
private CraftingExtractor extractor;
|
||||
private IStackList<ItemStack> itemsToReceive = API.instance().createItemStackList();
|
||||
|
||||
public CraftingStepProcess(ICraftingPattern pattern, INetwork network, List<ItemStack> toExtract) {
|
||||
super(pattern);
|
||||
this.extractor = new CraftingExtractor(network, toExtract);
|
||||
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
this.itemsToReceive.add(output);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecute() {
|
||||
extractor.updateStatus();
|
||||
|
||||
return extractor.isAllAvailable();
|
||||
}
|
||||
|
||||
public int onTrackedItemInserted(ItemStack stack, int size) {
|
||||
if (!extractor.isAllExtracted()) {
|
||||
return size;
|
||||
}
|
||||
|
||||
ItemStack inList = itemsToReceive.get(stack);
|
||||
if (inList == null) {
|
||||
return size;
|
||||
}
|
||||
|
||||
int toExtract = Math.min(size, inList.getCount());
|
||||
|
||||
itemsToReceive.remove(stack, toExtract);
|
||||
|
||||
return size - toExtract;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
if (!extractor.isAllExtracted()) {
|
||||
extractor.extractOneAndInsert(pattern.getContainer().getConnectedInventory());
|
||||
}
|
||||
|
||||
return itemsToReceive.isEmpty();
|
||||
}
|
||||
|
||||
public CraftingExtractor getExtractor() {
|
||||
return extractor;
|
||||
}
|
||||
}
|
||||
@@ -64,8 +64,7 @@ public class NetworkNodeCrafter extends NetworkNode implements ICraftingPatternC
|
||||
|
||||
private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, new ItemHandlerListenerNetworkNode(this), ItemUpgrade.TYPE_SPEED);
|
||||
|
||||
// Used to prevent infinite recursion on getRootContainer() when
|
||||
// there's eg. two crafters facing each other.
|
||||
// Used to prevent infinite recursion on getRootContainer() when there's eg. two crafters facing each other.
|
||||
private boolean visited = false;
|
||||
|
||||
@Nullable
|
||||
@@ -173,20 +172,24 @@ public class NetworkNodeCrafter extends NetworkNode implements ICraftingPatternC
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IItemHandler getConnectedInventory() {
|
||||
ICraftingPatternContainer proxy = getRootContainer();
|
||||
if (proxy == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return WorldUtils.getItemHandler(proxy.getFacingTile(), proxy.getDirection().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TileEntity getConnectedTile() {
|
||||
ICraftingPatternContainer proxy = getRootContainer();
|
||||
if (proxy == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return proxy.getFacingTile();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
|
||||
public class BlockWirelessTransmitter extends BlockNode {
|
||||
// From BlockTorch
|
||||
// TODO: make consistent with shape
|
||||
private static final AxisAlignedBB WIRELESS_TRANSMITTER_AABB = new AxisAlignedBB(0.4000000059604645D, 0.0D, 0.4000000059604645D, 0.6000000238418579D, 0.6000000238418579D, 0.6000000238418579D);
|
||||
|
||||
public BlockWirelessTransmitter() {
|
||||
|
||||
@@ -25,7 +25,6 @@ gui.refinedstorage:crafting_monitor.items_crafting=Teil herstellen
|
||||
gui.refinedstorage:crafting_monitor.items_processing=Teil verarbeiten
|
||||
gui.refinedstorage:crafting_monitor.items_inserting=Teil einfügen
|
||||
gui.refinedstorage:crafting_monitor.items_missing=Teil fehlt
|
||||
gui.refinedstorage:crafting_monitor.machine_in_use=Maschine in Gebrauch
|
||||
gui.refinedstorage:crafting_monitor.machine_none=keine Maschine gefunden
|
||||
gui.refinedstorage:crafting_monitor.waiting_for_items=Warte auf Teile
|
||||
gui.refinedstorage:wireless_transmitter=Funk-Sender
|
||||
|
||||
@@ -30,7 +30,7 @@ gui.refinedstorage:crafting_monitor.items_crafting=Items crafting
|
||||
gui.refinedstorage:crafting_monitor.items_processing=Items processing
|
||||
gui.refinedstorage:crafting_monitor.items_inserting=Items inserting
|
||||
gui.refinedstorage:crafting_monitor.items_missing=Items missing
|
||||
gui.refinedstorage:crafting_monitor.machine_in_use=Machine is in use
|
||||
gui.refinedstorage:crafting_monitor.machine_does_not_accept=Machine doesn't accept item
|
||||
gui.refinedstorage:crafting_monitor.machine_none=No machine found
|
||||
gui.refinedstorage:crafting_monitor.waiting_for_items=Waiting for items
|
||||
gui.refinedstorage:crafting_monitor.network_full=Network is full
|
||||
|
||||
@@ -30,7 +30,6 @@ gui.refinedstorage:crafting_monitor.items_crafting=Fabrica Objetos
|
||||
gui.refinedstorage:crafting_monitor.items_processing=Procesamiento de objetos
|
||||
gui.refinedstorage:crafting_monitor.items_inserting=Inserta Objetos
|
||||
gui.refinedstorage:crafting_monitor.items_missing=Faltan objetos
|
||||
gui.refinedstorage:crafting_monitor.machine_in_use=Maquina en uso
|
||||
gui.refinedstorage:crafting_monitor.machine_none=Maquina no Hallada
|
||||
gui.refinedstorage:crafting_monitor.waiting_for_items=Esperando Objetos
|
||||
gui.refinedstorage:wireless_transmitter=Emisor inalámbrico
|
||||
|
||||
@@ -29,7 +29,6 @@ gui.refinedstorage:crafting_monitor.items_crafting=Items en craft
|
||||
gui.refinedstorage:crafting_monitor.items_processing=Items en traitement
|
||||
gui.refinedstorage:crafting_monitor.items_inserting=Insertion d'items
|
||||
gui.refinedstorage:crafting_monitor.items_missing=Items manquants
|
||||
gui.refinedstorage:crafting_monitor.machine_in_use=Machine en cours d'utilisation
|
||||
gui.refinedstorage:crafting_monitor.machine_none=Pas de machine disponible
|
||||
gui.refinedstorage:crafting_monitor.waiting_for_items=En attente d'items
|
||||
gui.refinedstorage:wireless_transmitter=Emetteur sans-fil
|
||||
|
||||
@@ -28,7 +28,6 @@ gui.refinedstorage:crafting_monitor.items_crafting=제작할 아이템
|
||||
gui.refinedstorage:crafting_monitor.items_processing=가공할 아이템
|
||||
gui.refinedstorage:crafting_monitor.items_inserting=삽입할 아이템
|
||||
gui.refinedstorage:crafting_monitor.items_missing=부족한 아이템
|
||||
gui.refinedstorage:crafting_monitor.machine_in_use=기계가 이미 사용 중임
|
||||
gui.refinedstorage:crafting_monitor.machine_none=기계를 찾을 수 없음
|
||||
gui.refinedstorage:crafting_monitor.waiting_for_items=아이템을 기다리는 중
|
||||
gui.refinedstorage:wireless_transmitter=무선 송신기
|
||||
|
||||
@@ -22,7 +22,6 @@ gui.refinedstorage:crafting_monitor=Crafting Monitor
|
||||
gui.refinedstorage:crafting_monitor.missing_items=Ontbrekende items
|
||||
gui.refinedstorage:crafting_monitor.items_crafting=Items aan het craften
|
||||
gui.refinedstorage:crafting_monitor.items_processing=Items aan het verwerken
|
||||
gui.refinedstorage:crafting_monitor.machine_in_use=Wachten op machine die gebruikt wordt door een andere crafting taak
|
||||
gui.refinedstorage:crafting_monitor.machine_none=Geen machine gevonden
|
||||
gui.refinedstorage:wireless_transmitter=Draadloze Zender
|
||||
gui.refinedstorage:wireless_transmitter.distance=%d blokken
|
||||
|
||||
@@ -29,7 +29,6 @@ gui.refinedstorage:crafting_monitor.items_crafting=Fabricando itens
|
||||
gui.refinedstorage:crafting_monitor.items_processing=Processando itens
|
||||
gui.refinedstorage:crafting_monitor.items_inserting=Inserindo itens
|
||||
gui.refinedstorage:crafting_monitor.items_missing=Ausência de itens
|
||||
gui.refinedstorage:crafting_monitor.machine_in_use=A máquina está em uso
|
||||
gui.refinedstorage:crafting_monitor.machine_none=Nenhuma máquina encontrada
|
||||
gui.refinedstorage:crafting_monitor.waiting_for_items=Esperando itens
|
||||
gui.refinedstorage:wireless_transmitter=Transmissor Wireless
|
||||
|
||||
@@ -30,7 +30,6 @@ gui.refinedstorage:crafting_monitor.items_crafting=Предметы с возм
|
||||
gui.refinedstorage:crafting_monitor.items_processing=Предметы с возможностью обработки
|
||||
gui.refinedstorage:crafting_monitor.items_inserting=Вставка предметов
|
||||
gui.refinedstorage:crafting_monitor.items_missing=Отсутствуют предметы
|
||||
gui.refinedstorage:crafting_monitor.machine_in_use=Машина используется
|
||||
gui.refinedstorage:crafting_monitor.machine_none=Машина не найдена
|
||||
gui.refinedstorage:crafting_monitor.waiting_for_items=Ожидание предметов
|
||||
gui.refinedstorage:wireless_transmitter=Передатчик
|
||||
|
||||
@@ -30,7 +30,6 @@ gui.refinedstorage:crafting_monitor.items_crafting=正在合成
|
||||
gui.refinedstorage:crafting_monitor.items_processing=正在处理
|
||||
gui.refinedstorage:crafting_monitor.items_inserting=物品正在输入
|
||||
gui.refinedstorage:crafting_monitor.items_missing=物品丢失中
|
||||
gui.refinedstorage:crafting_monitor.machine_in_use=该机器正在处理其他工作,请稍等
|
||||
gui.refinedstorage:crafting_monitor.machine_none=找不到机器
|
||||
gui.refinedstorage:crafting_monitor.waiting_for_items=正在等待物品
|
||||
gui.refinedstorage:wireless_transmitter=无线访问点
|
||||
|
||||
Reference in New Issue
Block a user