Autocrafting (de)serialization.

This commit is contained in:
raoulvdberge
2018-08-16 14:00:36 +02:00
parent a10a3fe87d
commit ca5e8f96af
8 changed files with 315 additions and 31 deletions

View File

@@ -19,7 +19,7 @@ import java.util.List;
* Represents a grid. * Represents a grid.
*/ */
public interface IGrid { public interface IGrid {
int TABS_PER_PAGE = 6; int TABS_PER_PAGE = 5;
int SORTING_DIRECTION_ASCENDING = 0; int SORTING_DIRECTION_ASCENDING = 0;
int SORTING_DIRECTION_DESCENDING = 1; int SORTING_DIRECTION_DESCENDING = 1;

View File

@@ -22,6 +22,6 @@ public class CraftingTaskFactory implements ICraftingTaskFactory {
@Override @Override
public ICraftingTask createFromNbt(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException { public ICraftingTask createFromNbt(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException {
throw new CraftingTaskReadException("Persistence isn't implemented yet, ignoring..."); // TODO: Persistence return new CraftingTask(network, tag);
} }
} }

View File

@@ -1,11 +1,21 @@
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task; package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task;
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern; import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.CraftingTaskReadException;
import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.util.IStackList; import com.raoulvdberge.refinedstorage.api.util.IStackList;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraftforge.common.util.Constants;
class Crafting { class Crafting {
private static final String NBT_PATTERN = "Pattern";
private static final String NBT_TOOK = "Took";
private static final String NBT_TO_EXTRACT = "ToExtract";
private ICraftingPattern pattern; private ICraftingPattern pattern;
private NonNullList<ItemStack> took; private NonNullList<ItemStack> took;
private IStackList<ItemStack> toExtract; private IStackList<ItemStack> toExtract;
@@ -16,6 +26,21 @@ class Crafting {
this.toExtract = toExtract; this.toExtract = toExtract;
} }
public Crafting(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException {
this.pattern = CraftingTask.readPatternFromNbt(tag.getCompoundTag(NBT_PATTERN), network.world());
this.toExtract = CraftingTask.readItemStackList(tag.getTagList(NBT_TO_EXTRACT, Constants.NBT.TAG_COMPOUND));
this.took = NonNullList.create();
NBTTagList tookList = tag.getTagList(NBT_TOOK, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tookList.tagCount(); ++i) {
ItemStack stack = StackUtils.deserializeStackFromNbt(tookList.getCompoundTagAt(i));
// Can be empty.
took.add(stack);
}
}
public ICraftingPattern getPattern() { public ICraftingPattern getPattern() {
return pattern; return pattern;
} }
@@ -27,4 +52,20 @@ class Crafting {
public IStackList<ItemStack> getToExtract() { public IStackList<ItemStack> getToExtract() {
return toExtract; return toExtract;
} }
public NBTTagCompound writeToNbt() {
NBTTagCompound tag = new NBTTagCompound();
tag.setTag(NBT_PATTERN, CraftingTask.writePatternToNbt(pattern));
tag.setTag(NBT_TO_EXTRACT, CraftingTask.writeItemStackList(toExtract));
NBTTagList tookList = new NBTTagList();
for (ItemStack took : this.took) {
tookList.appendTag(StackUtils.serializeStackToNbt(took));
}
tag.setTag(NBT_TOOK, tookList);
return tag;
}
} }

View File

@@ -1,17 +1,13 @@
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task; package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task;
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern; import com.raoulvdberge.refinedstorage.api.autocrafting.*;
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPatternChain;
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPatternChainList;
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement; import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementList; import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementList;
import com.raoulvdberge.refinedstorage.api.autocrafting.preview.ICraftingPreviewElement; import com.raoulvdberge.refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.CraftingTaskErrorType; import com.raoulvdberge.refinedstorage.api.autocrafting.task.*;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingRequestInfo;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTaskError;
import com.raoulvdberge.refinedstorage.api.network.INetwork; import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.storage.IStorage; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.util.Action; import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.api.util.IStackList; import com.raoulvdberge.refinedstorage.api.util.IStackList;
@@ -21,11 +17,18 @@ import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.Craf
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack; import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFactoryFluid;
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFactoryItem;
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFluid; import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFluid;
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskItem; import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskItem;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;
@@ -33,6 +36,24 @@ import javax.annotation.Nullable;
import java.util.*; import java.util.*;
public class CraftingTask implements ICraftingTask { public class CraftingTask implements ICraftingTask {
private static final String NBT_REQUESTED = "Requested";
private static final String NBT_QUANTITY = "Quantity";
private static final String NBT_PATTERN = "Pattern";
private static final String NBT_TICKS = "Ticks";
private static final String NBT_ID = "Id";
private static final String NBT_EXECUTION_STARTED = "ExecutionStarted";
private static final String NBT_INTERNAL_STORAGE = "InternalStorage";
private static final String NBT_INTERNAL_FLUID_STORAGE = "InternalFluidStorage";
private static final String NBT_TO_EXTRACT_INITIAL = "ToExtractInitial";
private static final String NBT_TO_EXTRACT_INITIAL_FLUIDS = "ToExtractInitialFluids";
private static final String NBT_CRAFTING = "Crafting";
private static final String NBT_PROCESSING = "Processing";
private static final String NBT_MISSING = "Missing";
private static final String NBT_MISSING_FLUIDS = "MissingFluids";
private static final String NBT_PATTERN_STACK = "Stack";
private static final String NBT_PATTERN_CONTAINER_POS = "ContainerPos";
private static final long CALCULATION_TIMEOUT_MS = 5000; private static final long CALCULATION_TIMEOUT_MS = 5000;
private INetwork network; private INetwork network;
@@ -45,8 +66,8 @@ public class CraftingTask implements ICraftingTask {
private long executionStarted = -1; private long executionStarted = -1;
private Set<ICraftingPattern> patternsUsed = new HashSet<>(); private Set<ICraftingPattern> patternsUsed = new HashSet<>();
private IStorage<ItemStack> internalStorage; private IStorageDisk<ItemStack> internalStorage;
private IStorage<FluidStack> internalFluidStorage; private IStorageDisk<FluidStack> internalFluidStorage;
private IStackList<ItemStack> toExtractInitial = API.instance().createItemStackList(); private IStackList<ItemStack> toExtractInitial = API.instance().createItemStackList();
private IStackList<FluidStack> toExtractInitialFluids = API.instance().createFluidStackList(); private IStackList<FluidStack> toExtractInitialFluids = API.instance().createFluidStackList();
@@ -54,12 +75,12 @@ public class CraftingTask implements ICraftingTask {
private List<Crafting> crafting = new ArrayList<>(); private List<Crafting> crafting = new ArrayList<>();
private List<Processing> processing = new ArrayList<>(); private List<Processing> processing = new ArrayList<>();
private IStackList<ItemStack> toTake = API.instance().createItemStackList();
private IStackList<FluidStack> toTakeFluids = API.instance().createFluidStackList();
private IStackList<ItemStack> missing = API.instance().createItemStackList(); private IStackList<ItemStack> missing = API.instance().createItemStackList();
private IStackList<FluidStack> missingFluids = API.instance().createFluidStackList(); private IStackList<FluidStack> missingFluids = API.instance().createFluidStackList();
private IStackList<ItemStack> toTake = API.instance().createItemStackList();
private IStackList<FluidStack> toTakeFluids = API.instance().createFluidStackList();
private IStackList<ItemStack> toCraft = API.instance().createItemStackList(); private IStackList<ItemStack> toCraft = API.instance().createItemStackList();
private IStackList<FluidStack> toCraftFluids = API.instance().createFluidStackList(); private IStackList<FluidStack> toCraftFluids = API.instance().createFluidStackList();
@@ -73,6 +94,124 @@ public class CraftingTask implements ICraftingTask {
this.internalFluidStorage = new StorageDiskFluid(network.world(), -1); this.internalFluidStorage = new StorageDiskFluid(network.world(), -1);
} }
public CraftingTask(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException {
this.network = network;
this.requested = API.instance().createCraftingRequestInfo(tag.getCompoundTag(NBT_REQUESTED));
this.quantity = tag.getInteger(NBT_QUANTITY);
this.pattern = readPatternFromNbt(tag.getCompoundTag(NBT_PATTERN), network.world());
this.ticks = tag.getInteger(NBT_TICKS);
this.id = tag.getUniqueId(NBT_ID);
this.executionStarted = tag.getLong(NBT_EXECUTION_STARTED);
StorageDiskFactoryItem factoryItem = new StorageDiskFactoryItem();
StorageDiskFactoryFluid factoryFluid = new StorageDiskFactoryFluid();
this.internalStorage = factoryItem.createFromNbt(network.world(), tag.getCompoundTag(NBT_INTERNAL_STORAGE));
this.internalFluidStorage = factoryFluid.createFromNbt(network.world(), tag.getCompoundTag(NBT_INTERNAL_FLUID_STORAGE));
this.toExtractInitial = readItemStackList(tag.getTagList(NBT_TO_EXTRACT_INITIAL, Constants.NBT.TAG_COMPOUND));
this.toExtractInitialFluids = readFluidStackList(tag.getTagList(NBT_TO_EXTRACT_INITIAL_FLUIDS, Constants.NBT.TAG_COMPOUND));
NBTTagList craftingList = tag.getTagList(NBT_CRAFTING, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < craftingList.tagCount(); ++i) {
crafting.add(new Crafting(network, craftingList.getCompoundTagAt(i)));
}
NBTTagList processingList = tag.getTagList(NBT_PROCESSING, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < processingList.tagCount(); ++i) {
processing.add(new Processing(network, processingList.getCompoundTagAt(i)));
}
this.missing = readItemStackList(tag.getTagList(NBT_MISSING, Constants.NBT.TAG_COMPOUND));
this.missingFluids = readFluidStackList(tag.getTagList(NBT_MISSING_FLUIDS, Constants.NBT.TAG_COMPOUND));
}
@Override
public NBTTagCompound writeToNbt(NBTTagCompound tag) {
tag.setTag(NBT_REQUESTED, requested.writeToNbt());
tag.setInteger(NBT_QUANTITY, quantity);
tag.setTag(NBT_PATTERN, writePatternToNbt(pattern));
tag.setInteger(NBT_TICKS, ticks);
tag.setUniqueId(NBT_ID, id);
tag.setLong(NBT_EXECUTION_STARTED, executionStarted);
tag.setTag(NBT_INTERNAL_STORAGE, internalStorage.writeToNbt());
tag.setTag(NBT_INTERNAL_FLUID_STORAGE, internalFluidStorage.writeToNbt());
tag.setTag(NBT_TO_EXTRACT_INITIAL, writeItemStackList(toExtractInitial));
tag.setTag(NBT_TO_EXTRACT_INITIAL_FLUIDS, writeFluidStackList(toExtractInitialFluids));
NBTTagList craftingList = new NBTTagList();
for (Crafting crafting : this.crafting) {
craftingList.appendTag(crafting.writeToNbt());
}
tag.setTag(NBT_CRAFTING, craftingList);
NBTTagList processingList = new NBTTagList();
for (Processing processing : this.processing) {
processingList.appendTag(processing.writeToNbt());
}
tag.setTag(NBT_PROCESSING, processingList);
tag.setTag(NBT_MISSING, writeItemStackList(missing));
tag.setTag(NBT_MISSING_FLUIDS, writeFluidStackList(missingFluids));
return tag;
}
public static NBTTagList writeItemStackList(IStackList<ItemStack> stacks) {
NBTTagList list = new NBTTagList();
for (ItemStack stack : stacks.getStacks()) {
list.appendTag(StackUtils.serializeStackToNbt(stack));
}
return list;
}
public static IStackList<ItemStack> readItemStackList(NBTTagList list) throws CraftingTaskReadException {
IStackList<ItemStack> stacks = API.instance().createItemStackList();
for (int i = 0; i < list.tagCount(); ++i) {
ItemStack stack = StackUtils.deserializeStackFromNbt(list.getCompoundTagAt(i));
if (stack.isEmpty()) {
throw new CraftingTaskReadException("Empty stack!");
}
stacks.add(stack);
}
return stacks;
}
public static NBTTagList writeFluidStackList(IStackList<FluidStack> stacks) {
NBTTagList list = new NBTTagList();
for (FluidStack stack : stacks.getStacks()) {
list.appendTag(stack.writeToNBT(new NBTTagCompound()));
}
return list;
}
public static IStackList<FluidStack> readFluidStackList(NBTTagList list) throws CraftingTaskReadException {
IStackList<FluidStack> stacks = API.instance().createFluidStackList();
for (int i = 0; i < list.tagCount(); ++i) {
FluidStack stack = FluidStack.loadFluidStackFromNBT(list.getCompoundTagAt(i));
if (stack == null) {
throw new CraftingTaskReadException("Empty stack!");
}
stacks.add(stack);
}
return stacks;
}
@Override @Override
@Nullable @Nullable
public ICraftingTaskError calculate() { public ICraftingTaskError calculate() {
@@ -564,6 +703,10 @@ public class CraftingTask implements ICraftingTask {
executionStarted = System.currentTimeMillis(); executionStarted = System.currentTimeMillis();
} }
if (true) {
return false;
}
++ticks; ++ticks;
extractInitial(); extractInitial();
@@ -731,9 +874,31 @@ public class CraftingTask implements ICraftingTask {
return size; return size;
} }
@Override public static NBTTagCompound writePatternToNbt(ICraftingPattern pattern) {
public NBTTagCompound writeToNbt(NBTTagCompound tag) { NBTTagCompound tag = new NBTTagCompound();
return new NBTTagCompound();
tag.setTag(NBT_PATTERN_STACK, pattern.getStack().serializeNBT());
tag.setLong(NBT_PATTERN_CONTAINER_POS, pattern.getContainer().getPosition().toLong());
return tag;
}
public static ICraftingPattern readPatternFromNbt(NBTTagCompound tag, World world) throws CraftingTaskReadException {
BlockPos containerPos = BlockPos.fromLong(tag.getLong(NBT_PATTERN_CONTAINER_POS));
INetworkNode node = API.instance().getNetworkNodeManager(world).getNode(containerPos);
if (node instanceof ICraftingPatternContainer) {
ItemStack stack = new ItemStack(tag.getCompoundTag(NBT_PATTERN_STACK));
if (stack.getItem() instanceof ICraftingPatternProvider) {
return ((ICraftingPatternProvider) stack.getItem()).create(world, stack, (ICraftingPatternContainer) node);
} else {
throw new CraftingTaskReadException("Pattern stack is not a crafting pattern provider");
}
} else {
throw new CraftingTaskReadException("Crafting pattern container doesn't exist anymore");
}
} }
@Override @Override

View File

@@ -1,21 +1,35 @@
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task; package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task;
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern; import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.CraftingTaskReadException;
import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.util.IStackList; import com.raoulvdberge.refinedstorage.api.util.IStackList;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import java.util.ArrayList;
import java.util.List; import java.util.List;
class Processing { class Processing {
private static final String NBT_PATTERN = "Pattern";
private static final String NBT_ITEMS_TO_RECEIVE = "ItemsToReceive";
private static final String NBT_FLUIDS_TO_RECEIVE = "FluidsToReceive";
private static final String NBT_ITEMS_TO_PUT = "ItemsToPut";
private static final String NBT_FLUIDS_TO_PUT = "FluidsToPut";
private static final String NBT_STATE = "State";
private ICraftingPattern pattern; private ICraftingPattern pattern;
private IStackList<ItemStack> itemsToReceive; private IStackList<ItemStack> itemsToReceive;
private IStackList<FluidStack> fluidsToReceive; private IStackList<FluidStack> fluidsToReceive;
private List<ItemStack> itemsToPut; private ArrayList<ItemStack> itemsToPut;
private List<FluidStack> fluidsToPut; private ArrayList<FluidStack> fluidsToPut;
private ProcessingState state = ProcessingState.READY; private ProcessingState state = ProcessingState.READY;
public Processing(ICraftingPattern pattern, IStackList<ItemStack> itemsToReceive, IStackList<FluidStack> fluidsToReceive, List<ItemStack> itemsToPut, List<FluidStack> fluidsToPut) { public Processing(ICraftingPattern pattern, IStackList<ItemStack> itemsToReceive, IStackList<FluidStack> fluidsToReceive, ArrayList<ItemStack> itemsToPut, ArrayList<FluidStack> fluidsToPut) {
this.pattern = pattern; this.pattern = pattern;
this.itemsToReceive = itemsToReceive; this.itemsToReceive = itemsToReceive;
this.fluidsToReceive = fluidsToReceive; this.fluidsToReceive = fluidsToReceive;
@@ -23,6 +37,40 @@ class Processing {
this.fluidsToPut = fluidsToPut; this.fluidsToPut = fluidsToPut;
} }
public Processing(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException {
this.pattern = CraftingTask.readPatternFromNbt(tag.getCompoundTag(NBT_PATTERN), network.world());
this.itemsToReceive = CraftingTask.readItemStackList(tag.getTagList(NBT_ITEMS_TO_RECEIVE, Constants.NBT.TAG_COMPOUND));
this.fluidsToReceive = CraftingTask.readFluidStackList(tag.getTagList(NBT_FLUIDS_TO_RECEIVE, Constants.NBT.TAG_COMPOUND));
this.itemsToPut = new ArrayList<>();
NBTTagList itemsToPutList = tag.getTagList(NBT_ITEMS_TO_PUT, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < itemsToPutList.tagCount(); ++i) {
ItemStack stack = StackUtils.deserializeStackFromNbt(itemsToPutList.getCompoundTagAt(i));
if (stack.isEmpty()) {
throw new CraftingTaskReadException("Stack is empty!");
}
itemsToPut.add(stack);
}
this.fluidsToPut = new ArrayList<>();
NBTTagList fluidsToPutList = tag.getTagList(NBT_FLUIDS_TO_PUT, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < fluidsToPutList.tagCount(); ++i) {
FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidsToPutList.getCompoundTagAt(i));
if (stack == null) {
throw new CraftingTaskReadException("Stack is empty!");
}
fluidsToPut.add(stack);
}
this.state = ProcessingState.values()[tag.getInteger(NBT_STATE)];
}
public ICraftingPattern getPattern() { public ICraftingPattern getPattern() {
return pattern; return pattern;
} }
@@ -50,4 +98,30 @@ class Processing {
public ProcessingState getState() { public ProcessingState getState() {
return state; return state;
} }
public NBTTagCompound writeToNbt() {
NBTTagCompound tag = new NBTTagCompound();
tag.setTag(NBT_PATTERN, CraftingTask.writePatternToNbt(pattern));
tag.setTag(NBT_ITEMS_TO_RECEIVE, CraftingTask.writeItemStackList(itemsToReceive));
tag.setTag(NBT_FLUIDS_TO_RECEIVE, CraftingTask.writeFluidStackList(fluidsToReceive));
NBTTagList itemsToPutList = new NBTTagList();
for (ItemStack stack : this.itemsToPut) {
itemsToPutList.appendTag(StackUtils.serializeStackToNbt(stack));
}
tag.setTag(NBT_ITEMS_TO_PUT, itemsToPutList);
NBTTagList fluidsToPutList = new NBTTagList();
for (FluidStack stack : this.fluidsToPut) {
fluidsToPutList.appendTag(stack.writeToNBT(new NBTTagCompound()));
}
tag.setTag(NBT_FLUIDS_TO_PUT, fluidsToPutList);
tag.setInteger(NBT_STATE, state.ordinal());
return tag;
}
} }

View File

@@ -102,6 +102,8 @@ public class GuiCraftingMonitor extends GuiBase {
itemDrawer.draw(x, y, requested.getItem()); itemDrawer.draw(x, y, requested.getItem());
} else { } else {
fluidDrawer.draw(x, y, requested.getFluid()); fluidDrawer.draw(x, y, requested.getFluid());
GlStateManager.enableAlpha();
} }
} }
} }

View File

@@ -63,7 +63,7 @@ public class TabList {
if (i < tabs.get().size()) { if (i < tabs.get().size()) {
drawTab(tabs.get().get(i), true, x, y, i, j); drawTab(tabs.get().get(i), true, x, y, i, j);
if (gui.inBounds(x + ((IGridTab.TAB_WIDTH + 1) * j), y, IGridTab.TAB_WIDTH, IGridTab.TAB_HEIGHT - (i == selected.get() ? 2 : 7), mouseX, mouseY)) { if (gui.inBounds(x + getXOffset() + ((IGridTab.TAB_WIDTH + 1) * j), y, IGridTab.TAB_WIDTH, IGridTab.TAB_HEIGHT - (i == selected.get() ? 2 : 7), mouseX, mouseY)) {
this.tabHovering = i; this.tabHovering = i;
} }
@@ -104,6 +104,14 @@ public class TabList {
return !tabs.get().isEmpty() ? IGridTab.TAB_HEIGHT - 4 : 0; return !tabs.get().isEmpty() ? IGridTab.TAB_HEIGHT - 4 : 0;
} }
private int getXOffset() {
if (pages.get() > 0) {
return 23;
}
return 0;
}
private void drawTab(IGridTab tab, boolean foregroundLayer, int x, int y, int index, int num) { private void drawTab(IGridTab tab, boolean foregroundLayer, int x, int y, int index, int num) {
boolean isSelected = index == selected.get(); boolean isSelected = index == selected.get();
@@ -111,7 +119,7 @@ public class TabList {
return; return;
} }
int tx = x + ((IGridTab.TAB_WIDTH + 1) * num); int tx = x + getXOffset() + ((IGridTab.TAB_WIDTH + 1) * num);
int ty = y; int ty = y;
GlStateManager.enableAlpha(); GlStateManager.enableAlpha();
@@ -130,7 +138,7 @@ public class TabList {
if (isSelected) { if (isSelected) {
uvx = 227; uvx = 227;
if (num > 0) { if (num > 0 || getXOffset() != 0) {
uvx = 226; uvx = 226;
uvy = 194; uvy = 194;
tbw++; tbw++;
@@ -149,12 +157,6 @@ public class TabList {
if (tabHovering >= 0 && tabHovering < tabs.get().size()) { if (tabHovering >= 0 && tabHovering < tabs.get().size()) {
tabs.get().get(tabHovering).drawTooltip(mouseX, mouseY, gui.getScreenWidth(), gui.getScreenHeight(), fontRenderer); tabs.get().get(tabHovering).drawTooltip(mouseX, mouseY, gui.getScreenWidth(), gui.getScreenHeight(), fontRenderer);
} }
if (pages.get() > 0) {
String text = (page.get() + 1) + " / " + (pages.get() + 1);
gui.drawString((int) ((width - (float) fontRenderer.getStringWidth(text)) / 2F), -16, text, 0xFFFFFF);
}
} }
public void mouseClicked() { public void mouseClicked() {

View File

@@ -12,7 +12,7 @@ import java.util.Collection;
import java.util.UUID; import java.util.UUID;
public interface ICraftingMonitor { public interface ICraftingMonitor {
int TABS_PER_PAGE = 6; int TABS_PER_PAGE = 7;
String getGuiTitle(); String getGuiTitle();