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 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) - You can now specify the amount to export in the Fluid Interface (raoulvdberge)
- Made the Crafting Preview window bigger (raoulvdberge) - Made the Crafting Preview window bigger (raoulvdberge)
- Fixed crash log when opening Pattern Grid GUI (raoulvdberge)
- Updated Russian translation (kellixon) - Updated Russian translation (kellixon)
### 1.6 ### 1.6

View File

@@ -90,48 +90,48 @@ public class ContainerGrid extends ContainerBase {
addSlotToContainer(craftingResultSlot = new SlotGridCraftingResult(this, getPlayer(), grid, 0, 130 + 4, headerAndSlots + 22)); addSlotToContainer(craftingResultSlot = new SlotGridCraftingResult(this, getPlayer(), grid, 0, 130 + 4, headerAndSlots + 22));
} else if (grid.getGridType() == GridType.PATTERN) { } else if (grid.getGridType() == GridType.PATTERN) {
if (((NetworkNodeGrid) grid).isProcessingPattern()) { // Processing patterns
int ox = 8; int ox = 8;
int x = ox; int x = ox;
int y = headerAndSlots + 4; int y = headerAndSlots + 4;
for (int i = 0; i < 9 * 2; ++i) { for (int i = 0; i < 9 * 2; ++i) {
addSlotToContainer(new SlotFilterItemOrFluid((NetworkNodeGrid) grid, i, x, y, SlotFilter.FILTER_ALLOW_SIZE, (slot, amount) -> { 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()) { if (amount > 0 && amount <= Fluid.BUCKET_VOLUME && slot < ((NetworkNodeGrid) grid).getMatrixProcessingFluids().getSlots()) {
((NetworkNodeGrid) grid).getMatrixProcessingFluids().getStackInSlot(slot).setCount(amount); ((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;
}
} }
} }, Fluid.BUCKET_VOLUME, () -> ((NetworkNodeGrid) grid).isProcessingPattern()));
} else {
int x = 26;
int y = headerAndSlots + 4;
for (int i = 0; i < 9; ++i) { x += 18;
addSlotToContainer(new SlotFilterLegacy(grid.getCraftingMatrix(), i, x, y));
x += 18; if ((i + 1) % 3 == 0) {
if (i == 8) {
if ((i + 1) % 3 == 0) { ox = 98;
x = ox;
y = headerAndSlots + 4;
} else {
x = ox;
y += 18; 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 @Override
public void detectAndSendChanges() { public void detectAndSendChanges() {
if (!getPlayer().world.isRemote) { if (!getPlayer().world.isRemote) {

View File

@@ -5,14 +5,28 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.function.Supplier;
public class SlotDisabled extends Slot { public class SlotDisabled extends Slot {
private Supplier<Boolean> enableHandler = () -> true;
public SlotDisabled(IInventory inventory, int id, int x, int y) { public SlotDisabled(IInventory inventory, int id, int x, int y) {
super(inventory, id, x, 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 @Override
public boolean isItemValid(@Nonnull ItemStack stack) { public boolean isItemValid(@Nonnull ItemStack stack) {
return false; 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.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.function.Supplier;
public class SlotFilterItemOrFluid extends SlotFilter { public class SlotFilterItemOrFluid extends SlotFilter {
public interface IFluidAmountChangeListener { public interface IFluidAmountChangeListener {
@@ -19,6 +20,8 @@ public class SlotFilterItemOrFluid extends SlotFilter {
private IFluidAmountChangeListener listener; private IFluidAmountChangeListener listener;
private int maxFluidAmount; 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) { public SlotFilterItemOrFluid(IType type, int id, int x, int y, int flags, @Nullable IFluidAmountChangeListener listener, int maxFluidAmount) {
super(null, id, x, y, flags); super(null, id, x, y, flags);
@@ -27,6 +30,12 @@ public class SlotFilterItemOrFluid extends SlotFilter {
this.maxFluidAmount = maxFluidAmount; 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) { public SlotFilterItemOrFluid(IType type, int id, int x, int y) {
this(type, id, x, y, 0, null, 0); this(type, id, x, y, 0, null, 0);
} }
@@ -72,4 +81,9 @@ public class SlotFilterItemOrFluid extends SlotFilter {
public int getMaxFluidAmount() { public int getMaxFluidAmount() {
return maxFluidAmount; 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 net.minecraft.item.ItemStack;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.function.Supplier;
public class SlotFilterLegacy extends Slot { public class SlotFilterLegacy extends Slot {
private Supplier<Boolean> enableHandler = () -> true;
public SlotFilterLegacy(IInventory inventory, int id, int x, int y) { public SlotFilterLegacy(IInventory inventory, int id, int x, int y) {
super(inventory, id, x, 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 @Override
public boolean canTakeStack(EntityPlayer player) { public boolean canTakeStack(EntityPlayer player) {
return false; return false;
@@ -31,4 +40,9 @@ public class SlotFilterLegacy extends Slot {
super.putStack(stack); 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.RSKeyBindings;
import com.raoulvdberge.refinedstorage.api.network.grid.GridType; import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid; 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.api.network.grid.handler.IItemGridHandler;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid; import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid;
import com.raoulvdberge.refinedstorage.container.ContainerGrid; 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())); RS.INSTANCE.network.sendToServer(new MessageGridPatternCreate(gridPos.getX(), gridPos.getY(), gridPos.getZ()));
} else if (grid.isActive()) { } else if (grid.isActive()) {
if (clickedClear) { if (clickedClear && grid instanceof IGridNetworkAware) {
RS.INSTANCE.network.sendToServer(new MessageGridClear()); RS.INSTANCE.network.sendToServer(new MessageGridClear());
MessageGridClear.clear((IGridNetworkAware) grid, null); // Clear clientside
} }
ItemStack held = ((ContainerGrid) this.inventorySlots).getPlayer().inventory.getItemStack(); 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.container.ContainerGrid;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import javax.annotation.Nullable;
public class MessageGridClear extends MessageHandlerPlayerToServer<MessageGridClear> implements IMessage { public class MessageGridClear extends MessageHandlerPlayerToServer<MessageGridClear> implements IMessage {
public MessageGridClear() { public MessageGridClear() {
} }
@@ -33,21 +36,23 @@ public class MessageGridClear extends MessageHandlerPlayerToServer<MessageGridCl
Container container = player.openContainer; Container container = player.openContainer;
if (container instanceof ContainerGrid && ((ContainerGrid) container).getGrid() instanceof IGridNetworkAware) { 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)) { 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) { for (int i = 0; i < matrix.getSizeInventory(); ++i) {
ItemStack slot = matrix.getStackInSlot(i); ItemStack slot = matrix.getStackInSlot(i);
if (!slot.isEmpty()) { if (!slot.isEmpty()) {
matrix.setInventorySlotContents(i, StackUtils.nullToEmpty(grid.getNetwork().insertItem(slot, slot.getCount(), Action.PERFORM))); 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();
} }
} }
} }

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.GridType;
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid; import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid; 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.GuiBase;
import com.raoulvdberge.refinedstorage.gui.grid.GuiGrid; import com.raoulvdberge.refinedstorage.gui.grid.GuiGrid;
import com.raoulvdberge.refinedstorage.tile.TileNode; import com.raoulvdberge.refinedstorage.tile.TileNode;
@@ -72,16 +71,6 @@ public class TileGrid extends TileNode<NetworkNodeGrid> {
t.getNode().setProcessingPattern(v); t.getNode().setProcessingPattern(v);
t.getNode().clearMatrix(); t.getNode().clearMatrix();
t.getNode().markDirty(); 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)); }, (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)); public static final TileDataParameter<Integer, TileGrid> PROCESSING_TYPE = IType.createParameter((initial, p) -> GuiBase.executeLater(GuiGrid.class, GuiBase::initGui));