Client/server GUI communication logistics

This commit is contained in:
Aidan C. Brady 2013-10-27 17:29:34 -04:00
parent f60106f0e9
commit 5e7c01c1af
8 changed files with 207 additions and 44 deletions

View file

@ -350,12 +350,6 @@ public class ClientProxy extends CommonProxy
}
case 25:
return new GuiRobitRepair(player.inventory, world, x);
case 26:
return new GuiLogisticalSorter(player, (TileEntityLogisticalSorter)tileEntity);
case 27:
return new GuiItemStackFilter(player, (TileEntityLogisticalSorter)tileEntity);
case 28:
return new GuiOreDictFilter(player, (TileEntityLogisticalSorter)tileEntity);
}
return null;

View file

@ -8,9 +8,8 @@ import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.inventory.container.ContainerFilter;
import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.network.PacketNewFilter;
import mekanism.common.network.PacketRobit;
import mekanism.common.network.PacketRobit.RobitPacketType;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import mekanism.common.transporter.ItemStackFilter;
import mekanism.common.util.MekanismUtils;
@ -62,7 +61,13 @@ public class GuiItemStackFilter extends GuiMekanism
int guiHeight = (height - ySize) / 2;
buttonList.clear();
buttonList.add(new GuiButton(0, guiWidth + 58, guiHeight + 63, 60, 18, "Save"));
buttonList.add(new GuiButton(0, guiWidth + 27, guiHeight + 62, 60, 20, "Save"));
buttonList.add(new GuiButton(1, guiWidth + 89, guiHeight + 62, 60, 20, "Delete"));
if(isNew)
{
((GuiButton)buttonList.get(1)).enabled = false;
}
}
@Override
@ -75,7 +80,7 @@ public class GuiItemStackFilter extends GuiMekanism
if(filter.itemType != null)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketNewFilter().setParams(Object3D.get(tileEntity), filter));
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 0));
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Object3D.get(tileEntity), 0));
mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
}
else {
@ -115,12 +120,12 @@ public class GuiItemStackFilter extends GuiMekanism
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
mc.getTextureManager().bindTexture(MekanismRenderer.getColorResource(filter.color));
itemRenderer.renderIcon(12, 45, MekanismRenderer.getColorIcon(filter.color), 16, 16);
itemRenderer.renderIcon(12, 44, MekanismRenderer.getColorIcon(filter.color), 16, 16);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 45 && yAxis <= 61)
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 44 && yAxis <= 60)
{
drawCreativeTabHoveringText(filter.color.getName(), xAxis, yAxis);
}
@ -193,8 +198,7 @@ public class GuiItemStackFilter extends GuiMekanism
if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 0));
mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Object3D.get(tileEntity), 0));
}
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 19 && yAxis <= 35)
@ -208,7 +212,7 @@ public class GuiItemStackFilter extends GuiMekanism
}
}
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 45 && yAxis <= 61)
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 44 && yAxis <= 60)
{
filter.color = TransporterUtils.increment(filter.color);
}

View file

@ -7,6 +7,7 @@ import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.inventory.container.ContainerNull;
import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import mekanism.common.transporter.ItemStackFilter;
import mekanism.common.transporter.OreDictFilter;
@ -72,7 +73,15 @@ public class GuiLogisticalSorter extends GuiMekanism
if(xAxis >= 56 && xAxis <= 152 && yAxis >= yStart && yAxis <= yStart+29)
{
TransporterFilter filter = tileEntity.filters.get(getFilterIndex()+i);
System.out.println(getFilterIndex()+i);
if(filter instanceof ItemStackFilter)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER_INDEX, Object3D.get(tileEntity), 1, getFilterIndex()+i));
}
else if(filter instanceof OreDictFilter)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER_INDEX, Object3D.get(tileEntity), 2, getFilterIndex()+i));
}
}
}
}
@ -124,13 +133,11 @@ public class GuiLogisticalSorter extends GuiMekanism
if(guibutton.id == 0)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 1));
mc.displayGuiScreen(new GuiItemStackFilter(mc.thePlayer, tileEntity));
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Object3D.get(tileEntity), 1));
}
else if(guibutton.id == 1)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 2));
mc.displayGuiScreen(new GuiOreDictFilter(mc.thePlayer, tileEntity));
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Object3D.get(tileEntity), 2));
}
}

