diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ff666a0..9b9e446e8 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - You can now keep fluids in stock by attaching a External Storage in fluid mode to a Fluid Interface with a Crafting Upgrade (raoulvdberge) - You can now specify the amount to export in the Fluid Interface (raoulvdberge) - Made the Crafting Preview window bigger (raoulvdberge) +- Fixed crash log when opening Pattern Grid GUI (raoulvdberge) - Updated Russian translation (kellixon) ### 1.6 diff --git a/src/main/java/com/raoulvdberge/refinedstorage/container/ContainerGrid.java b/src/main/java/com/raoulvdberge/refinedstorage/container/ContainerGrid.java index 496eb28c1..210548e2d 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/container/ContainerGrid.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/container/ContainerGrid.java @@ -90,48 +90,48 @@ public class ContainerGrid extends ContainerBase { addSlotToContainer(craftingResultSlot = new SlotGridCraftingResult(this, getPlayer(), grid, 0, 130 + 4, headerAndSlots + 22)); } else if (grid.getGridType() == GridType.PATTERN) { - if (((NetworkNodeGrid) grid).isProcessingPattern()) { - int ox = 8; - int x = ox; - int y = headerAndSlots + 4; + // Processing patterns + int ox = 8; + int x = ox; + int y = headerAndSlots + 4; - for (int i = 0; i < 9 * 2; ++i) { - addSlotToContainer(new SlotFilterItemOrFluid((NetworkNodeGrid) grid, i, x, y, SlotFilter.FILTER_ALLOW_SIZE, (slot, amount) -> { - if (amount > 0 && amount <= Fluid.BUCKET_VOLUME && slot < ((NetworkNodeGrid) grid).getMatrixProcessingFluids().getSlots()) { - ((NetworkNodeGrid) grid).getMatrixProcessingFluids().getStackInSlot(slot).setCount(amount); - } - }, Fluid.BUCKET_VOLUME)); - - x += 18; - - if ((i + 1) % 3 == 0) { - if (i == 8) { - ox = 98; - x = ox; - y = headerAndSlots + 4; - } else { - x = ox; - y += 18; - } + for (int i = 0; i < 9 * 2; ++i) { + addSlotToContainer(new SlotFilterItemOrFluid((NetworkNodeGrid) grid, i, x, y, SlotFilter.FILTER_ALLOW_SIZE, (slot, amount) -> { + if (amount > 0 && amount <= Fluid.BUCKET_VOLUME && slot < ((NetworkNodeGrid) grid).getMatrixProcessingFluids().getSlots()) { + ((NetworkNodeGrid) grid).getMatrixProcessingFluids().getStackInSlot(slot).setCount(amount); } - } - } else { - int x = 26; - int y = headerAndSlots + 4; + }, Fluid.BUCKET_VOLUME, () -> ((NetworkNodeGrid) grid).isProcessingPattern())); - for (int i = 0; i < 9; ++i) { - addSlotToContainer(new SlotFilterLegacy(grid.getCraftingMatrix(), i, x, y)); + x += 18; - x += 18; - - if ((i + 1) % 3 == 0) { + if ((i + 1) % 3 == 0) { + if (i == 8) { + ox = 98; + x = ox; + y = headerAndSlots + 4; + } else { + x = ox; y += 18; - x = 26; } } - - addSlotToContainer(patternResultSlot = new SlotDisabled(grid.getCraftingResult(), 0, 134, headerAndSlots + 22)); } + + // Regular patterns + x = 26; + y = headerAndSlots + 4; + + for (int i = 0; i < 9; ++i) { + addSlotToContainer(new SlotFilterLegacy(grid.getCraftingMatrix(), i, x, y, () -> !((NetworkNodeGrid) grid).isProcessingPattern())); + + x += 18; + + if ((i + 1) % 3 == 0) { + y += 18; + x = 26; + } + } + + addSlotToContainer(patternResultSlot = new SlotDisabled(grid.getCraftingResult(), 0, 134, headerAndSlots + 22, () -> !((NetworkNodeGrid) grid).isProcessingPattern())); } } @@ -155,16 +155,6 @@ public class ContainerGrid extends ContainerBase { } } - public void sendAllSlots() { - for (int i = 0; i < inventorySlots.size(); ++i) { - Slot slot = inventorySlots.get(i); - - for (IContainerListener listener : listeners) { - listener.sendSlotContents(this, i, slot.getStack()); - } - } - } - @Override public void detectAndSendChanges() { if (!getPlayer().world.isRemote) { diff --git a/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotDisabled.java b/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotDisabled.java index 7d7dfbd52..85a3149e6 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotDisabled.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotDisabled.java @@ -5,14 +5,28 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import javax.annotation.Nonnull; +import java.util.function.Supplier; public class SlotDisabled extends Slot { + private Supplier enableHandler = () -> true; + public SlotDisabled(IInventory inventory, int id, int x, int y) { super(inventory, id, x, y); } + public SlotDisabled(IInventory inventory, int id, int x, int y, Supplier enableHandler) { + this(inventory, id, x, y); + + this.enableHandler = enableHandler; + } + @Override public boolean isItemValid(@Nonnull ItemStack stack) { return false; } + + @Override + public boolean isEnabled() { + return enableHandler.get(); + } } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotFilterItemOrFluid.java b/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotFilterItemOrFluid.java index e662b3949..d03377052 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotFilterItemOrFluid.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotFilterItemOrFluid.java @@ -7,6 +7,7 @@ import net.minecraftforge.items.IItemHandler; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.function.Supplier; public class SlotFilterItemOrFluid extends SlotFilter { public interface IFluidAmountChangeListener { @@ -19,6 +20,8 @@ public class SlotFilterItemOrFluid extends SlotFilter { private IFluidAmountChangeListener listener; private int maxFluidAmount; + private Supplier enableHandler = () -> true; + public SlotFilterItemOrFluid(IType type, int id, int x, int y, int flags, @Nullable IFluidAmountChangeListener listener, int maxFluidAmount) { super(null, id, x, y, flags); @@ -27,6 +30,12 @@ public class SlotFilterItemOrFluid extends SlotFilter { this.maxFluidAmount = maxFluidAmount; } + public SlotFilterItemOrFluid(IType type, int id, int x, int y, int flags, @Nullable IFluidAmountChangeListener listener, int maxFluidAmount, Supplier enableHandler) { + this(type, id, x, y, flags, listener, maxFluidAmount); + + this.enableHandler = enableHandler; + } + public SlotFilterItemOrFluid(IType type, int id, int x, int y) { this(type, id, x, y, 0, null, 0); } @@ -72,4 +81,9 @@ public class SlotFilterItemOrFluid extends SlotFilter { public int getMaxFluidAmount() { return maxFluidAmount; } + + @Override + public boolean isEnabled() { + return enableHandler.get(); + } } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotFilterLegacy.java b/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotFilterLegacy.java index de39a62a7..5687f2a06 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotFilterLegacy.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/container/slot/SlotFilterLegacy.java @@ -7,12 +7,21 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import javax.annotation.Nonnull; +import java.util.function.Supplier; public class SlotFilterLegacy extends Slot { + private Supplier enableHandler = () -> true; + public SlotFilterLegacy(IInventory inventory, int id, int x, int y) { super(inventory, id, x, y); } + public SlotFilterLegacy(IInventory inventory, int id, int x, int y, Supplier enableHandler) { + this(inventory, id, x, y); + + this.enableHandler = enableHandler; + } + @Override public boolean canTakeStack(EntityPlayer player) { return false; @@ -31,4 +40,9 @@ public class SlotFilterLegacy extends Slot { super.putStack(stack); } + + @Override + public boolean isEnabled() { + return enableHandler.get(); + } } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/GuiGrid.java b/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/GuiGrid.java index db679ff6b..9d09f63fe 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/GuiGrid.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/gui/grid/GuiGrid.java @@ -5,6 +5,7 @@ import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.RSKeyBindings; import com.raoulvdberge.refinedstorage.api.network.grid.GridType; import com.raoulvdberge.refinedstorage.api.network.grid.IGrid; +import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware; import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler; import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid; import com.raoulvdberge.refinedstorage.container.ContainerGrid; @@ -443,8 +444,10 @@ public class GuiGrid extends GuiBase implements IResizableDisplay { RS.INSTANCE.network.sendToServer(new MessageGridPatternCreate(gridPos.getX(), gridPos.getY(), gridPos.getZ())); } else if (grid.isActive()) { - if (clickedClear) { + if (clickedClear && grid instanceof IGridNetworkAware) { RS.INSTANCE.network.sendToServer(new MessageGridClear()); + + MessageGridClear.clear((IGridNetworkAware) grid, null); // Clear clientside } ItemStack held = ((ContainerGrid) this.inventorySlots).getPlayer().inventory.getItemStack(); diff --git a/src/main/java/com/raoulvdberge/refinedstorage/network/MessageGridClear.java b/src/main/java/com/raoulvdberge/refinedstorage/network/MessageGridClear.java index 6a22953d8..2c05c0d2f 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/network/MessageGridClear.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/network/MessageGridClear.java @@ -8,12 +8,15 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid; import com.raoulvdberge.refinedstorage.container.ContainerGrid; import com.raoulvdberge.refinedstorage.util.StackUtils; import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import javax.annotation.Nullable; + public class MessageGridClear extends MessageHandlerPlayerToServer implements IMessage { public MessageGridClear() { } @@ -33,21 +36,23 @@ public class MessageGridClear extends MessageHandlerPlayerToServer { t.getNode().setProcessingPattern(v); t.getNode().clearMatrix(); t.getNode().markDirty(); - - t.getWorld().getMinecraftServer() - .getPlayerList() - .getPlayers() - .stream() - .filter(player -> player.openContainer instanceof ContainerGrid && ((ContainerGrid) player.openContainer).getTile() != null && ((ContainerGrid) player.openContainer).getTile().getPos().equals(t.getPos())) - .forEach(player -> { - ((ContainerGrid) player.openContainer).initSlots(); - ((ContainerGrid) player.openContainer).sendAllSlots(); - }); }, (initial, p) -> GuiBase.executeLater(GuiGrid.class, GuiBase::initGui)); public static final TileDataParameter PROCESSING_TYPE = IType.createParameter((initial, p) -> GuiBase.executeLater(GuiGrid.class, GuiBase::initGui));