Edit/delete filter packets

This commit is contained in:
Aidan C. Brady 2013-10-27 17:47:17 -04:00
parent 5e7c01c1af
commit a500d0f592
6 changed files with 143 additions and 16 deletions

View file

@ -3,10 +3,10 @@ package mekanism.client.gui;
import mekanism.api.EnumColor; import mekanism.api.EnumColor;
import mekanism.api.Object3D; import mekanism.api.Object3D;
import mekanism.client.render.MekanismRenderer; import mekanism.client.render.MekanismRenderer;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler; import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission; import mekanism.common.PacketHandler.Transmission;
import mekanism.common.inventory.container.ContainerFilter; import mekanism.common.inventory.container.ContainerFilter;
import mekanism.common.network.PacketEditFilter;
import mekanism.common.network.PacketLogisticalSorterGui; import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket; import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.network.PacketNewFilter; import mekanism.common.network.PacketNewFilter;
@ -78,16 +78,27 @@ public class GuiItemStackFilter extends GuiMekanism
if(guibutton.id == 0) if(guibutton.id == 0)
{ {
if(filter.itemType != null) if(filter.itemType != null)
{
if(isNew)
{ {
PacketHandler.sendPacket(Transmission.SERVER, new PacketNewFilter().setParams(Object3D.get(tileEntity), filter)); PacketHandler.sendPacket(Transmission.SERVER, new PacketNewFilter().setParams(Object3D.get(tileEntity), filter));
}
else {
PacketHandler.sendPacket(Transmission.SERVER, new PacketEditFilter().setParams(Object3D.get(tileEntity), false, filter));
}
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, 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 { else {
status = EnumColor.DARK_RED + "No item"; status = EnumColor.DARK_RED + "No item";
ticker = 20; ticker = 20;
} }
} }
else if(guibutton.id == 1)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketEditFilter().setParams(Object3D.get(tileEntity), true, filter));
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Object3D.get(tileEntity), 0));
}
} }
@Override @Override

View file

@ -10,6 +10,7 @@ import mekanism.common.Mekanism;
import mekanism.common.PacketHandler; import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission; import mekanism.common.PacketHandler.Transmission;
import mekanism.common.inventory.container.ContainerFilter; import mekanism.common.inventory.container.ContainerFilter;
import mekanism.common.network.PacketEditFilter;
import mekanism.common.network.PacketLogisticalSorterGui; import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket; import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.network.PacketNewFilter; import mekanism.common.network.PacketNewFilter;
@ -121,16 +122,27 @@ public class GuiOreDictFilter extends GuiMekanism
if(guibutton.id == 0) if(guibutton.id == 0)
{ {
if(filter.oreDictName != null && !filter.oreDictName.isEmpty()) if(filter.oreDictName != null && !filter.oreDictName.isEmpty())
{
if(isNew)
{ {
PacketHandler.sendPacket(Transmission.SERVER, new PacketNewFilter().setParams(Object3D.get(tileEntity), filter)); PacketHandler.sendPacket(Transmission.SERVER, new PacketNewFilter().setParams(Object3D.get(tileEntity), filter));
}
else {
PacketHandler.sendPacket(Transmission.SERVER, new PacketEditFilter().setParams(Object3D.get(tileEntity), false, filter));
}
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, 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 { else {
status = EnumColor.DARK_RED + "No key"; status = EnumColor.DARK_RED + "No key";
ticker = 20; ticker = 20;
} }
} }
else if(guibutton.id == 1)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketEditFilter().setParams(Object3D.get(tileEntity), true, filter));
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Object3D.get(tileEntity), 0));
}
} }
@Override @Override

View file

