improves performance of ICraftingTask and ICraftingStep
and an info ICraftingMonitorElement, using the IElementDrawers#getOverlayDrawer which now takes a colour as argument
This commit is contained in:
@@ -28,11 +28,19 @@ public interface ICraftingStep {
|
||||
* Check if the processing can start.
|
||||
*
|
||||
* @param items a list to compare the needed {@link ItemStack} inputs against
|
||||
* @param fluids a list to compare the needed {@link net.minecraftforge.fluids.FluidStack} inputs against (eg. a bucket, machine insert)
|
||||
* @param fluids a list to compare the needed {@link FluidStack} inputs against (eg. a bucket, machine insert)
|
||||
* @return true if processing can start
|
||||
*/
|
||||
boolean canStartProcessing(IItemStackList items, IFluidStackList fluids);
|
||||
|
||||
/**
|
||||
* Check if the processing can start.
|
||||
* Assuming you have all needed {@link ItemStack}s and {@link FluidStack}s
|
||||
*
|
||||
* @return true if processing can start
|
||||
*/
|
||||
boolean canStartProcessing();
|
||||
|
||||
/**
|
||||
* When called, this step will be marked as started processing.
|
||||
*/
|
||||
|
||||
@@ -29,9 +29,9 @@ public interface IElementDrawers {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a red overlay drawer
|
||||
* @return an overlay drawer, colour will be the element
|
||||
*/
|
||||
default IElementDrawer<?> getRedOverlayDrawer() {
|
||||
default IElementDrawer<Integer> getOverlayDrawer() {
|
||||
return getNullDrawer();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public class CraftingMonitorElementError implements ICraftingMonitorElement {
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y, IElementDrawers drawers) {
|
||||
drawers.getRedOverlayDrawer().draw(x, y, null);
|
||||
drawers.getOverlayDrawer().draw(x, y, 0xFFF2DEDE);
|
||||
|
||||
base.draw(x, y, drawers);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import com.raoulvdberge.refinedstorage.api.render.IElementDrawers;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
|
||||
public class CraftingMonitorElementInfo implements ICraftingMonitorElement {
|
||||
public static final String ID = "info";
|
||||
|
||||
private ICraftingMonitorElement base;
|
||||
private String tooltip;
|
||||
|
||||
public CraftingMonitorElementInfo(ICraftingMonitorElement base, String tooltip) {
|
||||
this.base = base;
|
||||
this.tooltip = tooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y, IElementDrawers drawers) {
|
||||
drawers.getOverlayDrawer().draw(x, y, 0xFFD9EDF7);
|
||||
|
||||
base.draw(x, y, drawers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrawSelection() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTaskId() {
|
||||
return base.getTaskId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf) {
|
||||
ByteBufUtils.writeUTF8String(buf, base.getId());
|
||||
ByteBufUtils.writeUTF8String(buf, tooltip);
|
||||
|
||||
base.write(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(ICraftingMonitorElement element) {
|
||||
return element.getId().equals(getId()) && elementHashCode() == element.elementHashCode() && base.merge(((CraftingMonitorElementInfo)element).base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int elementHashCode() {
|
||||
return base.elementHashCode() ^ tooltip.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class CraftingPreviewElementFluidStack implements ICraftingPreviewElement
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, IElementDrawers drawers) {
|
||||
if (missing) {
|
||||
drawers.getRedOverlayDrawer().draw(x, y, null);
|
||||
drawers.getOverlayDrawer().draw(x, y, 0xFFF2DEDE);
|
||||
}
|
||||
x += 5;
|
||||
y += 7;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class CraftingPreviewElementItemStack implements ICraftingPreviewElement<
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, IElementDrawers drawers) {
|
||||
if (missing) {
|
||||
drawers.getRedOverlayDrawer().draw(x, y, null);
|
||||
drawers.getOverlayDrawer().draw(x, y, 0xFFF2DEDE);
|
||||
}
|
||||
x += 5;
|
||||
y += 7;
|
||||
|
||||
@@ -79,6 +79,11 @@ public abstract class CraftingStep implements ICraftingStep {
|
||||
public List<ItemStack> getToInsert() {
|
||||
return pattern.getInputs().stream().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
@Override
|
||||
public boolean canStartProcessing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setStartedProcessing() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class CraftingStepProcess extends CraftingStep {
|
||||
ItemStack actualStack = items.get(stack, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT | (pattern.isOredict() ? IComparer.COMPARE_OREDICT : 0));
|
||||
|
||||
boolean canInsert = ItemHandlerHelper.insertItem(inventory, ItemHandlerHelper.copyStackWithSize(actualStack, stack.stackSize), true) == null;
|
||||
if (actualStack == null || actualStack.stackSize == 0 || !items.trackedRemove(actualStack, stack.stackSize, true) && canInsert) {
|
||||
if (actualStack == null || actualStack.stackSize == 0 || !items.trackedRemove(actualStack, stack.stackSize, true) || !canInsert) {
|
||||
items.undo();
|
||||
return false;
|
||||
}
|
||||
@@ -43,6 +43,17 @@ public class CraftingStepProcess extends CraftingStep {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canStartProcessing() {
|
||||
IItemHandler inventory = getPattern().getContainer().getFacingInventory();
|
||||
for (ItemStack stack : getToInsert()) {
|
||||
if (ItemHandlerHelper.insertItem(inventory, stack, true) != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Deque<ItemStack> toInsertItems, Deque<FluidStack> toInsertFluids) {
|
||||
// @TODO: fluid handling
|
||||
|
||||
@@ -13,10 +13,7 @@ import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IFluidStackList;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IItemStackList;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementError;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementFluidRender;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.*;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -262,7 +259,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
}
|
||||
|
||||
if (timesUsed++ <= container.getSpeedUpdateCount()) {
|
||||
if (!step.hasStartedProcessing() && step.canStartProcessing(network.getItemStorageCache().getList(), tookFluids) && canProcess(step)) {
|
||||
if (!step.hasStartedProcessing() && step.canStartProcessing(network.getItemStorageCache().getList(), tookFluids)) {
|
||||
step.setStartedProcessing();
|
||||
step.execute(toInsertItems, toInsertFluids);
|
||||
usedContainers.put(container, timesUsed);
|
||||
@@ -289,43 +286,6 @@ public class CraftingTask implements ICraftingTask {
|
||||
return isFinished();
|
||||
}
|
||||
|
||||
private boolean canProcess(ICraftingStep processable) {
|
||||
if (processable.getPattern().isProcessing()) {
|
||||
for (ICraftingTask otherTask : network.getCraftingTasks()) {
|
||||
for (ICraftingStep otherProcessable : otherTask.getSteps()) {
|
||||
if (otherProcessable.getPattern().isProcessing() && otherProcessable != processable && !otherProcessable.hasReceivedOutputs() && otherProcessable.hasStartedProcessing() && otherProcessable.getPattern().getContainer().getFacingTile() != null) {
|
||||
if (processable.getPattern().getContainer().getFacingTile().getPos().equals(otherProcessable.getPattern().getContainer().getFacingTile().getPos())) {
|
||||
if (!arePatternsEqual(processable.getPattern(), otherProcessable.getPattern())) {
|
||||
return false;
|
||||
} else {
|
||||
for (ItemStack toInsert : processable.getToInsert()) {
|
||||
if (ItemHandlerHelper.insertItem(processable.getPattern().getContainer().getFacingInventory(), toInsert, true) != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean arePatternsEqual(ICraftingPattern left, ICraftingPattern right) {
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
ItemStack leftStack = left.getInputs().get(i);
|
||||
ItemStack rightStack = right.getInputs().get(i);
|
||||
|
||||
if (!API.instance().getComparer().isEqual(leftStack, rightStack)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getQuantity() {
|
||||
return quantity;
|
||||
@@ -402,14 +362,20 @@ public class CraftingTask implements ICraftingTask {
|
||||
if (steps.stream().filter(s -> !s.getPattern().isProcessing()).count() > 0) {
|
||||
elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_crafting", 16));
|
||||
|
||||
for (ICraftingStep processable : steps.stream().filter(s -> !s.getPattern().isProcessing()).collect(Collectors.toList())) {
|
||||
for (int i = 0; i < processable.getPattern().getOutputs().size(); ++i) {
|
||||
elements.add(new CraftingMonitorElementItemRender(
|
||||
for (ICraftingStep step : steps.stream().filter(s -> !s.getPattern().isProcessing()).collect(Collectors.toList())) {
|
||||
for (int i = 0; i < step.getPattern().getOutputs().size(); ++i) {
|
||||
ICraftingMonitorElement element = new CraftingMonitorElementItemRender(
|
||||
-1,
|
||||
processable.getPattern().getOutputs().get(i),
|
||||
processable.getPattern().getOutputs().get(i).stackSize,
|
||||
step.getPattern().getOutputs().get(i),
|
||||
step.getPattern().getOutputs().get(i).stackSize,
|
||||
32
|
||||
));
|
||||
);
|
||||
|
||||
if (!step.hasStartedProcessing() && !step.canStartProcessing(network.getItemStorageCache().getList(), tookFluids)) {
|
||||
element = new CraftingMonitorElementInfo(element, "gui.refinedstorage:crafting_monitor.waiting_for_items");
|
||||
}
|
||||
|
||||
elements.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,18 +385,18 @@ public class CraftingTask implements ICraftingTask {
|
||||
if (steps.stream().filter(s -> s.getPattern().isProcessing()).count() > 0) {
|
||||
elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_processing", 16));
|
||||
|
||||
for (ICraftingStep processable : steps.stream().filter(s -> s.getPattern().isProcessing()).collect(Collectors.toList())) {
|
||||
for (int i = 0; i < processable.getPattern().getOutputs().size(); ++i) {
|
||||
for (ICraftingStep step : steps.stream().filter(s -> s.getPattern().isProcessing()).collect(Collectors.toList())) {
|
||||
for (int i = 0; i < step.getPattern().getOutputs().size(); ++i) {
|
||||
ICraftingMonitorElement element = new CraftingMonitorElementItemRender(
|
||||
-1,
|
||||
processable.getPattern().getOutputs().get(i),
|
||||
processable.getPattern().getOutputs().get(i).stackSize,
|
||||
step.getPattern().getOutputs().get(i),
|
||||
step.getPattern().getOutputs().get(i).stackSize,
|
||||
32
|
||||
);
|
||||
|
||||
if (processable.getPattern().getContainer().getFacingTile() == null) {
|
||||
if (step.getPattern().getContainer().getFacingTile() == null) {
|
||||
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_none");
|
||||
} else if (!canProcess(processable)) {
|
||||
} else if (!step.hasStartedProcessing() && !step.canStartProcessing()) {
|
||||
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_in_use");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,16 +18,14 @@ import java.util.List;
|
||||
|
||||
public class GuiCraftingMonitor extends GuiBase {
|
||||
public class CraftingMonitorElementDrawers extends ElementDrawers {
|
||||
private IElementDrawer redOverlayDrawer = (x, y, element) -> {
|
||||
private IElementDrawer<Integer> overlayDrawer = (x, y, colour) -> {
|
||||
GlStateManager.color(1, 1, 1);
|
||||
bindTexture("gui/crafting_preview.png"); // Don't even care
|
||||
drawTexture(x, y, 0, 238, ITEM_WIDTH, ITEM_HEIGHT - 1);
|
||||
bindTexture("gui/crafting_monitor.png");
|
||||
drawRect(x, y, x + ITEM_WIDTH, y + ITEM_HEIGHT - 1, colour);
|
||||
};
|
||||
|
||||
@Override
|
||||
public IElementDrawer getRedOverlayDrawer() {
|
||||
return redOverlayDrawer;
|
||||
public IElementDrawer<Integer> getOverlayDrawer() {
|
||||
return overlayDrawer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,15 +25,14 @@ import java.util.List;
|
||||
|
||||
public class GuiCraftingPreview extends GuiBase {
|
||||
public class CraftingPreviewElementDrawers extends ElementDrawers {
|
||||
private IElementDrawer redOverlayDrawer = (x, y, element) -> {
|
||||
private IElementDrawer<Integer> overlayDrawer = (x, y, colour) -> {
|
||||
GlStateManager.color(1, 1, 1);
|
||||
bindTexture("gui/crafting_preview.png");
|
||||
drawTexture(x, y, 189, 0, 67, 29);
|
||||
drawRect(x, y, x + 67, y + 29, colour);
|
||||
};
|
||||
|
||||
@Override
|
||||
public IElementDrawer getRedOverlayDrawer() {
|
||||
return redOverlayDrawer;
|
||||
public IElementDrawer<Integer> getOverlayDrawer() {
|
||||
return overlayDrawer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,7 @@ import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementError;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementFluidRender;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.*;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactory;
|
||||
@@ -65,6 +62,12 @@ public class ProxyCommon {
|
||||
|
||||
return new CraftingMonitorElementError(API.instance().getCraftingMonitorElementRegistry().getFactory(id).apply(buf), tooltip);
|
||||
});
|
||||
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementInfo.ID, buf -> {
|
||||
String id = ByteBufUtils.readUTF8String(buf);
|
||||
String tooltip = ByteBufUtils.readUTF8String(buf);
|
||||
|
||||
return new CraftingMonitorElementInfo(API.instance().getCraftingMonitorElementRegistry().getFactory(id).apply(buf), tooltip);
|
||||
});
|
||||
|
||||
API.instance().getCraftingPreviewElementRegistry().add(CraftingPreviewElementItemStack.ID, CraftingPreviewElementItemStack::fromByteBuf);
|
||||
API.instance().getCraftingPreviewElementRegistry().add(CraftingPreviewElementFluidStack.ID, CraftingPreviewElementFluidStack::fromByteBuf);
|
||||
|
||||
@@ -25,6 +25,7 @@ gui.refinedstorage:crafting_monitor.items_processing=Items processing
|
||||
gui.refinedstorage:crafting_monitor.items_inserting=Items inserting
|
||||
gui.refinedstorage:crafting_monitor.machine_in_use=Machine is in use
|
||||
gui.refinedstorage:crafting_monitor.machine_none=No machine found
|
||||
gui.refinedstorage:crafting_monitor.waiting_for_items=Waiting for items
|
||||
gui.refinedstorage:wireless_transmitter=Wireless Transmitter
|
||||
gui.refinedstorage:wireless_transmitter.distance=%d blocks
|
||||
gui.refinedstorage:crafter=Crafter
|
||||
|
||||
Reference in New Issue
Block a user