Fixes #847 and fixes a bug with nodes not being removed clientside
This commit is contained in:
@@ -44,10 +44,11 @@ public interface IItemGridHandler {
|
||||
/**
|
||||
* Called when a player requests the crafting preview window to be opened.
|
||||
*
|
||||
* @param hash the item stack hash
|
||||
* @param quantity the amount of that item that we need a preview for
|
||||
* @param hash the item stack hash
|
||||
* @param quantity the amount of that item that we need a preview for
|
||||
* @param noPreview whether the preview should show
|
||||
*/
|
||||
void onCraftingPreviewRequested(EntityPlayerMP player, int hash, int quantity);
|
||||
void onCraftingPreviewRequested(EntityPlayerMP player, int hash, int quantity, boolean noPreview);
|
||||
|
||||
/**
|
||||
* Called when a player requested crafting for an item.
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.CraftingTask;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.item.NetworkItemWirelessCraftingMonitor;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.item.NetworkItemWirelessGrid;
|
||||
import com.raoulvdberge.refinedstorage.network.MessageGridCraftingPreviewResponse;
|
||||
import com.raoulvdberge.refinedstorage.network.MessageGridCraftingStartResponse;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -149,7 +150,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftingPreviewRequested(EntityPlayerMP player, int hash, int quantity) {
|
||||
public void onCraftingPreviewRequested(EntityPlayerMP player, int hash, int quantity, boolean noPreview) {
|
||||
if (!network.getSecurityManager().hasPermission(Permission.AUTOCRAFTING, player)) {
|
||||
return;
|
||||
}
|
||||
@@ -172,7 +173,13 @@ public class ItemGridHandler implements IItemGridHandler {
|
||||
|
||||
task.calculate();
|
||||
|
||||
RS.INSTANCE.network.sendTo(new MessageGridCraftingPreviewResponse(task.getPreviewStacks(), stack, quantity), player);
|
||||
if (noPreview && task.getMissing().isEmpty()) {
|
||||
network.getCraftingManager().add(task);
|
||||
|
||||
RS.INSTANCE.network.sendTo(new MessageGridCraftingStartResponse(), player);
|
||||
} else {
|
||||
RS.INSTANCE.network.sendTo(new MessageGridCraftingPreviewResponse(task.getPreviewStacks(), stack, quantity), player);
|
||||
}
|
||||
}, "RS crafting calculation");
|
||||
|
||||
calculationThread.start();
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.raoulvdberge.refinedstorage.block;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.network.MessageNodeRemove;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileNode;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
@@ -56,9 +58,12 @@ public abstract class BlockNode extends BlockBase {
|
||||
|
||||
manager.removeNode(pos);
|
||||
|
||||
if (!world.isRemote && node.getNetwork() != null) {
|
||||
if (node.getNetwork() != null) {
|
||||
node.getNetwork().getNodeGraph().rebuild();
|
||||
}
|
||||
|
||||
// Since Block#breakBlock is only called on the server and we can't trust TileEntity#invalidate:
|
||||
RS.INSTANCE.network.sendToAll(new MessageNodeRemove(world.provider.getDimension(), pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -112,7 +112,6 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
} else {
|
||||
|
||||
int slot = scrollbar.getOffset() * 2;
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
@@ -71,7 +71,7 @@ public class GuiPriority extends GuiCraftingStart {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startRequest() {
|
||||
protected void startRequest(boolean noPreview) {
|
||||
Integer amount = Ints.tryParse(amountField.getText());
|
||||
|
||||
if (amount != null) {
|
||||
|
||||
@@ -130,7 +130,7 @@ public class GuiCraftingStart extends GuiBase {
|
||||
// NO OP
|
||||
} else {
|
||||
if (keyCode == Keyboard.KEY_RETURN) {
|
||||
startRequest();
|
||||
startRequest(isShiftKeyDown());
|
||||
} else if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
close();
|
||||
} else {
|
||||
@@ -144,7 +144,7 @@ public class GuiCraftingStart extends GuiBase {
|
||||
super.actionPerformed(button);
|
||||
|
||||
if (button.id == startButton.id) {
|
||||
startRequest();
|
||||
startRequest(isShiftKeyDown());
|
||||
} else if (button.id == cancelButton.id) {
|
||||
close();
|
||||
} else {
|
||||
@@ -172,17 +172,17 @@ public class GuiCraftingStart extends GuiBase {
|
||||
}
|
||||
}
|
||||
|
||||
protected void startRequest() {
|
||||
protected void startRequest(boolean noPreview) {
|
||||
Integer quantity = Ints.tryParse(amountField.getText());
|
||||
|
||||
if (quantity != null && quantity > 0) {
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridCraftingPreview(stack.getHash(), quantity));
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridCraftingPreview(stack.getHash(), quantity, noPreview));
|
||||
|
||||
startButton.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void close() {
|
||||
public void close() {
|
||||
FMLClientHandler.instance().showGuiScreen(parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,25 +10,29 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
public class MessageGridCraftingPreview extends MessageHandlerPlayerToServer<MessageGridCraftingPreview> implements IMessage {
|
||||
private int hash;
|
||||
private int quantity;
|
||||
private boolean noPreview;
|
||||
|
||||
public MessageGridCraftingPreview() {
|
||||
}
|
||||
|
||||
public MessageGridCraftingPreview(int hash, int quantity) {
|
||||
public MessageGridCraftingPreview(int hash, int quantity, boolean noPreview) {
|
||||
this.hash = hash;
|
||||
this.quantity = quantity;
|
||||
this.noPreview = noPreview;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
hash = buf.readInt();
|
||||
quantity = buf.readInt();
|
||||
noPreview = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(hash);
|
||||
buf.writeInt(quantity);
|
||||
buf.writeBoolean(noPreview);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,7 +43,7 @@ public class MessageGridCraftingPreview extends MessageHandlerPlayerToServer<Mes
|
||||
IGrid grid = ((ContainerGrid) container).getGrid();
|
||||
|
||||
if (grid.getNetwork() != null) {
|
||||
grid.getNetwork().getItemGridHandler().onCraftingPreviewRequested(player, message.hash, message.quantity);
|
||||
grid.getNetwork().getItemGridHandler().onCraftingPreviewRequested(player, message.hash, message.quantity, message.noPreview);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
package com.raoulvdberge.refinedstorage.network;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.proxy.ProxyClient;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class MessageGridCraftingStartResponse implements IMessage, IMessageHandler<MessageGridCraftingStartResponse, IMessage> {
|
||||
public MessageGridCraftingStartResponse() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(MessageGridCraftingStartResponse message, MessageContext ctx) {
|
||||
ProxyClient.onReceiveCraftingStartResponse();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.raoulvdberge.refinedstorage.network;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class MessageNodeRemove implements IMessage, IMessageHandler<MessageNodeRemove, IMessage> {
|
||||
private int dim;
|
||||
private BlockPos pos;
|
||||
|
||||
public MessageNodeRemove() {
|
||||
}
|
||||
|
||||
public MessageNodeRemove(int dim, BlockPos pos) {
|
||||
this.dim = dim;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
dim = buf.readInt();
|
||||
pos = BlockPos.fromLong(buf.readLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(dim);
|
||||
buf.writeLong(pos.toLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(MessageNodeRemove message, MessageContext ctx) {
|
||||
Minecraft.getMinecraft().addScheduledTask(() -> {
|
||||
INetworkNodeManager manager = API.instance().getNetworkNodeManager(message.dim);
|
||||
|
||||
manager.removeNode(message.pos);
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,6 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.model.ICustomModelLoader;
|
||||
@@ -42,7 +40,6 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -261,13 +258,14 @@ public class ProxyClient extends ProxyCommon {
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent e) {
|
||||
if (RS.VERSION.contains("beta")) {
|
||||
e.player.sendMessage(new TextComponentString("" + TextFormatting.RED + TextFormatting.BOLD + "WARNING: You are playing on a beta version of Refined Storage (" + RS.VERSION + ")!" + TextFormatting.RESET));
|
||||
e.player.sendMessage(new TextComponentString("Literally anything can happen: world breaking bugs, item duplication bugs, etc. So, make sure you make backups."));
|
||||
e.player.sendMessage(new TextComponentString("If you encounter a bug, please report it on the GitHub issue tracker."));
|
||||
}
|
||||
public static void onReceiveCraftingStartResponse() {
|
||||
Minecraft.getMinecraft().addScheduledTask(() -> {
|
||||
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
|
||||
|
||||
if (screen instanceof GuiCraftingStart) {
|
||||
((GuiCraftingStart) screen).close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -116,12 +116,14 @@ public class ProxyCommon {
|
||||
RS.INSTANCE.network.registerMessage(MessageGridFilterUpdate.class, MessageGridFilterUpdate.class, id++, Side.SERVER);
|
||||
RS.INSTANCE.network.registerMessage(MessageGridCraftingPreview.class, MessageGridCraftingPreview.class, id++, Side.SERVER);
|
||||
RS.INSTANCE.network.registerMessage(MessageGridCraftingPreviewResponse.class, MessageGridCraftingPreviewResponse.class, id++, Side.CLIENT);
|
||||
RS.INSTANCE.network.registerMessage(MessageGridCraftingStartResponse.class, MessageGridCraftingStartResponse.class, id++, Side.CLIENT);
|
||||
RS.INSTANCE.network.registerMessage(MessageProcessingPatternEncoderTransfer.class, MessageProcessingPatternEncoderTransfer.class, id++, Side.SERVER);
|
||||
RS.INSTANCE.network.registerMessage(MessageReaderWriterUpdate.class, MessageReaderWriterUpdate.class, id++, Side.CLIENT);
|
||||
RS.INSTANCE.network.registerMessage(MessageReaderWriterChannelAdd.class, MessageReaderWriterChannelAdd.class, id++, Side.SERVER);
|
||||
RS.INSTANCE.network.registerMessage(MessageReaderWriterChannelRemove.class, MessageReaderWriterChannelRemove.class, id++, Side.SERVER);
|
||||
RS.INSTANCE.network.registerMessage(MessageSecurityManagerUpdate.class, MessageSecurityManagerUpdate.class, id++, Side.SERVER);
|
||||
RS.INSTANCE.network.registerMessage(MessageWirelessFluidGridSettingsUpdate.class, MessageWirelessFluidGridSettingsUpdate.class, id++, Side.SERVER);
|
||||
RS.INSTANCE.network.registerMessage(MessageNodeRemove.class, MessageNodeRemove.class, id++, Side.CLIENT);
|
||||
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(RS.INSTANCE, new GuiHandler());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user