@ -43,6 +43,16 @@ public class HashList<T> implements Iterable<T>
} }
} }
public void remove(int index)
{
list.remove(index);
}
public void remove(T obj)
{
list.remove(obj);
}
public int indexOf(T obj) public int indexOf(T obj)
{ {
return list.indexOf(obj); return list.indexOf(obj);

View file

@ -57,6 +57,7 @@ import mekanism.common.network.PacketConfiguratorState;
import mekanism.common.network.PacketControlPanel; import mekanism.common.network.PacketControlPanel;
import mekanism.common.network.PacketDataRequest; import mekanism.common.network.PacketDataRequest;
import mekanism.common.network.PacketDigitUpdate; import mekanism.common.network.PacketDigitUpdate;
import mekanism.common.network.PacketEditFilter;
import mekanism.common.network.PacketElectricBowState; import mekanism.common.network.PacketElectricBowState;
import mekanism.common.network.PacketElectricChest; import mekanism.common.network.PacketElectricChest;
import mekanism.common.network.PacketLogisticalSorterGui; import mekanism.common.network.PacketLogisticalSorterGui;
@ -1150,6 +1151,7 @@ public class Mekanism
PacketHandler.registerPacket(PacketWalkieTalkieState.class); PacketHandler.registerPacket(PacketWalkieTalkieState.class);
PacketHandler.registerPacket(PacketLogisticalSorterGui.class); PacketHandler.registerPacket(PacketLogisticalSorterGui.class);
PacketHandler.registerPacket(PacketNewFilter.class); PacketHandler.registerPacket(PacketNewFilter.class);
PacketHandler.registerPacket(PacketEditFilter.class);
//Donators //Donators
donators.add("mrgreaper"); donators.add("mrgreaper");

View file

@ -0,0 +1,93 @@
package mekanism.common.network;
import java.io.DataOutputStream;
import java.util.ArrayList;
import mekanism.api.Object3D;
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;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.FMLCommonHandler;
public class PacketEditFilter implements IMekanismPacket
{
public Object3D object3D;
public TransporterFilter edited;
public boolean delete;
@Override
public String getName()
{
return "EditFilter";
}
@Override
public IMekanismPacket setParams(Object... data)
{
object3D = (Object3D)data[0];
delete = (Boolean)data[1];
edited = (TransporterFilter)data[2];
return this;
}
@Override
public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception
{
object3D = new Object3D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
delete = dataStream.readBoolean();
edited = TransporterFilter.readFromPacket(dataStream);
World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(object3D.dimensionId);
if(worldServer != null && object3D.getTileEntity(worldServer) instanceof TileEntityLogisticalSorter)
{
TileEntityLogisticalSorter sorter = (TileEntityLogisticalSorter)object3D.getTileEntity(worldServer);
TransporterFilter filter = TransporterFilter.readFromPacket(dataStream);
if(!sorter.filters.contains(filter))
{
return;
}
int index = sorter.filters.indexOf(filter);
sorter.filters.remove(index);
if(!delete)
{
sorter.filters.add(index, edited);
}
for(EntityPlayer iterPlayer : sorter.playersUsing)
{
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketTileEntity().setParams(Object3D.get(sorter), sorter.getFilterPacket(new ArrayList())), iterPlayer);
}
}
}
@Override
public void write(DataOutputStream dataStream) throws Exception
{
dataStream.writeInt(object3D.xCoord);
dataStream.writeInt(object3D.yCoord);
dataStream.writeInt(object3D.zCoord);
dataStream.writeInt(object3D.dimensionId);
dataStream.writeBoolean(delete);
ArrayList data = new ArrayList();
edited.write(data);
PacketHandler.encode(data.toArray(), dataStream);
}
}

View file

@ -24,7 +24,7 @@ public class PacketNewFilter implements IMekanismPacket
@Override @Override
public String getName() public String getName()
{ {
return "FilterUpdate"; return "NewFilter";
} }
@Override @Override
@ -39,22 +39,21 @@ public class PacketNewFilter implements IMekanismPacket
@Override @Override
public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception
{ {
int x = dataStream.readInt(); object3D = new Object3D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
int y = dataStream.readInt();
int z = dataStream.readInt();
int id = dataStream.readInt(); World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(object3D.dimensionId);
World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(id); if(worldServer != null && object3D.getTileEntity(worldServer) instanceof TileEntityLogisticalSorter)
if(worldServer != null && worldServer.getBlockTileEntity(x, y, z) instanceof TileEntityLogisticalSorter)
{ {
TileEntityLogisticalSorter sorter = (TileEntityLogisticalSorter)worldServer.getBlockTileEntity(x, y, z); TileEntityLogisticalSorter sorter = (TileEntityLogisticalSorter)object3D.getTileEntity(worldServer);
TransporterFilter filter = TransporterFilter.readFromPacket(dataStream); TransporterFilter filter = TransporterFilter.readFromPacket(dataStream);
sorter.filters.add(filter); //sorter.filters.add(filter);
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketTileEntity().setParams(Object3D.get(sorter), sorter.getFilterPacket(new ArrayList())), player); for(EntityPlayer iterPlayer : sorter.playersUsing)
{
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketTileEntity().setParams(Object3D.get(sorter), sorter.getFilterPacket(new ArrayList())), iterPlayer);
}
} }
} }