ICraftingPreviewElement uses IElementDrawers now
and some fixes for autocrafting ofc
This commit is contained in:
@@ -3,6 +3,7 @@ package refinedstorage.api.autocrafting.craftingmonitor;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.api.render.IElementDrawers;
|
||||
|
||||
/**
|
||||
* Represents a crafting monitor element.
|
||||
@@ -14,7 +15,7 @@ public interface ICraftingMonitorElement<T> {
|
||||
* @param drawers the drawers that this element can use
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
void draw(int x, int y, ICraftingMonitorElementDrawers drawers);
|
||||
void draw(int x, int y, IElementDrawers drawers);
|
||||
|
||||
/**
|
||||
* @return whether the crafting monitor can draw a grey background behind the element when selected
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package refinedstorage.api.autocrafting.craftingmonitor;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
|
||||
public interface ICraftingMonitorElementDrawers {
|
||||
IElementDrawer<ItemStack> getItemDrawer();
|
||||
|
||||
IElementDrawer<FluidStack> getFluidDrawer();
|
||||
|
||||
IElementDrawer<String> getStringDrawer();
|
||||
|
||||
IElementDrawer<?> getRedOverlayDrawer();
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.api.render.IElementDrawers;
|
||||
|
||||
public interface ICraftingPreviewElement<T> {
|
||||
/**
|
||||
@@ -16,12 +17,10 @@ public interface ICraftingPreviewElement<T> {
|
||||
/**
|
||||
* @param x position on the x axis to render
|
||||
* @param y position on the y axis to render
|
||||
* @param itemDrawer a drawer for {@link ItemStack}s
|
||||
* @param fluidDrawer a drawer for {@link FluidStack}s
|
||||
* @param stringDrawer a drawer for {@link String}s
|
||||
* @param drawers the drawers this element can use
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer);
|
||||
void draw(int x, int y, IElementDrawers drawers);
|
||||
|
||||
/**
|
||||
* @return available amount of the {@link #getElement()}
|
||||
|
||||
@@ -5,8 +5,9 @@ import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
/**
|
||||
* This {@link FunctionalInterface} is used to define a draw/render function
|
||||
* This function use x and y coords and the element to be draw
|
||||
* Used in {@link ICraftingPreviewElement#draw(int, int, IElementDrawer, IElementDrawer, IElementDrawer)} and
|
||||
* {@link refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement#draw(int, int, IElementDrawer, IElementDrawer, IElementDrawer)}
|
||||
* Usually packaged in a {@link IElementDrawers}
|
||||
* Used in {@link ICraftingPreviewElement#draw(int, int, IElementDrawers)} and
|
||||
* {@link refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement#draw(int, int, IElementDrawers)}
|
||||
*
|
||||
* @param <T> The element to draw, usually {@link String}, {@link net.minecraft.item.ItemStack} or {@link net.minecraftforge.fluids.FluidStack}
|
||||
*/
|
||||
|
||||
33
src/main/java/refinedstorage/api/render/IElementDrawers.java
Normal file
33
src/main/java/refinedstorage/api/render/IElementDrawers.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package refinedstorage.api.render;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
|
||||
public interface IElementDrawers {
|
||||
default IElementDrawer<ItemStack> getItemDrawer() {
|
||||
return getNullDrawer();
|
||||
}
|
||||
|
||||
default IElementDrawer<FluidStack> getFluidDrawer() {
|
||||
return getNullDrawer();
|
||||
}
|
||||
|
||||
default IElementDrawer<String> getStringDrawer() {
|
||||
return getNullDrawer();
|
||||
}
|
||||
|
||||
default IElementDrawer<?> getRedOverlayDrawer() {
|
||||
return getNullDrawer();
|
||||
}
|
||||
|
||||
/**
|
||||
* DO NOT OVERRIDE
|
||||
*
|
||||
* @param <T> any type of drawer
|
||||
* @return A drawer that does nothing
|
||||
*/
|
||||
default <T> IElementDrawer<T> getNullDrawer() {
|
||||
return (x, y, element) -> {};
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,11 @@ public interface IItemStackList {
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Removes all stacks with size zero
|
||||
*/
|
||||
void clean();
|
||||
|
||||
/**
|
||||
* @return true if the list is empty, false otherwise
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,7 @@ package refinedstorage.apiimpl.autocrafting.craftingmonitor;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementDrawers;
|
||||
import refinedstorage.api.render.IElementDrawers;
|
||||
|
||||
public class CraftingMonitorElementError implements ICraftingMonitorElement {
|
||||
public static final String ID = "error";
|
||||
@@ -17,7 +17,7 @@ public class CraftingMonitorElementError implements ICraftingMonitorElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y, ICraftingMonitorElementDrawers drawers) {
|
||||
public void draw(int x, int y, IElementDrawers drawers) {
|
||||
drawers.getRedOverlayDrawer().draw(x, y, null);
|
||||
|
||||
base.draw(x, y, drawers);
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.RSUtils;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementDrawers;
|
||||
import refinedstorage.api.render.IElementDrawers;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
|
||||
public class CraftingMonitorElementFluidRender implements ICraftingMonitorElement<FluidStack> {
|
||||
@@ -25,7 +25,7 @@ public class CraftingMonitorElementFluidRender implements ICraftingMonitorElemen
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, ICraftingMonitorElementDrawers drawers) {
|
||||
public void draw(int x, int y, IElementDrawers drawers) {
|
||||
drawers.getFluidDrawer().draw(x + 2 + offset, y + 1, stack);
|
||||
|
||||
float scale = 0.5f;
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementDrawers;
|
||||
import refinedstorage.api.render.IElementDrawers;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
|
||||
public class CraftingMonitorElementItemRender implements ICraftingMonitorElement<ItemStack> {
|
||||
@@ -27,7 +27,7 @@ public class CraftingMonitorElementItemRender implements ICraftingMonitorElement
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, ICraftingMonitorElementDrawers drawers) {
|
||||
public void draw(int x, int y, IElementDrawers drawers) {
|
||||
drawers.getItemDrawer().draw(x + 2 + offset, y + 1, stack);
|
||||
|
||||
float scale = 0.5f;
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementDrawers;
|
||||
import refinedstorage.api.render.IElementDrawers;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
|
||||
public class CraftingMonitorElementText implements ICraftingMonitorElement<String> {
|
||||
@@ -31,7 +31,7 @@ public class CraftingMonitorElementText implements ICraftingMonitorElement<Strin
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, ICraftingMonitorElementDrawers drawers) {
|
||||
public void draw(int x, int y, IElementDrawers drawers) {
|
||||
float scale = 0.5f;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.api.render.IElementDrawers;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
|
||||
public class CraftingPreviewElementFluidStack implements ICraftingPreviewElement<FluidStack> {
|
||||
@@ -61,16 +62,21 @@ public class CraftingPreviewElementFluidStack implements ICraftingPreviewElement
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer) {
|
||||
fluidDrawer.draw(x, y, getElement());
|
||||
public void draw(int x, int y, IElementDrawers drawers) {
|
||||
if (missing) {
|
||||
drawers.getRedOverlayDrawer().draw(x, y, null);
|
||||
}
|
||||
x += 5;
|
||||
y += 7;
|
||||
drawers.getFluidDrawer().draw(x, y, getElement());
|
||||
|
||||
float scale = 0.5f;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y + 3, scale), GuiBase.t("gui.refinedstorage:crafting_preview.available", ""));
|
||||
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y + 9, scale), getAvailable() + " mB");
|
||||
drawers.getStringDrawer().draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y + 3, scale), GuiBase.t("gui.refinedstorage:crafting_preview.available", ""));
|
||||
drawers.getStringDrawer().draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y + 9, scale), getAvailable() + " mB");
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.api.render.IElementDrawers;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
|
||||
public class CraftingPreviewElementItemStack implements ICraftingPreviewElement<ItemStack> {
|
||||
@@ -64,8 +65,13 @@ public class CraftingPreviewElementItemStack implements ICraftingPreviewElement<
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer) {
|
||||
itemDrawer.draw(x, y, getElement());
|
||||
public void draw(int x, int y, IElementDrawers drawers) {
|
||||
if (missing) {
|
||||
drawers.getRedOverlayDrawer().draw(x, y, null);
|
||||
}
|
||||
x += 5;
|
||||
y += 7;
|
||||
drawers.getItemDrawer().draw(x, y, getElement());
|
||||
|
||||
float scale = 0.5f;
|
||||
y += 2;
|
||||
@@ -75,13 +81,13 @@ public class CraftingPreviewElementItemStack implements ICraftingPreviewElement<
|
||||
|
||||
if (getToCraft() > 0) {
|
||||
String format = hasMissing() ? "gui.refinedstorage:crafting_preview.missing" : "gui.refinedstorage:crafting_preview.to_craft";
|
||||
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y, scale), GuiBase.t(format, getToCraft()));
|
||||
drawers.getStringDrawer().draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y, scale), GuiBase.t(format, getToCraft()));
|
||||
|
||||
y += 7;
|
||||
}
|
||||
|
||||
if (getAvailable() > 0) {
|
||||
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y, scale), GuiBase.t("gui.refinedstorage:crafting_preview.available", getAvailable()));
|
||||
drawers.getStringDrawer().draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y, scale), GuiBase.t("gui.refinedstorage:crafting_preview.available", getAvailable()));
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
@@ -39,11 +39,12 @@ public class CraftingTaskFactory implements ICraftingTaskFactory {
|
||||
}
|
||||
|
||||
IItemStackList toTake = RSUtils.readItemStackList(tag.getTagList(CraftingTask.NBT_TO_TAKE, Constants.NBT.TAG_COMPOUND));
|
||||
IItemStackList internalToTake = RSUtils.readItemStackList(tag.getTagList(CraftingTask.NBT_INTERNAL_TO_TAKE, Constants.NBT.TAG_COMPOUND));
|
||||
IFluidStackList toTakeFluids = RSUtils.readFluidStackList(tag.getTagList(CraftingTask.NBT_TO_TAKE_FLUIDS, Constants.NBT.TAG_COMPOUND));
|
||||
|
||||
NBTTagList toInsertList = tag.getTagList(CraftingTask.NBT_TO_INSERT, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
List<ItemStack> toInsert = new ArrayList<>();
|
||||
ArrayDeque<ItemStack> toInsert = new ArrayDeque<>();
|
||||
|
||||
for (int i = 0; i < toInsertList.tagCount(); ++i) {
|
||||
ItemStack insertStack = ItemStack.loadItemStackFromNBT(toInsertList.getCompoundTagAt(i));
|
||||
@@ -55,15 +56,7 @@ public class CraftingTaskFactory implements ICraftingTaskFactory {
|
||||
|
||||
NBTTagList tookList = tag.getTagList(CraftingTask.NBT_TOOK, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
List<ItemStack> took = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < tookList.tagCount(); ++i) {
|
||||
ItemStack tookStack = ItemStack.loadItemStackFromNBT(tookList.getCompoundTagAt(i));
|
||||
|
||||
if (tookStack != null) {
|
||||
took.add(tookStack);
|
||||
}
|
||||
}
|
||||
IItemStackList took = RSUtils.readItemStackList(tookList);
|
||||
|
||||
NBTTagList tookFluidsList = tag.getTagList(CraftingTask.NBT_TOOK_FLUIDS, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
@@ -77,7 +70,7 @@ public class CraftingTaskFactory implements ICraftingTaskFactory {
|
||||
}
|
||||
}
|
||||
|
||||
return new CraftingTask(network, stack, pattern, quantity, toProcess, toTake, toTakeFluids, new ArrayDeque<>(toInsert), took, tookFluids);
|
||||
return new CraftingTask(network, stack, pattern, quantity, toProcess, toTake, internalToTake, toTakeFluids, toInsert, took, tookFluids);
|
||||
}
|
||||
|
||||
return new CraftingTask(network, stack, pattern, quantity);
|
||||
|
||||
@@ -27,12 +27,14 @@ import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemSta
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CraftingTask implements ICraftingTask {
|
||||
private static final int DEFAULT_COMPARE = IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT;
|
||||
|
||||
public static final String NBT_TO_PROCESS = "ToProcess";
|
||||
public static final String NBT_TO_TAKE = "ToTake";
|
||||
public static final String NBT_INTERNAL_TO_TAKE = "InternalToTake";
|
||||
public static final String NBT_TO_TAKE_FLUIDS = "ToTakeFluids";
|
||||
public static final String NBT_TO_INSERT = "ToInsert";
|
||||
public static final String NBT_TOOK = "Took";
|
||||
@@ -45,13 +47,14 @@ public class CraftingTask implements ICraftingTask {
|
||||
private int quantity;
|
||||
private List<IProcessable> toProcess = new ArrayList<>();
|
||||
private IItemStackList toTake = API.instance().createItemStackList();
|
||||
private IItemStackList internalToTake = API.instance().createItemStackList();
|
||||
private IItemStackList toCraft = API.instance().createItemStackList();
|
||||
private IFluidStackList toTakeFluids = API.instance().createFluidStackList();
|
||||
private IItemStackList missing = API.instance().createItemStackList();
|
||||
private Set<ICraftingPattern> usedPatterns = new HashSet<>();
|
||||
private boolean recurseFound = false;
|
||||
private Deque<ItemStack> toInsert = new ArrayDeque<>();
|
||||
private List<ItemStack> took = new ArrayList<>();
|
||||
private IItemStackList took = API.instance().createItemStackList();
|
||||
private List<FluidStack> tookFluids = new ArrayList<>();
|
||||
|
||||
public CraftingTask(INetworkMaster network, @Nullable ItemStack requested, ICraftingPattern pattern, int quantity) {
|
||||
@@ -61,11 +64,12 @@ public class CraftingTask implements ICraftingTask {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public CraftingTask(INetworkMaster network, @Nullable ItemStack requested, ICraftingPattern pattern, int quantity, List<IProcessable> toProcess, IItemStackList toTake, IFluidStackList toTakeFluids, Deque<ItemStack> toInsert, List<ItemStack> took, List<FluidStack> tookFluids) {
|
||||
public CraftingTask(INetworkMaster network, @Nullable ItemStack requested, ICraftingPattern pattern, int quantity, List<IProcessable> toProcess, IItemStackList toTake, IItemStackList internalToTake, IFluidStackList toTakeFluids, Deque<ItemStack> toInsert, IItemStackList took, List<FluidStack> tookFluids) {
|
||||
this(network, requested, pattern, quantity);
|
||||
|
||||
this.toProcess = toProcess;
|
||||
this.toTake = toTake;
|
||||
this.internalToTake = internalToTake;
|
||||
this.toTakeFluids = toTakeFluids;
|
||||
this.toInsert = toInsert;
|
||||
this.took = took;
|
||||
@@ -140,6 +144,10 @@ public class CraftingTask implements ICraftingTask {
|
||||
// Calculate added all the crafted outputs toInsert
|
||||
// So we remove the ones we use from toInsert
|
||||
toInsert.remove(inputCrafted, true);
|
||||
// If the pattern is processing the have to be taken.
|
||||
if (pattern.isProcessing()) {
|
||||
internalToTake.add(inputCrafted.copy());
|
||||
}
|
||||
} else if (doFluidCalculation(networkList, input, toInsert)) {
|
||||
actualInputs.add(ItemHandlerHelper.copyStackWithSize(input, 1));
|
||||
input.stackSize -= 1;
|
||||
@@ -212,7 +220,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
|
||||
@Override
|
||||
public void onCancelled() {
|
||||
for (ItemStack stack : took) {
|
||||
for (ItemStack stack : took.getStacks()) {
|
||||
network.insertItem(stack, stack.stackSize, false);
|
||||
}
|
||||
|
||||
@@ -225,6 +233,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
public String toString() {
|
||||
return "\nCraftingTask{quantity=" + quantity +
|
||||
"\n, toTake=" + toTake +
|
||||
"\n, internalToTake=" + internalToTake +
|
||||
"\n, toTakeFluids=" + toTakeFluids +
|
||||
"\n, toProcess=" + toProcess +
|
||||
"\n, toCraft=" + toProcess +
|
||||
@@ -234,24 +243,6 @@ public class CraftingTask implements ICraftingTask {
|
||||
|
||||
@Override
|
||||
public boolean update() {
|
||||
for (IProcessable processable : toProcess) {
|
||||
IItemHandler inventory = processable.getPattern().getContainer().getFacingInventory();
|
||||
|
||||
if (inventory != null && !processable.hasStartedProcessing() && processable.canStartProcessing(network.getItemStorageCache().getList()) && canProcess(processable)) {
|
||||
processable.setStartedProcessing();
|
||||
|
||||
for (ItemStack insertStack : processable.getToInsert().getStacks()) {
|
||||
ItemStack toInsert = network.extractItem(insertStack, insertStack.stackSize, DEFAULT_COMPARE | (processable.getPattern().isOredict() ? IComparer.COMPARE_OREDICT : 0));
|
||||
|
||||
if (ItemHandlerHelper.insertItem(inventory, toInsert, true) == null) {
|
||||
ItemHandlerHelper.insertItem(inventory, toInsert, false);
|
||||
|
||||
network.sendCraftingMonitorUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack stack : toTake.getStacks()) {
|
||||
ItemStack stackExtracted = network.extractItem(stack, Math.min(stack.stackSize, 64));
|
||||
|
||||
@@ -266,6 +257,41 @@ public class CraftingTask implements ICraftingTask {
|
||||
}
|
||||
}
|
||||
|
||||
// Fetches results from processing patterns
|
||||
for (ItemStack stack : internalToTake.getStacks()) {
|
||||
ItemStack stackExtracted = network.extractItem(stack, Math.min(stack.stackSize, 64));
|
||||
|
||||
if (stackExtracted != null) {
|
||||
internalToTake.remove(stack, stackExtracted.stackSize, false);
|
||||
|
||||
took.add(stackExtracted);
|
||||
|
||||
network.sendCraftingMonitorUpdate();
|
||||
}
|
||||
}
|
||||
// Clean up zero stacks, cause we can't remove them in the loop (CME ahoy!)
|
||||
internalToTake.clean();
|
||||
|
||||
for (IProcessable processable : toProcess) {
|
||||
IItemHandler inventory = processable.getPattern().getContainer().getFacingInventory();
|
||||
|
||||
if (inventory != null && !processable.hasStartedProcessing() && processable.canStartProcessing(took) && canProcess(processable)) {
|
||||
processable.setStartedProcessing();
|
||||
|
||||
for (ItemStack insertStack : processable.getToInsert().getStacks()) {
|
||||
ItemStack tookStack = took.get(insertStack, DEFAULT_COMPARE | (processable.getPattern().isOredict() ? IComparer.COMPARE_OREDICT : 0));
|
||||
ItemStack toInsert = ItemHandlerHelper.copyStackWithSize(tookStack, insertStack.stackSize);
|
||||
|
||||
if (ItemHandlerHelper.insertItem(inventory, toInsert, true) == null) {
|
||||
ItemHandlerHelper.insertItem(inventory, toInsert, false);
|
||||
took.remove(tookStack, toInsert.stackSize, true);
|
||||
|
||||
network.sendCraftingMonitorUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we took all the items, we can start taking fluids
|
||||
if (toTake.isEmpty()) {
|
||||
for (FluidStack stack : toTakeFluids.getStacks()) {
|
||||
@@ -353,6 +379,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
tag.setTag(NBT_TO_PROCESS, processablesList);
|
||||
|
||||
tag.setTag(NBT_TO_TAKE, RSUtils.serializeItemStackList(toTake));
|
||||
tag.setTag(NBT_INTERNAL_TO_TAKE, RSUtils.serializeItemStackList(internalToTake));
|
||||
tag.setTag(NBT_TO_TAKE_FLUIDS, RSUtils.serializeFluidStackList(toTakeFluids));
|
||||
|
||||
NBTTagList toInsertList = new NBTTagList();
|
||||
@@ -363,13 +390,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
|
||||
tag.setTag(NBT_TO_INSERT, toInsertList);
|
||||
|
||||
NBTTagList tookList = new NBTTagList();
|
||||
|
||||
for (ItemStack took : this.took) {
|
||||
tookList.appendTag(took.serializeNBT());
|
||||
}
|
||||
|
||||
tag.setTag(NBT_TOOK, tookList);
|
||||
tag.setTag(NBT_TOOK, RSUtils.serializeItemStackList(took));
|
||||
|
||||
NBTTagList fluidsTookList = new NBTTagList();
|
||||
|
||||
@@ -524,7 +545,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
}
|
||||
|
||||
private boolean isFinished() {
|
||||
return toTake.isEmpty() && toTakeFluids.isEmpty() && missing.isEmpty() && hasProcessedItems();
|
||||
return toTake.isEmpty() && internalToTake.isEmpty() && toTakeFluids.isEmpty() && missing.isEmpty() && hasProcessedItems();
|
||||
}
|
||||
|
||||
private boolean hasProcessedItems() {
|
||||
|
||||
@@ -9,6 +9,7 @@ import refinedstorage.apiimpl.API;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FluidStackList implements IFluidStackList {
|
||||
private ArrayListMultimap<Fluid, FluidStack> stacks = ArrayListMultimap.create();
|
||||
|
||||
@@ -10,6 +10,8 @@ import refinedstorage.apiimpl.API;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemStackList implements IItemStackList {
|
||||
private ArrayListMultimap<Item, ItemStack> stacks = ArrayListMultimap.create();
|
||||
@@ -74,6 +76,14 @@ public class ItemStackList implements IItemStackList {
|
||||
stacks.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clean() {
|
||||
List<ItemStack> toRemove = stacks.values().stream()
|
||||
.filter(stack -> stack.stackSize <= 0)
|
||||
.collect(Collectors.toList());
|
||||
toRemove.forEach(stack -> stacks.remove(stack.getItem(), stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return stacks.isEmpty();
|
||||
|
||||
@@ -13,6 +13,8 @@ import net.minecraftforge.fml.client.config.GuiCheckBox;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import refinedstorage.RS;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.api.render.IElementDrawers;
|
||||
import refinedstorage.apiimpl.storage.fluid.FluidRenderer;
|
||||
import refinedstorage.gui.sidebutton.SideButton;
|
||||
import refinedstorage.inventory.ItemHandlerFluid;
|
||||
@@ -28,6 +30,25 @@ public abstract class GuiBase extends GuiContainer {
|
||||
|
||||
public static final FluidRenderer FLUID_RENDERER = new FluidRenderer(-1, 16, 16);
|
||||
|
||||
public class ElementDrawers implements IElementDrawers {
|
||||
private IElementDrawer<FluidStack> fluidDrawer = (x, y, element) -> FLUID_RENDERER.draw(GuiBase.this.mc, x, y, element);
|
||||
|
||||
@Override
|
||||
public IElementDrawer<ItemStack> getItemDrawer() {
|
||||
return GuiBase.this::drawItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElementDrawer<FluidStack> getFluidDrawer() {
|
||||
return fluidDrawer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElementDrawer<String> getStringDrawer() {
|
||||
return GuiBase.this::drawString;
|
||||
}
|
||||
}
|
||||
|
||||
private int lastButtonId;
|
||||
private int lastSideButtonY = 6;
|
||||
|
||||
|
||||
@@ -4,12 +4,10 @@ import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import refinedstorage.RS;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementDrawers;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.api.render.IElementDrawers;
|
||||
import refinedstorage.container.ContainerCraftingMonitor;
|
||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||
import refinedstorage.network.MessageCraftingMonitorCancel;
|
||||
@@ -19,8 +17,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiCraftingMonitor extends GuiBase {
|
||||
public class CraftingMonitorElementDrawers implements ICraftingMonitorElementDrawers {
|
||||
private IElementDrawer<FluidStack> fluidDrawer = (x, y, element) -> FLUID_RENDERER.draw(GuiCraftingMonitor.this.mc, x, y, element);
|
||||
public class CraftingMonitorElementDrawers extends ElementDrawers {
|
||||
private IElementDrawer redOverlayDrawer = (x, y, element) -> {
|
||||
GlStateManager.color(1, 1, 1);
|
||||
bindTexture("gui/crafting_preview.png"); // Don't even care
|
||||
@@ -29,22 +26,7 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
};
|
||||
|
||||
@Override
|
||||
public IElementDrawer<ItemStack> getItemDrawer() {
|
||||
return GuiCraftingMonitor.this::drawItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElementDrawer<FluidStack> getFluidDrawer() {
|
||||
return fluidDrawer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElementDrawer<String> getStringDrawer() {
|
||||
return GuiCraftingMonitor.this::drawString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElementDrawer<?> getRedOverlayDrawer() {
|
||||
public IElementDrawer getRedOverlayDrawer() {
|
||||
return redOverlayDrawer;
|
||||
}
|
||||
}
|
||||
@@ -59,7 +41,7 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
private GuiButton cancelButton;
|
||||
private GuiButton cancelAllButton;
|
||||
|
||||
private ICraftingMonitorElementDrawers drawers = new CraftingMonitorElementDrawers();
|
||||
private IElementDrawers drawers = new CraftingMonitorElementDrawers();
|
||||
|
||||
private int itemSelected = -1;
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.lwjgl.input.Keyboard;
|
||||
import refinedstorage.RS;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.api.render.IElementDrawers;
|
||||
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack;
|
||||
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
|
||||
import refinedstorage.network.MessageGridCraftingStart;
|
||||
@@ -23,6 +24,19 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiCraftingPreview extends GuiBase {
|
||||
public class CraftingPreviewElementDrawers extends ElementDrawers {
|
||||
private IElementDrawer redOverlayDrawer = (x, y, element) -> {
|
||||
GlStateManager.color(1, 1, 1);
|
||||
bindTexture("gui/crafting_preview.png");
|
||||
drawTexture(x, y, 189, 0, 67, 29);
|
||||
};
|
||||
|
||||
@Override
|
||||
public IElementDrawer getRedOverlayDrawer() {
|
||||
return redOverlayDrawer;
|
||||
}
|
||||
}
|
||||
|
||||
private static final int VISIBLE_ROWS = 4;
|
||||
|
||||
private List<ICraftingPreviewElement> stacks;
|
||||
@@ -34,9 +48,7 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
private GuiButton startButton;
|
||||
private GuiButton cancelButton;
|
||||
|
||||
private IElementDrawer<String> stringDrawer = this::drawString;
|
||||
private IElementDrawer<ItemStack> itemDrawer = this::drawItem;
|
||||
private IElementDrawer<FluidStack> fluidDrawer = (x, y, element) -> FLUID_RENDERER.draw(mc, x, y, element);
|
||||
private IElementDrawers drawers = new CraftingPreviewElementDrawers();
|
||||
|
||||
public GuiCraftingPreview(GuiScreen parent, List<ICraftingPreviewElement> stacks, int hash, int quantity) {
|
||||
super(new Container() {
|
||||
@@ -77,47 +89,22 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
if (stacks.isEmpty()) {
|
||||
drawRect(x + 7, y + 20, x + 142, y + 139, 0xFFDBDBDB);
|
||||
}
|
||||
else {
|
||||
x += 7;
|
||||
y += 20;
|
||||
|
||||
int slot = scrollbar.getOffset() * 2;
|
||||
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if (slot < stacks.size()) {
|
||||
ICraftingPreviewElement stack = stacks.get(slot);
|
||||
|
||||
if (stack.hasMissing()) {
|
||||
drawTexture(x, y, 189, 0, 67, 29);
|
||||
}
|
||||
}
|
||||
|
||||
if (i % 2 == 1) {
|
||||
x -= 68;
|
||||
y += 30;
|
||||
} else {
|
||||
x += 68;
|
||||
}
|
||||
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
drawString(7, 7, t("gui.refinedstorage:crafting_preview"));
|
||||
|
||||
int x = 12;
|
||||
int y = 22;
|
||||
int x = 7;
|
||||
int y = 15;
|
||||
float scale = 0.5f;
|
||||
|
||||
if (stacks.isEmpty()) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
drawString(calculateOffsetOnScale(x + 34, scale), calculateOffsetOnScale(y + 50, scale), t("gui.refinedstorage:crafting_preview.circular"));
|
||||
drawString(calculateOffsetOnScale(x + 35, scale), calculateOffsetOnScale(y + 57, scale), t("gui.refinedstorage:crafting_preview.loop"));
|
||||
drawString(calculateOffsetOnScale(x + 39, scale), calculateOffsetOnScale(y + 57, scale), t("gui.refinedstorage:crafting_preview.circular"));
|
||||
drawString(calculateOffsetOnScale(x + 40, scale), calculateOffsetOnScale(y + 64, scale), t("gui.refinedstorage:crafting_preview.loop"));
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
} else {
|
||||
@@ -134,7 +121,7 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
if (slot < stacks.size()) {
|
||||
ICraftingPreviewElement stack = stacks.get(slot);
|
||||
|
||||
stack.draw(x, y + 5, itemDrawer, fluidDrawer, stringDrawer);
|
||||
stack.draw(x, y + 5, drawers);
|
||||
|
||||
if (inBounds(x, y, 16, 16, mouseX, mouseY)) {
|
||||
hoveringStack = stack.getId().equals(CraftingPreviewElementItemStack.ID) ? (ItemStack) stack.getElement() : null;
|
||||
|
||||
Reference in New Issue
Block a user