Fix craftable items having stack size 0
This commit is contained in:
@@ -59,13 +59,14 @@ public final class RSUtils {
|
||||
QUANTITY_FORMATTER.setRoundingMode(RoundingMode.DOWN);
|
||||
}
|
||||
|
||||
public static void writeItemStack(ByteBuf buf, INetworkMaster network, ItemStack stack) {
|
||||
public static void writeItemStack(ByteBuf buf, INetworkMaster network, ItemStack stack, boolean outputFromPattern) {
|
||||
buf.writeInt(Item.getIdFromItem(stack.getItem()));
|
||||
buf.writeInt(stack.getCount());
|
||||
buf.writeInt(stack.getItemDamage());
|
||||
ByteBufUtils.writeTag(buf, stack.getItem().getNBTShareTag(stack));
|
||||
buf.writeInt(API.instance().getItemStackHashCode(stack));
|
||||
buf.writeBoolean(network.hasPattern(stack));
|
||||
buf.writeBoolean(outputFromPattern);
|
||||
}
|
||||
|
||||
public static void writeFluidStack(ByteBuf buf, FluidStack stack) {
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.storage.item;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.item.IItemStorage;
|
||||
@@ -39,20 +38,12 @@ public class ItemStorageCache implements IItemStorageCache {
|
||||
}
|
||||
|
||||
for (ItemStack stack : storage.getStacks()) {
|
||||
if (stack != null) {
|
||||
if (!stack.isEmpty()) {
|
||||
add(stack, stack.getCount(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ICraftingPattern pattern : network.getPatterns()) {
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
ItemStack patternStack = output.copy();
|
||||
patternStack.setCount(0);
|
||||
add(patternStack, patternStack.getCount(), true);
|
||||
}
|
||||
}
|
||||
|
||||
network.sendItemStorageToClient();
|
||||
}
|
||||
|
||||
@@ -67,7 +58,7 @@ public class ItemStorageCache implements IItemStorageCache {
|
||||
|
||||
@Override
|
||||
public synchronized void remove(@Nonnull ItemStack stack, int size) {
|
||||
if (list.remove(stack, size, !network.hasPattern(stack))) {
|
||||
if (list.remove(stack, size, true)) {
|
||||
network.sendItemStorageDeltaToClient(stack, -size);
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ public class ItemStackList implements IItemStackList {
|
||||
@Override
|
||||
public boolean remove(@Nonnull ItemStack stack, int size, boolean removeIfReachedZero) {
|
||||
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
||||
if (otherStack.getCount() > 0 && API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
|
||||
if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
|
||||
if (otherStack.getCount() - size <= 0 && removeIfReachedZero) {
|
||||
stacks.remove(otherStack.getItem(), otherStack);
|
||||
} else {
|
||||
@@ -56,7 +56,7 @@ public class ItemStackList implements IItemStackList {
|
||||
@Override
|
||||
public boolean trackedRemove(@Nonnull ItemStack stack, int size, boolean removeIfReachedZero) {
|
||||
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
||||
if (otherStack.getCount() > 0 && API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
|
||||
if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
|
||||
ItemStack removed = ItemHandlerHelper.copyStackWithSize(otherStack, Math.min(size, otherStack.getCount()));
|
||||
this.removeTracker.add(removed);
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ItemStackList implements IItemStackList {
|
||||
public ItemStack get(@Nonnull ItemStack stack, int flags) {
|
||||
// When the oredict flag is set all stacks need to be checked not just the ones matching the item
|
||||
for (ItemStack otherStack : (flags & IComparer.COMPARE_OREDICT) == IComparer.COMPARE_OREDICT ? stacks.values() : stacks.get(stack.getItem())) {
|
||||
if (otherStack.getCount() > 0 && API.instance().getComparer().isEqual(otherStack, stack, flags)) {
|
||||
if (API.instance().getComparer().isEqual(otherStack, stack, flags)) {
|
||||
return otherStack;
|
||||
}
|
||||
}
|
||||
|
@@ -369,7 +369,7 @@ public class GuiGrid extends GuiBase {
|
||||
if (grid.getType() != EnumGridType.FLUID && (held.isEmpty() || (!held.isEmpty() && clickedButton == 2))) {
|
||||
ClientStackItem stack = (ClientStackItem) STACKS.get(slotNumber);
|
||||
|
||||
if (stack.isCraftable() && (stack.getQuantity() == 0 || (GuiScreen.isShiftKeyDown() && GuiScreen.isCtrlKeyDown()))) {
|
||||
if (stack.isCraftable() && (stack.isOutputFromPattern() || (GuiScreen.isShiftKeyDown() && GuiScreen.isCtrlKeyDown()))) {
|
||||
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingStart(this, container.getPlayer(), stack));
|
||||
} else {
|
||||
int flags = 0;
|
||||
|
@@ -17,12 +17,14 @@ public class ClientStackItem implements IClientStack {
|
||||
private int hash;
|
||||
private ItemStack stack;
|
||||
private boolean craftable;
|
||||
private boolean outputFromPattern;
|
||||
|
||||
public ClientStackItem(ByteBuf buf) {
|
||||
stack = new ItemStack(Item.getItemById(buf.readInt()), buf.readInt(), buf.readInt());
|
||||
stack.setTagCompound(ByteBufUtils.readTag(buf));
|
||||
hash = buf.readInt();
|
||||
craftable = buf.readBoolean();
|
||||
setOutputFromPattern(buf.readBoolean());
|
||||
}
|
||||
|
||||
public ItemStack getStack() {
|
||||
@@ -33,6 +35,18 @@ public class ClientStackItem implements IClientStack {
|
||||
return craftable;
|
||||
}
|
||||
|
||||
public boolean isOutputFromPattern() {
|
||||
return outputFromPattern;
|
||||
}
|
||||
|
||||
public void setOutputFromPattern(boolean outputFromPattern) {
|
||||
this.outputFromPattern = outputFromPattern;
|
||||
|
||||
if (outputFromPattern) {
|
||||
stack.setCount(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHash() {
|
||||
return hash;
|
||||
@@ -72,12 +86,12 @@ public class ClientStackItem implements IClientStack {
|
||||
private String getQuantityForDisplay(boolean advanced) {
|
||||
int qty = stack.getCount();
|
||||
|
||||
if (advanced && qty > 1) {
|
||||
if (outputFromPattern) {
|
||||
return I18n.format("gui.refinedstorage:grid.craft");
|
||||
} else if (advanced && qty > 1) {
|
||||
return String.valueOf(qty);
|
||||
} else if (qty == 1) {
|
||||
return null;
|
||||
} else if (qty == 0) {
|
||||
return I18n.format("gui.refinedstorage:grid.craft");
|
||||
}
|
||||
|
||||
return RSUtils.formatQuantity(qty);
|
||||
|
@@ -35,7 +35,7 @@ public class MessageGridItemDelta implements IMessage, IMessageHandler<MessageGr
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
RSUtils.writeItemStack(buf, network, stack);
|
||||
RSUtils.writeItemStack(buf, network, stack, false);
|
||||
buf.writeInt(delta);
|
||||
}
|
||||
|
||||
@@ -45,10 +45,15 @@ public class MessageGridItemDelta implements IMessage, IMessageHandler<MessageGr
|
||||
|
||||
for (ClientStackItem stack : GuiGrid.ITEMS.get(item)) {
|
||||
if (stack.equals(message.clientStack)) {
|
||||
if (stack.getStack().getCount() + message.delta == 0 && !message.clientStack.isCraftable()) {
|
||||
GuiGrid.ITEMS.remove(item, stack);
|
||||
if (stack.getStack().getCount() + message.delta == 0) {
|
||||
if (message.clientStack.isCraftable()) {
|
||||
stack.setOutputFromPattern(true);
|
||||
} else {
|
||||
GuiGrid.ITEMS.remove(item, stack);
|
||||
}
|
||||
} else {
|
||||
stack.getStack().grow(message.delta);
|
||||
stack.getStack().grow(message.delta - (stack.isOutputFromPattern() ? 1 : 0));
|
||||
stack.setOutputFromPattern(false);
|
||||
}
|
||||
|
||||
GuiGrid.markForSorting();
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package com.raoulvdberge.refinedstorage.network;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.gui.grid.GuiGrid;
|
||||
import com.raoulvdberge.refinedstorage.gui.grid.stack.ClientStackItem;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -28,7 +30,7 @@ public class MessageGridItemUpdate implements IMessage, IMessageHandler<MessageG
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int items = buf.readInt();
|
||||
|
||||
for (int i = 0; i < items; ++i) {
|
||||
for (int i = 0; i < items + 1; ++i) {
|
||||
this.stacks.add(new ClientStackItem(buf));
|
||||
}
|
||||
}
|
||||
@@ -38,7 +40,15 @@ public class MessageGridItemUpdate implements IMessage, IMessageHandler<MessageG
|
||||
buf.writeInt(network.getItemStorageCache().getList().getStacks().size());
|
||||
|
||||
for (ItemStack stack : network.getItemStorageCache().getList().getStacks()) {
|
||||
RSUtils.writeItemStack(buf, network, stack);
|
||||
RSUtils.writeItemStack(buf, network, stack, false);
|
||||
}
|
||||
|
||||
for (ICraftingPattern pattern : network.getPatterns()) {
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
if (output != null) {
|
||||
RSUtils.writeItemStack(buf, network, output, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +57,22 @@ public class MessageGridItemUpdate implements IMessage, IMessageHandler<MessageG
|
||||
GuiGrid.ITEMS.clear();
|
||||
|
||||
for (ClientStackItem item : message.stacks) {
|
||||
GuiGrid.ITEMS.put(item.getStack().getItem(), item);
|
||||
boolean canAdd = true;
|
||||
|
||||
if (item.isOutputFromPattern()) {
|
||||
// This is an output from a pattern being sent. Only add it if it hasn't been added before.
|
||||
for (ClientStackItem otherItem : GuiGrid.ITEMS.get(item.getStack().getItem())) {
|
||||
if (API.instance().getComparer().isEqualNoQuantity(item.getStack(), otherItem.getStack())) {
|
||||
canAdd = false;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (canAdd) {
|
||||
GuiGrid.ITEMS.put(item.getStack().getItem(), item);
|
||||
}
|
||||
}
|
||||
|
||||
GuiGrid.markForSorting();
|
||||
|
Reference in New Issue
Block a user