Fixed not being able to craft Immersive Engineering Revolver, fixes #1465

This commit is contained in:
raoulvdberge
2017-10-04 01:13:08 +02:00
parent d1c275d35e
commit 80b980dd45
8 changed files with 41 additions and 26 deletions

View File

@@ -7,6 +7,7 @@
- Fixed device names overflowing Controller GUI (raoulvdberge) - Fixed device names overflowing Controller GUI (raoulvdberge)
- Fixed high CPU load when Refined Storage GUIs are open (raoulvdberge) - Fixed high CPU load when Refined Storage GUIs are open (raoulvdberge)
- Fixed not being able to extract Mekanism tanks and bins from the Grid (raoulvdberge) - Fixed not being able to extract Mekanism tanks and bins from the Grid (raoulvdberge)
- Fixed not being able to craft Immersive Engineering Revolver (raoulvdberge)
### 1.5.18 ### 1.5.18
- Added Project E integration for the External Storage on the Transmutation Table (raoulvdberge) - Added Project E integration for the External Storage on the Transmutation Table (raoulvdberge)

View File

@@ -53,6 +53,7 @@ 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 player the player
* @param hash the item stack hash * @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
* @param noPreview true if the crafting preview window shouldn't be shown, false otherwise * @param noPreview true if the crafting preview window shouldn't be shown, false otherwise
@@ -63,10 +64,10 @@ public interface IItemGridHandler {
* Called when a player requested crafting for an item. * Called when a player requested crafting for an item.
* *
* @param player the player that is requesting the crafting * @param player the player that is requesting the crafting
* @param stack the {@link ItemStack} to request a craft for * @param hash the hash of the item to request a craft for
* @param quantity the amount of the item that has to be crafted * @param quantity the amount of the item that has to be crafted
*/ */
void onCraftingRequested(EntityPlayerMP player, ItemStack stack, int quantity); void onCraftingRequested(EntityPlayerMP player, int hash, int quantity);
/** /**
* Called when a player wants to cancel a crafting task. * Called when a player wants to cancel a crafting task.

View File

@@ -183,20 +183,36 @@ public class ItemGridHandler implements IItemGridHandler {
RS.INSTANCE.network.sendTo(new MessageGridCraftingStartResponse(), player); RS.INSTANCE.network.sendTo(new MessageGridCraftingStartResponse(), player);
} else { } else {
RS.INSTANCE.network.sendTo(new MessageGridCraftingPreviewResponse(task.getPreviewStacks(), stack, quantity), player); RS.INSTANCE.network.sendTo(new MessageGridCraftingPreviewResponse(task.getPreviewStacks(), hash, quantity), player);
} }
}, "RS crafting calculation"); }, "RS crafting preview calculation");
calculationThread.start(); calculationThread.start();
} }
} }
@Override @Override
public void onCraftingRequested(EntityPlayerMP player, ItemStack stack, int quantity) { public void onCraftingRequested(EntityPlayerMP player, int hash, int quantity) {
if (quantity <= 0 || !network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)) { if (quantity <= 0 || !network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)) {
return; return;
} }
ItemStack stack = null;
for (ICraftingPattern pattern : network.getCraftingManager().getPatterns()) {
for (ItemStack output : pattern.getOutputs()) {
if (output != null && API.instance().getItemStackHashCode(output) == hash) {
stack = output;
break;
}
}
if (stack != null) {
break;
}
}
if (stack != null) { if (stack != null) {
ICraftingTask task = new CraftingTask(network, stack, network.getCraftingManager().getPatternChain(stack), quantity, false); ICraftingTask task = new CraftingTask(network, stack, network.getCraftingManager().getPatternChain(stack), quantity, false);

View File

@@ -149,7 +149,7 @@ public class ItemGridHandlerPortable implements IItemGridHandler {
} }
@Override @Override
public void onCraftingRequested(EntityPlayerMP player, ItemStack stack, int quantity) { public void onCraftingRequested(EntityPlayerMP player, int hash, int quantity) {
// NO OP // NO OP
} }

View File

@@ -44,7 +44,7 @@ public class GuiCraftingPreview extends GuiBase {
private List<ICraftingPreviewElement> stacks; private List<ICraftingPreviewElement> stacks;
private GuiScreen parent; private GuiScreen parent;
private ItemStack stack; private int hash;
private int quantity; private int quantity;
private GuiButton startButton; private GuiButton startButton;
@@ -52,7 +52,7 @@ public class GuiCraftingPreview extends GuiBase {
private IElementDrawers drawers = new CraftingPreviewElementDrawers(); private IElementDrawers drawers = new CraftingPreviewElementDrawers();
public GuiCraftingPreview(GuiScreen parent, List<ICraftingPreviewElement> stacks, ItemStack stack, int quantity) { public GuiCraftingPreview(GuiScreen parent, List<ICraftingPreviewElement> stacks, int hash, int quantity) {
super(new Container() { super(new Container() {
@Override @Override
public boolean canInteractWith(EntityPlayer player) { public boolean canInteractWith(EntityPlayer player) {
@@ -63,7 +63,7 @@ public class GuiCraftingPreview extends GuiBase {
this.stacks = new ArrayList<>(stacks); this.stacks = new ArrayList<>(stacks);
this.parent = parent; this.parent = parent;
this.stack = stack; this.hash = hash;
this.quantity = quantity; this.quantity = quantity;
this.scrollbar = new Scrollbar(149, 20, 12, 119); this.scrollbar = new Scrollbar(149, 20, 12, 119);
@@ -184,7 +184,7 @@ public class GuiCraftingPreview extends GuiBase {
} }
private void startRequest() { private void startRequest() {
RS.INSTANCE.network.sendToServer(new MessageGridCraftingStart(stack, quantity)); RS.INSTANCE.network.sendToServer(new MessageGridCraftingStart(hash, quantity));
close(); close();
} }

View File

@@ -4,7 +4,6 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.preview.ICraftingPreview
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.proxy.ProxyClient; import com.raoulvdberge.refinedstorage.proxy.ProxyClient;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
@@ -15,21 +14,21 @@ import java.util.List;
public class MessageGridCraftingPreviewResponse implements IMessage, IMessageHandler<MessageGridCraftingPreviewResponse, IMessage> { public class MessageGridCraftingPreviewResponse implements IMessage, IMessageHandler<MessageGridCraftingPreviewResponse, IMessage> {
public List<ICraftingPreviewElement> stacks; public List<ICraftingPreviewElement> stacks;
public ItemStack stack; public int hash;
public int quantity; public int quantity;
public MessageGridCraftingPreviewResponse() { public MessageGridCraftingPreviewResponse() {
} }
public MessageGridCraftingPreviewResponse(List<ICraftingPreviewElement> stacks, ItemStack stack, int quantity) { public MessageGridCraftingPreviewResponse(List<ICraftingPreviewElement> stacks, int hash, int quantity) {
this.stacks = stacks; this.stacks = stacks;
this.stack = stack; this.hash = hash;
this.quantity = quantity; this.quantity = quantity;
} }
@Override @Override
public void fromBytes(ByteBuf buf) { public void fromBytes(ByteBuf buf) {
this.stack = ByteBufUtils.readItemStack(buf); this.hash = buf.readInt();
this.quantity = buf.readInt(); this.quantity = buf.readInt();
this.stacks = new LinkedList<>(); this.stacks = new LinkedList<>();
@@ -43,8 +42,8 @@ public class MessageGridCraftingPreviewResponse implements IMessage, IMessageHan
@Override @Override
public void toBytes(ByteBuf buf) { public void toBytes(ByteBuf buf) {
ByteBufUtils.writeItemStack(buf, this.stack); buf.writeInt(hash);
buf.writeInt(this.quantity); buf.writeInt(quantity);
buf.writeInt(stacks.size()); buf.writeInt(stacks.size());

View File

@@ -5,31 +5,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 MessageGridCraftingStart extends MessageHandlerPlayerToServer<MessageGridCraftingStart> implements IMessage { public class MessageGridCraftingStart extends MessageHandlerPlayerToServer<MessageGridCraftingStart> implements IMessage {
private ItemStack stack; private int hash;
private int quantity; private int quantity;
public MessageGridCraftingStart() { public MessageGridCraftingStart() {
} }
public MessageGridCraftingStart(ItemStack stack, int quantity) { public MessageGridCraftingStart(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);
} }
@@ -41,7 +39,7 @@ public class MessageGridCraftingStart extends MessageHandlerPlayerToServer<Messa
IGrid grid = ((ContainerGrid) container).getGrid(); IGrid grid = ((ContainerGrid) container).getGrid();
if (grid.getItemHandler() != null) { if (grid.getItemHandler() != null) {
grid.getItemHandler().onCraftingRequested(player, message.stack, message.quantity); grid.getItemHandler().onCraftingRequested(player, message.hash, message.quantity);
} }
} }
} }

View File

@@ -293,7 +293,7 @@ public class ProxyClient extends ProxyCommon {
screen = ((GuiCraftingStart) screen).getParent(); screen = ((GuiCraftingStart) screen).getParent();
} }
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingPreview(screen, message.stacks, message.stack, message.quantity)); FMLCommonHandler.instance().showGuiScreen(new GuiCraftingPreview(screen, message.stacks, message.hash, message.quantity));
}); });
} }