Fix not being able to start crafting in a few cases
This commit is contained in:
@@ -44,10 +44,10 @@ public interface IItemGridHandler {
|
|||||||
/**
|
/**
|
||||||
* Called when a player requests the crafting preview window to be opened.
|
* Called when a player requests the crafting preview window to be opened.
|
||||||
*
|
*
|
||||||
* @param stack the {@link ItemStack} to request a craft for
|
* @param hash the item stack hash
|
||||||
* @param quantity the amount of that item that we need a preview for
|
* @param quantity the amount of that item that we need a preview for
|
||||||
*/
|
*/
|
||||||
void onCraftingPreviewRequested(EntityPlayerMP player, ItemStack stack, int quantity);
|
void onCraftingPreviewRequested(EntityPlayerMP player, int hash, int quantity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player requested crafting for an item.
|
* Called when a player requested crafting for an item.
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.raoulvdberge.refinedstorage.apiimpl.network.grid;
|
|||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RS;
|
import com.raoulvdberge.refinedstorage.RS;
|
||||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||||
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
|
|
||||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
|
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.IItemGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.IItemGridHandler;
|
||||||
@@ -142,7 +141,9 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingPreviewRequested(EntityPlayerMP player, ItemStack stack, int quantity) {
|
public void onCraftingPreviewRequested(EntityPlayerMP player, int hash, int quantity) {
|
||||||
|
ItemStack stack = network.getItemStorageCache().getList().get(hash);
|
||||||
|
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
Thread calculationThread = new Thread(() -> {
|
Thread calculationThread = new Thread(() -> {
|
||||||
ICraftingTask task = new CraftingTask(network, stack, network.getPattern(stack), quantity);
|
ICraftingTask task = new CraftingTask(network, stack, network.getPattern(stack), quantity);
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ public class GuiCraftingStart extends GuiBase {
|
|||||||
Integer quantity = Ints.tryParse(amountField.getText());
|
Integer quantity = Ints.tryParse(amountField.getText());
|
||||||
|
|
||||||
if (quantity != null && quantity > 0) {
|
if (quantity != null && quantity > 0) {
|
||||||
RS.INSTANCE.network.sendToServer(new MessageGridCraftingPreview(stack.getStack(), quantity));
|
RS.INSTANCE.network.sendToServer(new MessageGridCraftingPreview(stack.getHash(), quantity));
|
||||||
|
|
||||||
startButton.enabled = false;
|
startButton.enabled = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,31 +4,29 @@ import com.raoulvdberge.refinedstorage.container.ContainerGrid;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
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.item.ItemStack;
|
|
||||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
|
||||||
public class MessageGridCraftingPreview extends MessageHandlerPlayerToServer<MessageGridCraftingPreview> implements IMessage {
|
public class MessageGridCraftingPreview extends MessageHandlerPlayerToServer<MessageGridCraftingPreview> implements IMessage {
|
||||||
private ItemStack stack;
|
private int hash;
|
||||||
private int quantity;
|
private int quantity;
|
||||||
|
|
||||||
public MessageGridCraftingPreview() {
|
public MessageGridCraftingPreview() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageGridCraftingPreview(ItemStack stack, int quantity) {
|
public MessageGridCraftingPreview(int hash, int quantity) {
|
||||||
this.stack = stack;
|
this.hash = hash;
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf) {
|
||||||
stack = ByteBufUtils.readItemStack(buf);
|
hash = buf.readInt();
|
||||||
quantity = buf.readInt();
|
quantity = buf.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf) {
|
||||||
ByteBufUtils.writeItemStack(buf, stack);
|
buf.writeInt(hash);
|
||||||
buf.writeInt(quantity);
|
buf.writeInt(quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +35,7 @@ public class MessageGridCraftingPreview extends MessageHandlerPlayerToServer<Mes
|
|||||||
Container container = player.openContainer;
|
Container container = player.openContainer;
|
||||||
|
|
||||||
if (container instanceof ContainerGrid) {
|
if (container instanceof ContainerGrid) {
|
||||||
((ContainerGrid) container).getGrid().getItemHandler().onCraftingPreviewRequested(player, message.stack, message.quantity);
|
((ContainerGrid) container).getGrid().getItemHandler().onCraftingPreviewRequested(player, message.hash, message.quantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -455,8 +455,6 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
|||||||
patterns.addAll(((ICraftingPatternContainer) node).getPatterns());
|
patterns.addAll(((ICraftingPatternContainer) node).getPatterns());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
itemStorage.invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
|
|||||||
|
|
||||||
private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
||||||
private boolean active;
|
private boolean active;
|
||||||
private boolean rebuildNeighbors;
|
|
||||||
protected boolean rebuildOnUpdateChange;
|
protected boolean rebuildOnUpdateChange;
|
||||||
|
|
||||||
protected INetworkMaster network;
|
protected INetworkMaster network;
|
||||||
@@ -49,7 +48,9 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
|
|||||||
public void update() {
|
public void update() {
|
||||||
if (!getWorld().isRemote) {
|
if (!getWorld().isRemote) {
|
||||||
boolean wasActive = active;
|
boolean wasActive = active;
|
||||||
|
|
||||||
active = hasNetwork() && canUpdate();
|
active = hasNetwork() && canUpdate();
|
||||||
|
|
||||||
if (active != wasActive) {
|
if (active != wasActive) {
|
||||||
if (hasConnectivityState()) {
|
if (hasConnectivityState()) {
|
||||||
updateBlock();
|
updateBlock();
|
||||||
|
|||||||
Reference in New Issue
Block a user