Fixed crash log when opening Pattern Grid GUI. Fixes #1896
This commit is contained in:
@@ -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
|
||||
|
@@ -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) {
|
||||
|
@@ -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<Boolean> 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<Boolean> 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();
|
||||
}
|
||||
}
|
||||
|
@@ -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<Boolean> 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<Boolean> 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();
|
||||
}
|
||||
}
|
||||
|
@@ -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<Boolean> 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<Boolean> 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();
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -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<MessageGridClear> implements IMessage {
|
||||
public MessageGridClear() {
|
||||
}
|
||||
@@ -33,21 +36,23 @@ public class MessageGridClear extends MessageHandlerPlayerToServer<MessageGridCl
|
||||
Container container = player.openContainer;
|
||||
|
||||
if (container instanceof ContainerGrid && ((ContainerGrid) container).getGrid() instanceof IGridNetworkAware) {
|
||||
IGridNetworkAware grid = (IGridNetworkAware) ((ContainerGrid) container).getGrid();
|
||||
clear((IGridNetworkAware) ((ContainerGrid) container).getGrid(), player);
|
||||
}
|
||||
}
|
||||
|
||||
InventoryCrafting matrix = grid.getCraftingMatrix();
|
||||
public static void clear(IGridNetworkAware grid, @Nullable EntityPlayer player) {
|
||||
InventoryCrafting matrix = grid.getCraftingMatrix();
|
||||
|
||||
if (grid.getGridType() == GridType.CRAFTING && grid.getNetwork() != null && grid.getNetwork().getSecurityManager().hasPermission(Permission.INSERT, player)) {
|
||||
for (int i = 0; i < matrix.getSizeInventory(); ++i) {
|
||||
ItemStack slot = matrix.getStackInSlot(i);
|
||||
if (grid.getGridType() == GridType.CRAFTING && grid.getNetwork() != null && (player == null || grid.getNetwork().getSecurityManager().hasPermission(Permission.INSERT, player))) {
|
||||
for (int i = 0; i < matrix.getSizeInventory(); ++i) {
|
||||
ItemStack slot = matrix.getStackInSlot(i);
|
||||
|
||||
if (!slot.isEmpty()) {
|
||||
matrix.setInventorySlotContents(i, StackUtils.nullToEmpty(grid.getNetwork().insertItem(slot, slot.getCount(), Action.PERFORM)));
|
||||
}
|
||||
if (!slot.isEmpty()) {
|
||||
matrix.setInventorySlotContents(i, StackUtils.nullToEmpty(grid.getNetwork().insertItem(slot, slot.getCount(), Action.PERFORM)));
|
||||
}
|
||||
} else if (grid.getGridType() == GridType.PATTERN) {
|
||||
((NetworkNodeGrid) grid).clearMatrix();
|
||||
}
|
||||
} else if (grid.getGridType() == GridType.PATTERN) {
|
||||
((NetworkNodeGrid) grid).clearMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ package com.raoulvdberge.refinedstorage.tile.grid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid;
|
||||
import com.raoulvdberge.refinedstorage.container.ContainerGrid;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
|
||||
import com.raoulvdberge.refinedstorage.gui.grid.GuiGrid;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileNode;
|
||||
@@ -72,16 +71,6 @@ public class TileGrid extends TileNode<NetworkNodeGrid> {
|
||||
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<Integer, TileGrid> PROCESSING_TYPE = IType.createParameter((initial, p) -> GuiBase.executeLater(GuiGrid.class, GuiBase::initGui));
|
||||
|
||||
|
Reference in New Issue
Block a user