View file

@ -11,6 +11,7 @@ import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.inventory.container.ContainerFilter;
import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.network.PacketNewFilter;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import mekanism.common.transporter.OreDictFilter;
@ -76,9 +77,15 @@ public class GuiOreDictFilter extends GuiMekanism
int guiHeight = (height - ySize) / 2;
buttonList.clear();
buttonList.add(new GuiButton(0, guiWidth + 58, guiHeight + 63, 60, 18, "Save"));
buttonList.add(new GuiButton(0, guiWidth + 27, guiHeight + 62, 60, 20, "Save"));
buttonList.add(new GuiButton(1, guiWidth + 89, guiHeight + 62, 60, 20, "Delete"));
oreDictText = new GuiTextField(fontRenderer, guiWidth + 35, guiHeight + 48, 95, 12);
if(isNew)
{
((GuiButton)buttonList.get(1)).enabled = false;
}
oreDictText = new GuiTextField(fontRenderer, guiWidth + 35, guiHeight + 47, 95, 12);
oreDictText.setMaxStringLength(12);
oreDictText.setFocused(true);
}
@ -116,7 +123,7 @@ public class GuiOreDictFilter extends GuiMekanism
if(filter.oreDictName != null && !filter.oreDictName.isEmpty())
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketNewFilter().setParams(Object3D.get(tileEntity), filter));
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 0));
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Object3D.get(tileEntity), 0));
mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
}
else {
@ -151,12 +158,12 @@ public class GuiOreDictFilter extends GuiMekanism
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
mc.getTextureManager().bindTexture(MekanismRenderer.getColorResource(filter.color));
itemRenderer.renderIcon(12, 45, MekanismRenderer.getColorIcon(filter.color), 16, 16);
itemRenderer.renderIcon(12, 44, MekanismRenderer.getColorIcon(filter.color), 16, 16);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 45 && yAxis <= 61)
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 44 && yAxis <= 60)
{
drawCreativeTabHoveringText(filter.color.getName(), xAxis, yAxis);
}
@ -186,12 +193,12 @@ public class GuiOreDictFilter extends GuiMekanism
drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 11, 11, 11);
}
if(xAxis >= 131 && xAxis <= 143 && yAxis >= 48 && yAxis <= 60)
if(xAxis >= 131 && xAxis <= 143 && yAxis >= 47 && yAxis <= 59)
{
drawTexturedModalRect(guiWidth + 131, guiHeight + 48, 176 + 11, 0, 12, 12);
drawTexturedModalRect(guiWidth + 131, guiHeight + 47, 176 + 11, 0, 12, 12);
}
else {
drawTexturedModalRect(guiWidth + 131, guiHeight + 48, 176 + 11, 12, 12, 12);
drawTexturedModalRect(guiWidth + 131, guiHeight + 47, 176 + 11, 12, 12, 12);
}
oreDictText.drawTextBox();
@ -253,16 +260,15 @@ public class GuiOreDictFilter extends GuiMekanism
if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 0));
mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Object3D.get(tileEntity), 0));
}
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 45 && yAxis <= 61)
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 44 && yAxis <= 60)
{
filter.color = TransporterUtils.increment(filter.color);
}
if(xAxis >= 131 && xAxis <= 143 && yAxis >= 48 && yAxis <= 60)
if(xAxis >= 131 && xAxis <= 143 && yAxis >= 47 && yAxis <= 59)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
setOreDictKey();

View file

