Fixed crash log when opening Pattern Grid GUI. Fixes #1896

This commit is contained in:
raoulvdberge
2018-07-23 15:40:03 +02:00
parent c0ed630ac4
commit ebcfd05ca9
8 changed files with 96 additions and 66 deletions

View File

@@ -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

View File

@@ -90,7 +90,7 @@ 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()) {
// Processing patterns
int ox = 8;
int x = ox;
int y = headerAndSlots + 4;
@@ -100,7 +100,7 @@ public class ContainerGrid extends ContainerBase {
if (amount > 0 && amount <= Fluid.BUCKET_VOLUME && slot < ((NetworkNodeGrid) grid).getMatrixProcessingFluids().getSlots()) {
((NetworkNodeGrid) grid).getMatrixProcessingFluids().getStackInSlot(slot).setCount(amount);
}
}, Fluid.BUCKET_VOLUME));
}, Fluid.BUCKET_VOLUME, () -> ((NetworkNodeGrid) grid).isProcessingPattern()));
x += 18;
@@ -115,12 +115,13 @@ public class ContainerGrid extends ContainerBase {
}
}
}
} else {
int x = 26;
int y = headerAndSlots + 4;
// Regular patterns
x = 26;
y = headerAndSlots + 4;
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotFilterLegacy(grid.getCraftingMatrix(), i, x, y));
addSlotToContainer(new SlotFilterLegacy(grid.getCraftingMatrix(), i, x, y, () -> !((NetworkNodeGrid) grid).isProcessingPattern()));
x += 18;
@@ -130,8 +131,7 @@ public class ContainerGrid extends ContainerBase {
}
}
addSlotToContainer(patternResultSlot = new SlotDisabled(grid.getCraftingResult(), 0, 134, headerAndSlots + 22));
}
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) {

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();

View File

@@ -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,11 +36,14 @@ 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);
}
}
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)) {
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);
@@ -49,5 +55,4 @@ public class MessageGridClear extends MessageHandlerPlayerToServer<MessageGridCl
((NetworkNodeGrid) grid).clearMatrix();
}
}
}
}

View File

@@ -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));