mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-28 07:55:41 +00:00
#545 Crash with Conduit Probe
This commit is contained in:
1 parent
6d97c88a1b
commit
04cd560258
4 files changed
+49
-2
No files matched your search
@@ -57,6 +57,8 @@ public class PacketHandler implements IPacketHandler {
|
||||
|
||||
public static final int ID_ME_TERMINAL = 28;
|
||||
|
||||
public static final int ID_MJ_READER_OPEN_CONDUIT_UI = 29;
|
||||
|
||||
public static final String CHANNEL = "EnderIO";
|
||||
|
||||
public static PacketHandler instance;
|
||||
|
||||
@@ -12,8 +12,10 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.WorldCoord;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.machine.monitor.MJReaderPacketHandler;
|
||||
import crazypants.render.ColorUtil;
|
||||
|
||||
public class GuiExternalConnectionSelector extends GuiScreen {
|
||||
@@ -34,6 +36,8 @@ public class GuiExternalConnectionSelector extends GuiScreen {
|
||||
ForgeDirection dir = ForgeDirection.values()[b.id];
|
||||
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
|
||||
WorldCoord loc = cb.getLocation();
|
||||
|
||||
PacketDispatcher.sendPacketToServer(MJReaderPacketHandler.createOpenConduitGuiPacket(cb, dir));
|
||||
player.openGui(EnderIO.instance, GuiHandler.GUI_ID_EXTERNAL_CONNECTION_BASE + dir.ordinal(), player.worldObj, loc.x, loc.y, loc.z);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ItemMJReader extends Item {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float par8,
|
||||
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float par8,
|
||||
float par9, float par10) {
|
||||
|
||||
if(player.isSneaking()) {
|
||||
|
||||
@@ -20,10 +20,13 @@ import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.IPacketProcessor;
|
||||
import crazypants.enderio.Log;
|
||||
import crazypants.enderio.PacketHandler;
|
||||
import crazypants.enderio.conduit.ConnectionMode;
|
||||
import crazypants.enderio.conduit.IConduitBundle;
|
||||
import crazypants.enderio.conduit.TileConduitBundle;
|
||||
import crazypants.enderio.conduit.item.IItemConduit;
|
||||
import crazypants.enderio.conduit.item.ItemConduitNetwork;
|
||||
@@ -60,6 +63,27 @@ public class MJReaderPacketHandler implements IPacketProcessor {
|
||||
private static final String REQUEST_RANGE = " " + Lang.localize("gui.mjReader.requestRange") + ": ";;
|
||||
private static final String CUR_REQUEST = " " + Lang.localize("gui.mjReader.currentRequest") + ": ";;
|
||||
|
||||
public static Packet createOpenConduitGuiPacket(IConduitBundle bundle, ForgeDirection dir) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
try {
|
||||
dos.writeInt(PacketHandler.ID_MJ_READER_OPEN_CONDUIT_UI);
|
||||
TileEntity te = bundle.getEntity();
|
||||
dos.writeInt(te.xCoord);
|
||||
dos.writeInt(te.yCoord);
|
||||
dos.writeInt(te.zCoord);
|
||||
dos.writeInt(dir.ordinal());
|
||||
} catch (IOException e) {
|
||||
// never thrown
|
||||
}
|
||||
Packet250CustomPayload pkt = new Packet250CustomPayload();
|
||||
pkt.channel = PacketHandler.CHANNEL;
|
||||
pkt.data = bos.toByteArray();
|
||||
pkt.length = bos.size();
|
||||
pkt.isChunkDataPacket = true;
|
||||
return pkt;
|
||||
}
|
||||
|
||||
public static boolean canCreatePacket(World world, int x, int y, int z) {
|
||||
int id = world.getBlockId(x, y, z);
|
||||
TileEntity te = world.getBlockTileEntity(x, y, z);
|
||||
@@ -105,18 +129,35 @@ public class MJReaderPacketHandler implements IPacketProcessor {
|
||||
|
||||
@Override
|
||||
public boolean canProcessPacket(int packetID) {
|
||||
return PacketHandler.ID_MJ_READER_INFO_REQUEST == packetID;
|
||||
return PacketHandler.ID_MJ_READER_INFO_REQUEST == packetID || PacketHandler.ID_MJ_READER_OPEN_CONDUIT_UI == packetID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPacket(int packetID, INetworkManager manager, DataInputStream data, Player player) throws IOException {
|
||||
if(packetID == PacketHandler.ID_MJ_READER_INFO_REQUEST) {
|
||||
sendInfoMessage(data, player);
|
||||
} else if(packetID == PacketHandler.ID_MJ_READER_OPEN_CONDUIT_UI) {
|
||||
handleUiPacket(data, player);
|
||||
} else {
|
||||
Log.error("MJReaderPacketHandler.processPacket: Recieved unkown packet with ID " + packetID);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleUiPacket(DataInputStream data, Player p) throws IOException {
|
||||
int x = data.readInt();
|
||||
int y = data.readInt();
|
||||
int z = data.readInt();
|
||||
int side = data.readInt();
|
||||
|
||||
EntityPlayer player = (EntityPlayer) p;
|
||||
World world = player.worldObj;
|
||||
if(world == null) {
|
||||
Log.warn("MJReaderPacketHandler.sendInfoMessage: Could not handle packet as player world was null.");
|
||||
return;
|
||||
}
|
||||
player.openGui(EnderIO.instance, GuiHandler.GUI_ID_EXTERNAL_CONNECTION_BASE + side, player.worldObj, x, y, z);
|
||||
}
|
||||
|
||||
private void sendInfoMessage(DataInputStream data, Player p) throws IOException {
|
||||
int x = data.readInt();
|
||||
int y = data.readInt();
|
||||
|
||||
Reference in new issue
Block a user