@ -22,6 +22,7 @@ import mekanism.common.Tier;
import mekanism.common.network.PacketElectricChest;
import mekanism.common.network.PacketElectricChest.ElectricChestPacketType;
import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.tileentity.TileEntityAdvancedFactory;
import mekanism.common.tileentity.TileEntityBasicBlock;
import mekanism.common.tileentity.TileEntityChargepad;
@ -650,6 +651,11 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
return true;
}
}
else if(metadata == MachineType.LOGISTICAL_SORTER.meta)
{
TileEntityLogisticalSorter sorter = (TileEntityLogisticalSorter)tileEntity;
PacketLogisticalSorterGui.openServerGui(SorterGuiPacket.SERVER, 0, world, (EntityPlayerMP)entityplayer, Object3D.get(tileEntity), -1);
}
else {
if(!entityplayer.isSneaking() && MachineType.getFromMetadata(metadata).guiId != -1)
{
@ -860,7 +866,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
ELECTRIC_PUMP(12, "ElectricPump", 17, 10000, TileEntityElectricPump.class, true),
ELECTRIC_CHEST(13, "ElectricChest", -1, 12000, TileEntityElectricChest.class, true),
CHARGEPAD(14, "Chargepad", -1, 9000, TileEntityChargepad.class, true),
LOGISTICAL_SORTER(15, "LogisticalSorter", 26, 12000, TileEntityLogisticalSorter.class, false);
LOGISTICAL_SORTER(15, "LogisticalSorter", -1, 12000, TileEntityLogisticalSorter.class, false);
public int meta;
public String name;

View file

@ -3,21 +3,40 @@ package mekanism.common.network;
import java.io.DataOutputStream;
import mekanism.api.Object3D;
import mekanism.client.gui.GuiItemStackFilter;
import mekanism.client.gui.GuiLogisticalSorter;
import mekanism.client.gui.GuiOreDictFilter;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.inventory.container.ContainerFilter;
import mekanism.common.inventory.container.ContainerNull;
import mekanism.common.tileentity.TileEntityContainerBlock;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.world.World;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketLogisticalSorterGui implements IMekanismPacket
{
public Object3D object3D;
public SorterGuiPacket packetType;
public int type;
public int windowId = -1;
public int index = -1;
@Override
public String getName()
{
@ -27,8 +46,24 @@ public class PacketLogisticalSorterGui implements IMekanismPacket
@Override
public IMekanismPacket setParams(Object... data)
{
object3D = (Object3D)data[0];
type = (Integer)data[1];
packetType = (SorterGuiPacket)data[0];
object3D = (Object3D)data[1];
type = (Integer)data[2];
if(packetType == SorterGuiPacket.CLIENT)
{
windowId = (Integer)data[3];
}
else if(packetType == SorterGuiPacket.SERVER_INDEX)
{
index = (Integer)data[3];
}
else if(packetType == SorterGuiPacket.CLIENT_INDEX)
{
windowId = (Integer)data[3];
index = (Integer)data[4];
}
return this;
}
@ -36,25 +71,121 @@ public class PacketLogisticalSorterGui implements IMekanismPacket
@Override
public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception
{
int x = dataStream.readInt();
int y = dataStream.readInt();
int z = dataStream.readInt();
packetType = SorterGuiPacket.values()[dataStream.readInt()];
int id = dataStream.readInt();
object3D = new Object3D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
int type = dataStream.readInt();
type = dataStream.readInt();
World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(id);
if(worldServer != null && worldServer.getBlockTileEntity(x, y, z) instanceof TileEntityLogisticalSorter)
if(packetType == SorterGuiPacket.CLIENT || packetType == SorterGuiPacket.CLIENT_INDEX)
{
player.openGui(Mekanism.instance, 26+type, worldServer, x, y, z);
windowId = dataStream.readInt();
}
if(packetType == SorterGuiPacket.SERVER_INDEX || packetType == SorterGuiPacket.CLIENT_INDEX)
{
index = dataStream.readInt();
}
if(!world.isRemote)
{
World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(object3D.dimensionId);
if(worldServer != null && object3D.getTileEntity(worldServer) instanceof TileEntityLogisticalSorter)
{
openServerGui(packetType, type, worldServer, (EntityPlayerMP)player, object3D, index);
}
}
else {
if(object3D.getTileEntity(world) instanceof TileEntityLogisticalSorter)
{
try {
if(packetType == SorterGuiPacket.CLIENT)
{
FMLCommonHandler.instance().showGuiScreen(getGui(packetType, type, player, world, object3D.xCoord, object3D.yCoord, object3D.zCoord, -1));
}
else if(packetType == SorterGuiPacket.CLIENT_INDEX)
{
FMLCommonHandler.instance().showGuiScreen(getGui(packetType, type, player, world, object3D.xCoord, object3D.yCoord, object3D.zCoord, index));
}
player.openContainer.windowId = windowId;
} catch(Exception e) {}
}
}
}
public static void openServerGui(SorterGuiPacket t, int guiType, World world, EntityPlayerMP playerMP, Object3D obj, int i)
{
Container container = null;
if(guiType == 0)
{
container = new ContainerNull(playerMP, (TileEntityContainerBlock)obj.getTileEntity(world));
}
else if(guiType == 1 || guiType == 2)
{
container = new ContainerFilter(playerMP.inventory);
}
playerMP.incrementWindowID();
playerMP.closeContainer();
int window = playerMP.currentWindowId;
if(t == SorterGuiPacket.SERVER)
{
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.CLIENT, obj, guiType, window), playerMP);
}
else if(t == SorterGuiPacket.SERVER_INDEX)
{
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.CLIENT_INDEX, obj, guiType, window, i), playerMP);
}
playerMP.openContainer = container;
playerMP.openContainer.windowId = window;
playerMP.openContainer.addCraftingToCrafters(playerMP);
}
@SideOnly(Side.CLIENT)
public GuiScreen getGui(SorterGuiPacket packetType, int type, EntityPlayer player, World world, int x, int y, int z, int index)
{
if(type == 0)
{
return new GuiLogisticalSorter(player, (TileEntityLogisticalSorter)world.getBlockTileEntity(x, y, z));
}
else {
if(packetType == SorterGuiPacket.CLIENT)
{
if(type == 1)
{
return new GuiItemStackFilter(player, (TileEntityLogisticalSorter)world.getBlockTileEntity(x, y, z));
}
else if(type == 2)
{
return new GuiOreDictFilter(player, (TileEntityLogisticalSorter)world.getBlockTileEntity(x, y, z));
}
}
else if(packetType == SorterGuiPacket.CLIENT_INDEX)
{
if(type == 1)
{
return new GuiItemStackFilter(player, (TileEntityLogisticalSorter)world.getBlockTileEntity(x, y, z), index);
}
else if(type == 2)
{
return new GuiOreDictFilter(player, (TileEntityLogisticalSorter)world.getBlockTileEntity(x, y, z), index);
}
}
}
return null;
}
@Override
public void write(DataOutputStream dataStream) throws Exception
{
dataStream.writeInt(packetType.ordinal());
dataStream.writeInt(object3D.xCoord);
dataStream.writeInt(object3D.yCoord);
dataStream.writeInt(object3D.zCoord);
@ -62,5 +193,20 @@ public class PacketLogisticalSorterGui implements IMekanismPacket
dataStream.writeInt(object3D.dimensionId);
dataStream.writeInt(type);
if(packetType == SorterGuiPacket.CLIENT || packetType == SorterGuiPacket.CLIENT_INDEX)
{
dataStream.writeInt(windowId);
}
if(packetType == SorterGuiPacket.SERVER_INDEX || packetType == SorterGuiPacket.CLIENT_INDEX)
{
dataStream.writeInt(index);
}
}
public static enum SorterGuiPacket
{
SERVER, CLIENT, SERVER_INDEX, CLIENT_INDEX
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB