Cancelling crafting tasks
This commit is contained in:
@@ -4,8 +4,10 @@ import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.container.ContainerCraftingMonitor;
|
||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||
import refinedstorage.network.MessageCraftingMonitorCancel;
|
||||
import refinedstorage.tile.autocrafting.TileCraftingMonitor;
|
||||
import scala.actors.threadpool.Arrays;
|
||||
|
||||
@@ -38,7 +40,7 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
public void init(int x, int y) {
|
||||
addSideButton(new SideButtonRedstoneMode(craftingMonitor));
|
||||
|
||||
cancelButton = addButton(x + 7, y + 113, 50, 20, "Cancel");
|
||||
cancelButton = addButton(x + 7, y + 113, 50, 20, t("misc.refinedstorage:cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,6 +146,15 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
return max < 0 ? 0 : max;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
super.actionPerformed(button);
|
||||
|
||||
if (button == cancelButton && itemSelected != -1) {
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageCraftingMonitorCancel(craftingMonitor, itemSelected));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
54
src/main/java/refinedstorage/network/MessageCraftingMonitorCancel.java
Executable file
54
src/main/java/refinedstorage/network/MessageCraftingMonitorCancel.java
Executable file
@@ -0,0 +1,54 @@
|
||||
package refinedstorage.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import refinedstorage.tile.autocrafting.TileCraftingMonitor;
|
||||
|
||||
public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<MessageCraftingMonitorCancel> implements IMessage {
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private int id;
|
||||
|
||||
public MessageCraftingMonitorCancel() {
|
||||
}
|
||||
|
||||
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id) {
|
||||
this.x = craftingMonitor.getPos().getX();
|
||||
this.y = craftingMonitor.getPos().getY();
|
||||
this.z = craftingMonitor.getPos().getZ();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
id = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeInt(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MessageCraftingMonitorCancel message, EntityPlayerMP player) {
|
||||
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z));
|
||||
|
||||
if (tile instanceof TileCraftingMonitor) {
|
||||
TileCraftingMonitor craftingMonitor = (TileCraftingMonitor) tile;
|
||||
|
||||
if (craftingMonitor.isConnected()) {
|
||||
craftingMonitor.getController().onCraftingTaskCancelRequested(message.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,7 @@ public class CommonProxy {
|
||||
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingStart.class, MessageGridCraftingStart.class, 20, Side.SERVER);
|
||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridCraftingStart.class, MessageWirelessGridCraftingStart.class, 21, Side.SERVER);
|
||||
RefinedStorage.NETWORK.registerMessage(MessageGridPatternCreate.class, MessageGridPatternCreate.class, 22, Side.SERVER);
|
||||
RefinedStorage.NETWORK.registerMessage(MessageCraftingMonitorCancel.class, MessageCraftingMonitorCancel.class, 23, Side.SERVER);
|
||||
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler());
|
||||
|
||||
|
||||
@@ -750,4 +750,10 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onCraftingTaskCancelRequested(int id) {
|
||||
if (id >= 0 && id < craftingTasks.size()) {
|
||||
cancelCraftingTask(craftingTasks.get(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user