2014-01-05 09:39:48 +01:00
|
|
|
package appeng.core.sync.packets;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
|
|
2014-02-09 04:48:04 +01:00
|
|
|
import java.io.ByteArrayInputStream;
|
2014-02-09 04:41:49 +01:00
|
|
|
import java.io.ByteArrayOutputStream;
|
2014-01-05 09:39:48 +01:00
|
|
|
import java.io.DataInputStream;
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.Container;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.config.FuzzyMode;
|
2014-02-17 01:50:25 +01:00
|
|
|
import appeng.api.util.IConfigManager;
|
|
|
|
import appeng.api.util.IConfigureableObject;
|
2014-03-15 07:58:21 +01:00
|
|
|
import appeng.container.AEBaseContainer;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.container.implementations.ContainerCellWorkbench;
|
2014-01-05 09:39:48 +01:00
|
|
|
import appeng.container.implementations.ContainerLevelEmitter;
|
2014-01-26 07:44:50 +01:00
|
|
|
import appeng.container.implementations.ContainerPriority;
|
2014-03-07 04:02:15 +01:00
|
|
|
import appeng.container.implementations.ContainerQuartzKnife;
|
2014-02-01 06:37:27 +01:00
|
|
|
import appeng.container.implementations.ContainerSecurity;
|
2014-05-22 04:09:29 +02:00
|
|
|
import appeng.container.implementations.ContainerStorageBus;
|
2014-01-05 09:39:48 +01:00
|
|
|
import appeng.core.sync.AppEngPacket;
|
2014-02-09 02:34:52 +01:00
|
|
|
import appeng.core.sync.network.INetworkInfo;
|
|
|
|
|
2014-01-05 09:39:48 +01:00
|
|
|
public class PacketValueConfig extends AppEngPacket
|
|
|
|
{
|
|
|
|
|
|
|
|
final public String Name;
|
|
|
|
final public String Value;
|
|
|
|
|
|
|
|
// automatic.
|
2014-02-09 02:34:52 +01:00
|
|
|
public PacketValueConfig(ByteBuf stream) throws IOException {
|
2014-02-09 19:36:52 +01:00
|
|
|
DataInputStream dis = new DataInputStream( new ByteArrayInputStream( stream.array(), stream.readerIndex(), stream.readableBytes() ) );
|
2014-02-09 02:34:52 +01:00
|
|
|
Name = dis.readUTF();
|
|
|
|
Value = dis.readUTF();
|
2014-02-09 19:36:52 +01:00
|
|
|
// dis.close();
|
2014-01-05 09:39:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
|
2014-01-05 09:39:48 +01:00
|
|
|
{
|
|
|
|
Container c = player.openContainer;
|
|
|
|
|
2014-03-07 04:02:15 +01:00
|
|
|
if ( Name.equals( "QuartzKnife.Name" ) && c instanceof ContainerQuartzKnife )
|
|
|
|
{
|
|
|
|
ContainerQuartzKnife qk = (ContainerQuartzKnife) c;
|
|
|
|
qk.setName( Value );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ( Name.equals( "TileSecurity.ToggleOption" ) && c instanceof ContainerSecurity )
|
2014-02-01 06:37:27 +01:00
|
|
|
{
|
|
|
|
ContainerSecurity sc = (ContainerSecurity) c;
|
|
|
|
sc.toggleSetting( Value, player );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ( Name.equals( "PriorityHost.Priority" ) && c instanceof ContainerPriority )
|
2014-01-26 07:44:50 +01:00
|
|
|
{
|
|
|
|
ContainerPriority pc = (ContainerPriority) c;
|
|
|
|
pc.setPriority( Integer.parseInt( Value ), player );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ( Name.equals( "LevelEmitter.Value" ) && c instanceof ContainerLevelEmitter )
|
2014-01-05 09:39:48 +01:00
|
|
|
{
|
|
|
|
ContainerLevelEmitter lvc = (ContainerLevelEmitter) c;
|
2014-02-21 07:10:38 +01:00
|
|
|
lvc.setLevel( Long.parseLong( Value ), player );
|
2014-01-05 09:39:48 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-05-22 04:09:29 +02:00
|
|
|
else if ( Name.startsWith( "StorageBus." ) && c instanceof ContainerStorageBus )
|
|
|
|
{
|
|
|
|
ContainerStorageBus ccw = (ContainerStorageBus) c;
|
|
|
|
if ( Name.equals( "StorageBus.Action" ) )
|
|
|
|
{
|
|
|
|
if ( Value.equals( "Partition" ) )
|
|
|
|
{
|
|
|
|
ccw.partition();
|
|
|
|
}
|
|
|
|
else if ( Value.equals( "Clear" ) )
|
|
|
|
{
|
|
|
|
ccw.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
else if ( Name.startsWith( "CellWorkbench." ) && c instanceof ContainerCellWorkbench )
|
|
|
|
{
|
|
|
|
ContainerCellWorkbench ccw = (ContainerCellWorkbench) c;
|
|
|
|
if ( Name.equals( "CellWorkbench.Action" ) )
|
|
|
|
{
|
|
|
|
if ( Value.equals( "Partition" ) )
|
|
|
|
{
|
|
|
|
ccw.partition();
|
|
|
|
}
|
|
|
|
else if ( Value.equals( "Clear" ) )
|
|
|
|
{
|
|
|
|
ccw.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( Name.equals( "CellWorkbench.Fuzzy" ) )
|
|
|
|
{
|
|
|
|
ccw.setFuzzy( FuzzyMode.valueOf( Value ) );
|
|
|
|
}
|
|
|
|
}
|
2014-02-17 01:50:25 +01:00
|
|
|
else if ( c instanceof IConfigureableObject )
|
|
|
|
{
|
|
|
|
IConfigManager cm = ((IConfigureableObject) c).getConfigManager();
|
|
|
|
|
|
|
|
for (Enum e : cm.getSettings())
|
|
|
|
{
|
|
|
|
if ( e.name().equals( Name ) )
|
|
|
|
{
|
|
|
|
Enum def = cm.getSetting( e );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
cm.putSetting( e, Enum.valueOf( def.getClass(), Value ) );
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException err)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
|
|
|
|
{
|
|
|
|
Container c = player.openContainer;
|
|
|
|
|
2014-03-15 07:58:21 +01:00
|
|
|
if ( Name.equals( "CustomName" ) && c instanceof AEBaseContainer )
|
|
|
|
{
|
|
|
|
((AEBaseContainer) c).customName = Value;
|
|
|
|
}
|
|
|
|
else if ( c instanceof IConfigureableObject )
|
2014-02-17 01:50:25 +01:00
|
|
|
{
|
|
|
|
IConfigManager cm = ((IConfigureableObject) c).getConfigManager();
|
|
|
|
|
|
|
|
for (Enum e : cm.getSettings())
|
|
|
|
{
|
|
|
|
if ( e.name().equals( Name ) )
|
|
|
|
{
|
|
|
|
Enum def = cm.getSetting( e );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
cm.putSetting( e, Enum.valueOf( def.getClass(), Value ) );
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException err)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-05 09:39:48 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// api
|
|
|
|
public PacketValueConfig(String Name, String Value) throws IOException {
|
|
|
|
this.Name = Name;
|
|
|
|
this.Value = Value;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
ByteBuf data = Unpooled.buffer();
|
2014-01-05 09:39:48 +01:00
|
|
|
|
|
|
|
data.writeInt( getPacketID() );
|
|
|
|
|
2014-02-09 04:41:49 +01:00
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
2014-02-09 02:34:52 +01:00
|
|
|
DataOutputStream dos = new DataOutputStream( bos );
|
2014-02-09 19:36:52 +01:00
|
|
|
dos.writeUTF( Name );
|
|
|
|
dos.writeUTF( Value );
|
|
|
|
// dos.close();
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2014-02-09 04:41:49 +01:00
|
|
|
data.writeBytes( bos.toByteArray() );
|
2014-02-09 02:34:52 +01:00
|
|
|
|
|
|
|
configureWrite( data );
|
2014-01-05 09:39:48 +01:00
|
|
|
}
|
|
|
|
}
|