Edit/delete filter packets
This commit is contained in:
parent
5e7c01c1af
commit
a500d0f592
6 changed files with 143 additions and 16 deletions
|
@ -3,10 +3,10 @@ package mekanism.client.gui;
|
|||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.client.render.MekanismRenderer;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.inventory.container.ContainerFilter;
|
||||
import mekanism.common.network.PacketEditFilter;
|
||||
import mekanism.common.network.PacketLogisticalSorterGui;
|
||||
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
|
||||
import mekanism.common.network.PacketNewFilter;
|
||||
|
@ -78,16 +78,27 @@ public class GuiItemStackFilter extends GuiMekanism
|
|||
if(guibutton.id == 0)
|
||||
{
|
||||
if(filter.itemType != null)
|
||||
{
|
||||
if(isNew)
|
||||
{
|
||||
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));
|
||||
mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
}
|
||||
else {
|
||||
status = EnumColor.DARK_RED + "No item";
|
||||
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
|
||||
|
|
|
@ -10,6 +10,7 @@ import mekanism.common.Mekanism;
|
|||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.inventory.container.ContainerFilter;
|
||||
import mekanism.common.network.PacketEditFilter;
|
||||
import mekanism.common.network.PacketLogisticalSorterGui;
|
||||
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
|
||||
import mekanism.common.network.PacketNewFilter;
|
||||
|
@ -121,16 +122,27 @@ public class GuiOreDictFilter extends GuiMekanism
|
|||
if(guibutton.id == 0)
|
||||
{
|
||||
if(filter.oreDictName != null && !filter.oreDictName.isEmpty())
|
||||
{
|
||||
if(isNew)
|
||||
{
|
||||
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));
|
||||
mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
}
|
||||
else {
|
||||
status = EnumColor.DARK_RED + "No key";
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
return list.indexOf(obj);
|
||||
|
|
|
@ -57,6 +57,7 @@ import mekanism.common.network.PacketConfiguratorState;
|
|||
import mekanism.common.network.PacketControlPanel;
|
||||
import mekanism.common.network.PacketDataRequest;
|
||||
import mekanism.common.network.PacketDigitUpdate;
|
||||
import mekanism.common.network.PacketEditFilter;
|
||||
import mekanism.common.network.PacketElectricBowState;
|
||||
import mekanism.common.network.PacketElectricChest;
|
||||
import mekanism.common.network.PacketLogisticalSorterGui;
|
||||
|
@ -1150,6 +1151,7 @@ public class Mekanism
|
|||
PacketHandler.registerPacket(PacketWalkieTalkieState.class);
|
||||
PacketHandler.registerPacket(PacketLogisticalSorterGui.class);
|
||||
PacketHandler.registerPacket(PacketNewFilter.class);
|
||||
PacketHandler.registerPacket(PacketEditFilter.class);
|
||||
|
||||
//Donators
|
||||
donators.add("mrgreaper");
|
||||
|
|
93
common/mekanism/common/network/PacketEditFilter.java
Normal file
93
common/mekanism/common/network/PacketEditFilter.java
Normal 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);
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ public class PacketNewFilter implements IMekanismPacket
|
|||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "FilterUpdate";
|
||||
return "NewFilter";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,22 +39,21 @@ public class PacketNewFilter 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();
|
||||
object3D = new Object3D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
|
||||
|
||||
int id = dataStream.readInt();
|
||||
World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(object3D.dimensionId);
|
||||
|
||||
World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(id);
|
||||
|
||||
if(worldServer != null && worldServer.getBlockTileEntity(x, y, z) instanceof TileEntityLogisticalSorter)
|
||||
if(worldServer != null && object3D.getTileEntity(worldServer) instanceof TileEntityLogisticalSorter)
|
||||
{
|
||||
TileEntityLogisticalSorter sorter = (TileEntityLogisticalSorter)worldServer.getBlockTileEntity(x, y, z);
|
||||
TileEntityLogisticalSorter sorter = (TileEntityLogisticalSorter)object3D.getTileEntity(worldServer);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue