Some work on networking logistics of GUI
This commit is contained in:
parent
a8d6386bb5
commit
4a042cfdc2
9 changed files with 197 additions and 33 deletions
|
@ -8,6 +8,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.PacketNewFilter;
|
||||
import mekanism.common.network.PacketRobit;
|
||||
import mekanism.common.network.PacketRobit.RobitPacketType;
|
||||
import mekanism.common.tileentity.TileEntityLogisticalSorter;
|
||||
|
@ -26,6 +27,8 @@ public class GuiItemStackFilter extends GuiMekanism
|
|||
{
|
||||
public TileEntityLogisticalSorter tileEntity;
|
||||
|
||||
public boolean isNew = false;
|
||||
|
||||
public ItemStackFilter filter = new ItemStackFilter();
|
||||
|
||||
public String status = EnumColor.DARK_GREEN + "All OK";
|
||||
|
@ -45,6 +48,8 @@ public class GuiItemStackFilter extends GuiMekanism
|
|||
super(new ContainerFilter(player.inventory));
|
||||
tileEntity = tentity;
|
||||
|
||||
isNew = true;
|
||||
|
||||
filter.color = TransporterUtils.colors.get(0);
|
||||
}
|
||||
|
||||
|
@ -73,7 +78,16 @@ public class GuiItemStackFilter extends GuiMekanism
|
|||
|
||||
if(guibutton.id == 0)
|
||||
{
|
||||
//PacketFilterUpdate TODO
|
||||
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));
|
||||
mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
}
|
||||
else {
|
||||
status = EnumColor.DARK_RED + "No item";
|
||||
ticker = 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +97,7 @@ public class GuiItemStackFilter extends GuiMekanism
|
|||
int xAxis = (mouseX - (width - xSize) / 2);
|
||||
int yAxis = (mouseY - (height - ySize) / 2);
|
||||
|
||||
fontRenderer.drawString("Edit ItemStack Filter", 43, 6, 0x404040);
|
||||
fontRenderer.drawString((isNew ? "New" : "Edit") + " ItemStack Filter", 43, 6, 0x404040);
|
||||
fontRenderer.drawString("Status: " + status, 35, 20, 0x00CD00);
|
||||
fontRenderer.drawString("ItemStack Details:", 35, 32, 0x00CD00);
|
||||
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package mekanism.client.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.inventory.container.ContainerNull;
|
||||
import mekanism.common.network.PacketLogisticalSorterGui;
|
||||
import mekanism.common.tileentity.TileEntityLogisticalSorter;
|
||||
import mekanism.common.transporter.ItemStackFilter;
|
||||
import mekanism.common.transporter.OreDictFilter;
|
||||
import mekanism.common.transporter.TransporterFilter;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
@ -73,7 +77,9 @@ public class GuiLogisticalSorter extends GuiMekanism
|
|||
|
||||
fontRenderer.drawString("Logistical Sorter", 43, 6, 0x404040);
|
||||
fontRenderer.drawString("Filters:", 11, 17, 0x00CD00);
|
||||
fontRenderer.drawString("- " + tileEntity.filters.size(), 11, 26, 0x00CD00);
|
||||
fontRenderer.drawString("T: " + tileEntity.filters.size(), 11, 26, 0x00CD00);
|
||||
fontRenderer.drawString("IS: " + getItemStackFilters().size(), 11, 35, 0x00CD00);
|
||||
fontRenderer.drawString("OD: " + getOreDictFilters().size(), 11, 44, 0x00CD00);
|
||||
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
}
|
||||
|
@ -89,4 +95,34 @@ public class GuiLogisticalSorter extends GuiMekanism
|
|||
int guiHeight = (height - ySize) / 2;
|
||||
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
|
||||
}
|
||||
|
||||
public ArrayList getItemStackFilters()
|
||||
{
|
||||
ArrayList list = new ArrayList();
|
||||
|
||||
for(TransporterFilter filter : tileEntity.filters)
|
||||
{
|
||||
if(filter instanceof ItemStackFilter)
|
||||
{
|
||||
list.add(filter);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList getOreDictFilters()
|
||||
{
|
||||
ArrayList list = new ArrayList();
|
||||
|
||||
for(TransporterFilter filter : tileEntity.filters)
|
||||
{
|
||||
if(filter instanceof OreDictFilter)
|
||||
{
|
||||
list.add(filter);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -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.PacketNewFilter;
|
||||
import mekanism.common.tileentity.TileEntityLogisticalSorter;
|
||||
import mekanism.common.transporter.OreDictFilter;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
@ -30,6 +31,8 @@ public class GuiOreDictFilter extends GuiMekanism
|
|||
{
|
||||
public TileEntityLogisticalSorter tileEntity;
|
||||
|
||||
public boolean isNew = false;
|
||||
|
||||
public OreDictFilter filter = new OreDictFilter();
|
||||
|
||||
private GuiTextField oreDictText;
|
||||
|
@ -59,6 +62,8 @@ public class GuiOreDictFilter extends GuiMekanism
|
|||
super(new ContainerFilter(player.inventory));
|
||||
tileEntity = tentity;
|
||||
|
||||
isNew = true;
|
||||
|
||||
filter.color = TransporterUtils.colors.get(0);
|
||||
}
|
||||
|
||||
|
@ -114,7 +119,16 @@ public class GuiOreDictFilter extends GuiMekanism
|
|||
|
||||
if(guibutton.id == 0)
|
||||
{
|
||||
//PacketFilterUpdate TODO
|
||||
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));
|
||||
mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
}
|
||||
else {
|
||||
status = EnumColor.DARK_RED + "No key";
|
||||
ticker = 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +138,7 @@ public class GuiOreDictFilter extends GuiMekanism
|
|||
int xAxis = (mouseX - (width - xSize) / 2);
|
||||
int yAxis = (mouseY - (height - ySize) / 2);
|
||||
|
||||
fontRenderer.drawString("Edit OreDict Filter", 43, 6, 0x404040);
|
||||
fontRenderer.drawString((isNew ? "New" : "Edit") + " OreDict Filter", 43, 6, 0x404040);
|
||||
fontRenderer.drawString("Status: " + status, 35, 20, 0x00CD00);
|
||||
fontRenderer.drawString("Key: " + filter.oreDictName, 35, 32, 0x00CD00);
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ import mekanism.common.network.PacketDataRequest;
|
|||
import mekanism.common.network.PacketDigitUpdate;
|
||||
import mekanism.common.network.PacketElectricBowState;
|
||||
import mekanism.common.network.PacketElectricChest;
|
||||
import mekanism.common.network.PacketFilterUpdate;
|
||||
import mekanism.common.network.PacketNewFilter;
|
||||
import mekanism.common.network.PacketLogisticalSorterGui;
|
||||
import mekanism.common.network.PacketPortableTeleport;
|
||||
import mekanism.common.network.PacketPortalFX;
|
||||
|
@ -1139,7 +1139,7 @@ public class Mekanism
|
|||
PacketHandler.registerPacket(PacketRedstoneControl.class);
|
||||
PacketHandler.registerPacket(PacketWalkieTalkieState.class);
|
||||
PacketHandler.registerPacket(PacketLogisticalSorterGui.class);
|
||||
PacketHandler.registerPacket(PacketFilterUpdate.class);
|
||||
PacketHandler.registerPacket(PacketNewFilter.class);
|
||||
|
||||
//Donators
|
||||
donators.add("mrgreaper");
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package mekanism.common.network;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.tileentity.TileEntityLogisticalSorter;
|
||||
import mekanism.common.transporter.TransporterFilter;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -12,12 +15,14 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
public class PacketFilterUpdate implements IMekanismPacket
|
||||
public class PacketNewFilter implements IMekanismPacket
|
||||
{
|
||||
public Object3D object3D;
|
||||
|
||||
public int type;
|
||||
|
||||
public TransporterFilter filter;
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
|
@ -28,7 +33,7 @@ public class PacketFilterUpdate implements IMekanismPacket
|
|||
public IMekanismPacket setParams(Object... data)
|
||||
{
|
||||
object3D = (Object3D)data[0];
|
||||
type = (Integer)data[1];
|
||||
filter = (TransporterFilter)data[1];
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -48,7 +53,12 @@ public class PacketFilterUpdate implements IMekanismPacket
|
|||
|
||||
if(worldServer != null && worldServer.getBlockTileEntity(x, y, z) instanceof TileEntityLogisticalSorter)
|
||||
{
|
||||
player.openGui(Mekanism.instance, 26+type, worldServer, x, y, z);
|
||||
TileEntityLogisticalSorter sorter = (TileEntityLogisticalSorter)worldServer.getBlockTileEntity(x, y, z);
|
||||
TransporterFilter filter = TransporterFilter.readFromPacket(dataStream);
|
||||
|
||||
sorter.filters.add(filter);
|
||||
|
||||
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketTileEntity().setParams(Object3D.get(sorter), sorter.getFilterPacket(new ArrayList())), player);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,6 +71,8 @@ public class PacketFilterUpdate implements IMekanismPacket
|
|||
|
||||
dataStream.writeInt(object3D.dimensionId);
|
||||
|
||||
dataStream.writeInt(type);
|
||||
ArrayList data = new ArrayList();
|
||||
filter.write(data);
|
||||
PacketHandler.encode(data.toArray(), dataStream);
|
||||
}
|
||||
}
|
|
@ -97,6 +97,11 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
|
|||
delayTicks = 10;
|
||||
}
|
||||
}
|
||||
|
||||
if(playersUsing.size() > 0)
|
||||
{
|
||||
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getGenericPacket(new ArrayList())), Object3D.get(this), 50D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,19 +150,42 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
|
|||
{
|
||||
super.handlePacketData(dataStream);
|
||||
|
||||
isActive = dataStream.readBoolean();
|
||||
controlType = RedstoneControl.values()[dataStream.readInt()];
|
||||
int type = dataStream.readInt();
|
||||
|
||||
filters.clear();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
if(type == 0)
|
||||
{
|
||||
filters.add(TransporterFilter.readFromPacket(dataStream));
|
||||
isActive = dataStream.readBoolean();
|
||||
controlType = RedstoneControl.values()[dataStream.readInt()];
|
||||
|
||||
filters.clear();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
{
|
||||
filters.add(TransporterFilter.readFromPacket(dataStream));
|
||||
}
|
||||
|
||||
MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
else if(type == 1)
|
||||
{
|
||||
isActive = dataStream.readBoolean();
|
||||
controlType = RedstoneControl.values()[dataStream.readInt()];
|
||||
|
||||
MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
else if(type == 2)
|
||||
{
|
||||
filters.clear();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
{
|
||||
filters.add(TransporterFilter.readFromPacket(dataStream));
|
||||
}
|
||||
}
|
||||
|
||||
MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -165,8 +193,40 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
|
|||
{
|
||||
super.getNetworkedData(data);
|
||||
|
||||
data.add(0);
|
||||
|
||||
data.add(isActive);
|
||||
data.add(controlType.ordinal());
|
||||
|
||||
data.add(filters.size());
|
||||
|
||||
for(TransporterFilter filter : filters)
|
||||
{
|
||||
filter.write(data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public ArrayList getGenericPacket(ArrayList data)
|
||||
{
|
||||
super.getNetworkedData(data);
|
||||
|
||||
data.add(1);
|
||||
|
||||
data.add(isActive);
|
||||
data.add(controlType.ordinal());
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList getFilterPacket(ArrayList data)
|
||||
{
|
||||
super.getNetworkedData(data);
|
||||
|
||||
data.add(2);
|
||||
|
||||
data.add(filters.size());
|
||||
|
||||
for(TransporterFilter filter : filters)
|
||||
|
@ -206,7 +266,7 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
|
|||
{
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())), Object3D.get(this), 50D);
|
||||
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getFilterPacket(new ArrayList())), Object3D.get(this), 50D);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,12 @@ public class ItemStackFilter extends TransporterFilter
|
|||
{
|
||||
super.write(nbtTags);
|
||||
|
||||
nbtTags.setInteger("type", 0);
|
||||
itemType.writeToNBT(nbtTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NBTTagCompound nbtTags)
|
||||
protected void read(NBTTagCompound nbtTags)
|
||||
{
|
||||
super.read(nbtTags);
|
||||
|
||||
|
@ -37,6 +38,8 @@ public class ItemStackFilter extends TransporterFilter
|
|||
@Override
|
||||
public void write(ArrayList data)
|
||||
{
|
||||
data.add(0);
|
||||
|
||||
super.write(data);
|
||||
|
||||
data.add(itemType.itemID);
|
||||
|
@ -45,7 +48,7 @@ public class ItemStackFilter extends TransporterFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput dataStream)
|
||||
protected void read(ByteArrayDataInput dataStream)
|
||||
{
|
||||
super.read(dataStream);
|
||||
|
||||
|
|
|
@ -57,11 +57,12 @@ public class OreDictFilter extends TransporterFilter
|
|||
{
|
||||
super.write(nbtTags);
|
||||
|
||||
nbtTags.setInteger("type", 1);
|
||||
nbtTags.setString("oreDictName", oreDictName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NBTTagCompound nbtTags)
|
||||
protected void read(NBTTagCompound nbtTags)
|
||||
{
|
||||
super.read(nbtTags);
|
||||
|
||||
|
@ -71,13 +72,15 @@ public class OreDictFilter extends TransporterFilter
|
|||
@Override
|
||||
public void write(ArrayList data)
|
||||
{
|
||||
data.add(1);
|
||||
|
||||
super.write(data);
|
||||
|
||||
data.add(oreDictName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput dataStream)
|
||||
protected void read(ByteArrayDataInput dataStream)
|
||||
{
|
||||
super.read(dataStream);
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package mekanism.common.transporter;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.common.Teleporter.Code;
|
||||
import mekanism.common.util.TransporterUtils;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -24,7 +23,7 @@ public class TransporterFilter
|
|||
nbtTags.setInteger("color", TransporterUtils.colors.indexOf(color));
|
||||
}
|
||||
|
||||
public void read(NBTTagCompound nbtTags)
|
||||
protected void read(NBTTagCompound nbtTags)
|
||||
{
|
||||
color = TransporterUtils.colors.get(nbtTags.getInteger("color"));
|
||||
}
|
||||
|
@ -34,14 +33,25 @@ public class TransporterFilter
|
|||
data.add(TransporterUtils.colors.indexOf(color));
|
||||
}
|
||||
|
||||
public void read(ByteArrayDataInput dataStream)
|
||||
protected void read(ByteArrayDataInput dataStream)
|
||||
{
|
||||
color = TransporterUtils.colors.get(dataStream.readInt());
|
||||
}
|
||||
|
||||
public static TransporterFilter readFromNBT(NBTTagCompound nbtTags)
|
||||
{
|
||||
TransporterFilter filter = new TransporterFilter();
|
||||
int type = nbtTags.getInteger("type");
|
||||
|
||||
TransporterFilter filter = null;
|
||||
|
||||
if(type == 0)
|
||||
{
|
||||
filter = new ItemStackFilter();
|
||||
}
|
||||
else {
|
||||
filter = new OreDictFilter();
|
||||
}
|
||||
|
||||
filter.read(nbtTags);
|
||||
|
||||
return filter;
|
||||
|
@ -49,7 +59,19 @@ public class TransporterFilter
|
|||
|
||||
public static TransporterFilter readFromPacket(ByteArrayDataInput dataStream)
|
||||
{
|
||||
TransporterFilter filter = new TransporterFilter();
|
||||
int type = dataStream.readInt();
|
||||
|
||||
TransporterFilter filter = null;
|
||||
|
||||
if(type == 0)
|
||||
{
|
||||
filter = new ItemStackFilter();
|
||||
}
|
||||
else if(type == 1)
|
||||
{
|
||||
filter = new OreDictFilter();
|
||||
}
|
||||
|
||||
filter.read(dataStream);
|
||||
|
||||
return filter;
|
||||
|
|
Loading…
Add table
Reference in a new issue