Fix subtle bugs, not finished yet in a long shot
This commit is contained in:
@@ -35,7 +35,7 @@ public final class RS {
|
||||
public final CreativeTabs tab = new CreativeTabs(ID) {
|
||||
@Override
|
||||
public ItemStack getTabIconItem() {
|
||||
return getIconItemStack();
|
||||
return new ItemStack(RSItems.STORAGE_HOUSING);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
@@ -84,6 +85,10 @@ public final class RSUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getStack(@Nullable ItemStack stack) {
|
||||
return stack == null ? ItemStack.EMPTY : stack;
|
||||
}
|
||||
|
||||
public static NonNullList<ItemStack> toNonNullList(List<ItemStack> list) {
|
||||
NonNullList<ItemStack> other = NonNullList.create();
|
||||
|
||||
@@ -100,7 +105,7 @@ public final class RSUtils {
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < handler.getSlots(); i++) {
|
||||
if (handler.getStackInSlot(i) != null) {
|
||||
if (!handler.getStackInSlot(i).isEmpty()) {
|
||||
NBTTagCompound stackTag = new NBTTagCompound();
|
||||
|
||||
stackTag.setInteger(NBT_SLOT, i);
|
||||
@@ -134,7 +139,7 @@ public final class RSUtils {
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
if (inventory.getStackInSlot(i) != null) {
|
||||
if (!inventory.getStackInSlot(i).isEmpty()) {
|
||||
NBTTagCompound stackTag = new NBTTagCompound();
|
||||
|
||||
stackTag.setInteger(NBT_SLOT, i);
|
||||
|
||||
@@ -42,8 +42,12 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
ItemStack slot = ItemPattern.getSlot(stack, i);
|
||||
|
||||
inputs.add(slot);
|
||||
inv.setInventorySlotContents(i, slot);
|
||||
|
||||
if (slot != null) {
|
||||
inv.setInventorySlotContents(i, slot);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ItemPattern.isProcessing(stack)) {
|
||||
@@ -88,7 +92,7 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
List<ItemStack> cleaned = new LinkedList<>();
|
||||
for (ItemStack in : (List<ItemStack>) input) {
|
||||
ItemStack stripped = in.copy();
|
||||
if (mekanism && stripped.hasTagCompound()){
|
||||
if (mekanism && stripped.hasTagCompound()) {
|
||||
stripped.getTagCompound().removeTag("mekData");
|
||||
}
|
||||
if (stripped.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
@@ -125,17 +129,17 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
if (ids == null || ids.length == 0) {
|
||||
oreInputs.add(Collections.singletonList(input));
|
||||
} else {
|
||||
oreInputs.add(
|
||||
Arrays.stream(ids)
|
||||
.mapToObj(OreDictionary::getOreName)
|
||||
.map(OreDictionary::getOres)
|
||||
.flatMap(List::stream)
|
||||
.map(ItemStack::copy)
|
||||
.map(s -> {
|
||||
s.setCount(input.getCount());
|
||||
return s;
|
||||
})
|
||||
.collect(Collectors.toList()));
|
||||
oreInputs.add(Arrays.stream(ids)
|
||||
.mapToObj(OreDictionary::getOreName)
|
||||
.map(OreDictionary::getOres)
|
||||
.flatMap(List::stream)
|
||||
.map(ItemStack::copy)
|
||||
.map(s -> {
|
||||
s.setCount(input.getCount());
|
||||
return s;
|
||||
})
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IItemGridHandler;
|
||||
@@ -40,10 +41,10 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
ItemStack held = player.inventory.getItemStack();
|
||||
|
||||
if (single) {
|
||||
if (held != null && (!API.instance().getComparer().isEqualNoQuantity(item, held) || held.getCount() + 1 > held.getMaxStackSize())) {
|
||||
if (!held.isEmpty() && (!API.instance().getComparer().isEqualNoQuantity(item, held) || held.getCount() + 1 > held.getMaxStackSize())) {
|
||||
return;
|
||||
}
|
||||
} else if (player.inventory.getItemStack() != null) {
|
||||
} else if (!player.inventory.getItemStack().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) {
|
||||
IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
|
||||
|
||||
if (ItemHandlerHelper.insertItem(playerInventory, took, true) == null) {
|
||||
if (ItemHandlerHelper.insertItem(playerInventory, took, true).isEmpty()) {
|
||||
took = network.extractItem(item, size, false);
|
||||
|
||||
ItemHandlerHelper.insertItem(playerInventory, took, false);
|
||||
@@ -77,7 +78,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
} else {
|
||||
took = network.extractItem(item, size, false);
|
||||
|
||||
if (single && held != null) {
|
||||
if (single && !held.isEmpty()) {
|
||||
held.grow(1);
|
||||
} else {
|
||||
player.inventory.setItemStack(took);
|
||||
@@ -109,7 +110,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
|
||||
@Override
|
||||
public void onInsertHeldItem(EntityPlayerMP player, boolean single) {
|
||||
if (player.inventory.getItemStack() == null) {
|
||||
if (player.inventory.getItemStack().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -123,11 +124,11 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
stack.shrink(size);
|
||||
|
||||
if (stack.getCount() == 0) {
|
||||
player.inventory.setItemStack(null);
|
||||
player.inventory.setItemStack(ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.inventory.setItemStack(network.insertItem(stack, size, false));
|
||||
player.inventory.setItemStack(RSUtils.getStack(network.insertItem(stack, size, false)));
|
||||
}
|
||||
|
||||
player.updateHeldItem();
|
||||
@@ -168,6 +169,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
ICraftingTask task = new CraftingTask(network, stack, network.getPattern(stack), quantity);
|
||||
|
||||
task.calculate();
|
||||
|
||||
task.getMissing().clear();
|
||||
|
||||
network.addCraftingTask(task);
|
||||
|
||||
@@ -40,15 +40,13 @@ public class ItemStackList implements IItemStackList {
|
||||
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)) {
|
||||
otherStack.shrink(size);
|
||||
|
||||
boolean success = otherStack.getCount() >= 0;
|
||||
|
||||
if (otherStack.getCount() <= 0 && removeIfReachedZero) {
|
||||
if (otherStack.getCount() - size <= 0 && removeIfReachedZero) {
|
||||
stacks.remove(otherStack.getItem(), otherStack);
|
||||
} else {
|
||||
otherStack.shrink(size);
|
||||
}
|
||||
|
||||
return success;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ public abstract class ContainerBase extends Container {
|
||||
if (slot instanceof SlotSpecimen) {
|
||||
if (((SlotSpecimen) slot).isWithSize()) {
|
||||
if (clickType == ClickType.QUICK_MOVE) {
|
||||
slot.putStack(null);
|
||||
} else if (player.inventory.getItemStack() != null) {
|
||||
slot.putStack(ItemStack.EMPTY);
|
||||
} else if (!player.inventory.getItemStack().isEmpty()) {
|
||||
int amount = player.inventory.getItemStack().getCount();
|
||||
|
||||
slot.putStack(ItemHandlerHelper.copyStackWithSize(player.inventory.getItemStack(), amount));
|
||||
@@ -76,16 +76,16 @@ public abstract class ContainerBase extends Container {
|
||||
|
||||
slot.getStack().setCount(amount);
|
||||
}
|
||||
} else if (player.inventory.getItemStack() == null) {
|
||||
slot.putStack(null);
|
||||
} else if (player.inventory.getItemStack().isEmpty()) {
|
||||
slot.putStack(ItemStack.EMPTY);
|
||||
} else if (slot.isItemValid(player.inventory.getItemStack())) {
|
||||
slot.putStack(player.inventory.getItemStack().copy());
|
||||
}
|
||||
|
||||
return player.inventory.getItemStack();
|
||||
} else if (slot instanceof SlotSpecimenLegacy) {
|
||||
if (player.inventory.getItemStack() == null) {
|
||||
slot.putStack(null);
|
||||
if (player.inventory.getItemStack().isEmpty()) {
|
||||
slot.putStack(ItemStack.EMPTY);
|
||||
} else if (slot.isItemValid(player.inventory.getItemStack())) {
|
||||
slot.putStack(player.inventory.getItemStack().copy());
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public abstract class ContainerBase extends Container {
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
|
||||
return null;
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
protected ItemStack mergeItemStackToSpecimen(ItemStack stack, int begin, int end) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.container;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.block.EnumGridType;
|
||||
import com.raoulvdberge.refinedstorage.container.slot.*;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileBase;
|
||||
@@ -109,9 +110,9 @@ public class ContainerGrid extends ContainerBase {
|
||||
((TileGrid) grid).onCraftedShift(this, player);
|
||||
} else if (slot != patternResultSlot && !(slot instanceof SlotSpecimenLegacy)) {
|
||||
if (grid.getType() != EnumGridType.FLUID && grid.getItemHandler() != null) {
|
||||
slot.putStack(grid.getItemHandler().onInsert((EntityPlayerMP) player, slot.getStack()));
|
||||
slot.putStack(RSUtils.getStack(grid.getItemHandler().onInsert((EntityPlayerMP) player, slot.getStack())));
|
||||
} else if (grid.getType() == EnumGridType.FLUID && grid.getFluidHandler() != null) {
|
||||
slot.putStack(grid.getFluidHandler().onInsert(slot.getStack()));
|
||||
slot.putStack(RSUtils.getStack(grid.getFluidHandler().onInsert(slot.getStack())));
|
||||
}
|
||||
|
||||
detectAndSendChanges();
|
||||
@@ -119,6 +120,6 @@ public class ContainerGrid extends ContainerBase {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,12 +361,12 @@ public class GuiGrid extends GuiBase {
|
||||
|
||||
ItemStack held = container.getPlayer().inventory.getItemStack();
|
||||
|
||||
if (isOverSlotArea(mouseX - guiLeft, mouseY - guiTop) && held != null && (clickedButton == 0 || clickedButton == 1)) {
|
||||
if (isOverSlotArea(mouseX - guiLeft, mouseY - guiTop) && !held.isEmpty() && (clickedButton == 0 || clickedButton == 1)) {
|
||||
RS.INSTANCE.network.sendToServer(grid.getType() == EnumGridType.FLUID ? new MessageGridFluidInsertHeld() : new MessageGridItemInsertHeld(clickedButton == 1));
|
||||
}
|
||||
|
||||
if (isOverSlotWithItem()) {
|
||||
if (grid.getType() != EnumGridType.FLUID && (held == null || (held != null && clickedButton == 2))) {
|
||||
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()))) {
|
||||
@@ -388,7 +388,7 @@ public class GuiGrid extends GuiBase {
|
||||
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridItemPull(stack.getHash(), flags));
|
||||
}
|
||||
} else if (grid.getType() == EnumGridType.FLUID && held == null) {
|
||||
} else if (grid.getType() == EnumGridType.FLUID && held.isEmpty()) {
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridFluidPull(STACKS.get(slotNumber).getHash(), GuiScreen.isShiftKeyDown()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ItemHandlerFluid extends ItemHandlerBasic {
|
||||
|
||||
ItemStack stack = getStackInSlot(slot);
|
||||
|
||||
if (stack == null) {
|
||||
if (stack.isEmpty()) {
|
||||
fluids[slot] = null;
|
||||
} else {
|
||||
fluids[slot] = RSUtils.getFluidFromStack(ItemHandlerHelper.copyStackWithSize(stack, 1), true);
|
||||
|
||||
@@ -31,8 +31,6 @@ public class MessageGridItemDelta implements IMessage, IMessageHandler<MessageGr
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
clientStack = new ClientStackItem(buf);
|
||||
delta = buf.readInt();
|
||||
|
||||
clientStack.getStack().setCount(delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,6 +57,8 @@ public class MessageGridItemDelta implements IMessage, IMessageHandler<MessageGr
|
||||
}
|
||||
}
|
||||
|
||||
message.clientStack.getStack().setCount(message.delta);
|
||||
|
||||
GuiGrid.ITEMS.put(item, message.clientStack);
|
||||
GuiGrid.markForSorting();
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public interface IFilterable {
|
||||
for (int i = 0; i < filters.getSlots(); ++i) {
|
||||
ItemStack slot = filters.getStackInSlot(i);
|
||||
|
||||
if (slot != null) {
|
||||
if (!slot.isEmpty()) {
|
||||
slots++;
|
||||
|
||||
if (API.instance().getComparer().isEqual(slot, stack, compare)) {
|
||||
@@ -52,7 +52,7 @@ public interface IFilterable {
|
||||
for (int i = 0; i < filters.getSlots(); ++i) {
|
||||
ItemStack slot = filters.getStackInSlot(i);
|
||||
|
||||
if (slot != null && API.instance().getComparer().isEqual(slot, stack, compare)) {
|
||||
if (!slot.isEmpty() && API.instance().getComparer().isEqual(slot, stack, compare)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user