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);
|
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(Item.getIdFromItem(stack.getItem()));
|
||||||
buf.writeInt(stack.getCount());
|
buf.writeInt(stack.getCount());
|
||||||
buf.writeInt(stack.getItemDamage());
|
buf.writeInt(stack.getItemDamage());
|
||||||
ByteBufUtils.writeTag(buf, stack.getItem().getNBTShareTag(stack));
|
ByteBufUtils.writeTag(buf, stack.getItem().getNBTShareTag(stack));
|
||||||
buf.writeInt(API.instance().getItemStackHashCode(stack));
|
buf.writeInt(API.instance().getItemStackHashCode(stack));
|
||||||
buf.writeBoolean(network.hasPattern(stack));
|
buf.writeBoolean(network.hasPattern(stack));
|
||||||
|
buf.writeBoolean(outputFromPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeFluidStack(ByteBuf buf, FluidStack stack) {
|
public static void writeFluidStack(ByteBuf buf, FluidStack stack) {
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.storage.item;
|
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.network.INetworkMaster;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.item.IItemStorage;
|
import com.raoulvdberge.refinedstorage.api.storage.item.IItemStorage;
|
||||||
@@ -39,20 +38,12 @@ public class ItemStorageCache implements IItemStorageCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (ItemStack stack : storage.getStacks()) {
|
for (ItemStack stack : storage.getStacks()) {
|
||||||
if (stack != null) {
|
if (!stack.isEmpty()) {
|
||||||
add(stack, stack.getCount(), true);
|
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();
|
network.sendItemStorageToClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +58,7 @@ public class ItemStorageCache implements IItemStorageCache {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void remove(@Nonnull ItemStack stack, int size) {
|
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);
|
network.sendItemStorageDeltaToClient(stack, -size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,7 @@ public class ItemStackList implements IItemStackList {
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(@Nonnull ItemStack stack, int size, boolean removeIfReachedZero) {
|
public boolean remove(@Nonnull ItemStack stack, int size, boolean removeIfReachedZero) {
|
||||||
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
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) {
|
if (otherStack.getCount() - size <= 0 && removeIfReachedZero) {
|
||||||
stacks.remove(otherStack.getItem(), otherStack);
|
stacks.remove(otherStack.getItem(), otherStack);
|
||||||
} else {
|
} else {
|
||||||
@@ -56,7 +56,7 @@ public class ItemStackList implements IItemStackList {
|
|||||||
@Override
|
@Override
|
||||||
public boolean trackedRemove(@Nonnull ItemStack stack, int size, boolean removeIfReachedZero) {
|
public boolean trackedRemove(@Nonnull ItemStack stack, int size, boolean removeIfReachedZero) {
|
||||||
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
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()));
|
ItemStack removed = ItemHandlerHelper.copyStackWithSize(otherStack, Math.min(size, otherStack.getCount()));
|
||||||
this.removeTracker.add(removed);
|
this.removeTracker.add(removed);
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ public class ItemStackList implements IItemStackList {
|
|||||||
public ItemStack get(@Nonnull ItemStack stack, int flags) {
|
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
|
// 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())) {
|
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;
|
return otherStack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -369,7 +369,7 @@ public class GuiGrid extends GuiBase {
|
|||||||
if (grid.getType() != EnumGridType.FLUID && (held.isEmpty() || (!held.isEmpty() && clickedButton == 2))) {
|
if (grid.getType() != EnumGridType.FLUID && (held.isEmpty() || (!held.isEmpty() && clickedButton == 2))) {
|
||||||
ClientStackItem stack = (ClientStackItem) STACKS.get(slotNumber);
|
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));
|
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingStart(this, container.getPlayer(), stack));
|
||||||
} else {
|
} else {
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
@@ -17,12 +17,14 @@ public class ClientStackItem implements IClientStack {
|
|||||||
private int hash;
|
private int hash;
|
||||||
private ItemStack stack;
|
private ItemStack stack;
|
||||||
private boolean craftable;
|
private boolean craftable;
|
||||||
|
private boolean outputFromPattern;
|
||||||
|
|
||||||
public ClientStackItem(ByteBuf buf) {
|
public ClientStackItem(ByteBuf buf) {
|
||||||
stack = new ItemStack(Item.getItemById(buf.readInt()), buf.readInt(), buf.readInt());
|
stack = new ItemStack(Item.getItemById(buf.readInt()), buf.readInt(), buf.readInt());
|
||||||
stack.setTagCompound(ByteBufUtils.readTag(buf));
|
stack.setTagCompound(ByteBufUtils.readTag(buf));
|
||||||
hash = buf.readInt();
|
hash = buf.readInt();
|
||||||
craftable = buf.readBoolean();
|
craftable = buf.readBoolean();
|
||||||
|
setOutputFromPattern(buf.readBoolean());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getStack() {
|
public ItemStack getStack() {
|
||||||
@@ -33,6 +35,18 @@ public class ClientStackItem implements IClientStack {
|
|||||||
return craftable;
|
return craftable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isOutputFromPattern() {
|
||||||
|
return outputFromPattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutputFromPattern(boolean outputFromPattern) {
|
||||||
|
this.outputFromPattern = outputFromPattern;
|
||||||
|
|
||||||
|
if (outputFromPattern) {
|
||||||
|
stack.setCount(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHash() {
|
public int getHash() {
|
||||||
return hash;
|
return hash;
|
||||||
@@ -72,12 +86,12 @@ public class ClientStackItem implements IClientStack {
|
|||||||
private String getQuantityForDisplay(boolean advanced) {
|
private String getQuantityForDisplay(boolean advanced) {
|
||||||
int qty = stack.getCount();
|
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);
|
return String.valueOf(qty);
|
||||||
} else if (qty == 1) {
|
} else if (qty == 1) {
|
||||||
return null;
|
return null;
|
||||||
} else if (qty == 0) {
|
|
||||||
return I18n.format("gui.refinedstorage:grid.craft");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RSUtils.formatQuantity(qty);
|
return RSUtils.formatQuantity(qty);
|
||||||
|
@@ -35,7 +35,7 @@ public class MessageGridItemDelta implements IMessage, IMessageHandler<MessageGr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf) {
|
||||||
RSUtils.writeItemStack(buf, network, stack);
|
RSUtils.writeItemStack(buf, network, stack, false);
|
||||||
buf.writeInt(delta);
|
buf.writeInt(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,10 +45,15 @@ public class MessageGridItemDelta implements IMessage, IMessageHandler<MessageGr
|
|||||||
|
|
||||||
for (ClientStackItem stack : GuiGrid.ITEMS.get(item)) {
|
for (ClientStackItem stack : GuiGrid.ITEMS.get(item)) {
|
||||||
if (stack.equals(message.clientStack)) {
|
if (stack.equals(message.clientStack)) {
|
||||||
if (stack.getStack().getCount() + message.delta == 0 && !message.clientStack.isCraftable()) {
|
if (stack.getStack().getCount() + message.delta == 0) {
|
||||||
GuiGrid.ITEMS.remove(item, stack);
|
if (message.clientStack.isCraftable()) {
|
||||||
|
stack.setOutputFromPattern(true);
|
||||||
} else {
|
} else {
|
||||||
stack.getStack().grow(message.delta);
|
GuiGrid.ITEMS.remove(item, stack);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stack.getStack().grow(message.delta - (stack.isOutputFromPattern() ? 1 : 0));
|
||||||
|
stack.setOutputFromPattern(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiGrid.markForSorting();
|
GuiGrid.markForSorting();
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
package com.raoulvdberge.refinedstorage.network;
|
package com.raoulvdberge.refinedstorage.network;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
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.GuiGrid;
|
||||||
import com.raoulvdberge.refinedstorage.gui.grid.stack.ClientStackItem;
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.ClientStackItem;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
@@ -28,7 +30,7 @@ public class MessageGridItemUpdate implements IMessage, IMessageHandler<MessageG
|
|||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf) {
|
||||||
int items = buf.readInt();
|
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));
|
this.stacks.add(new ClientStackItem(buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +40,15 @@ public class MessageGridItemUpdate implements IMessage, IMessageHandler<MessageG
|
|||||||
buf.writeInt(network.getItemStorageCache().getList().getStacks().size());
|
buf.writeInt(network.getItemStorageCache().getList().getStacks().size());
|
||||||
|
|
||||||
for (ItemStack stack : network.getItemStorageCache().getList().getStacks()) {
|
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,8 +57,23 @@ public class MessageGridItemUpdate implements IMessage, IMessageHandler<MessageG
|
|||||||
GuiGrid.ITEMS.clear();
|
GuiGrid.ITEMS.clear();
|
||||||
|
|
||||||
for (ClientStackItem item : message.stacks) {
|
for (ClientStackItem item : message.stacks) {
|
||||||
|
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.ITEMS.put(item.getStack().getItem(), item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GuiGrid.markForSorting();
|
GuiGrid.markForSorting();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user