Applied-Energistics-2-tiler.../core/sync/packets/PacketValueConfig.java
AlgorithmX2 01bf88061d Merge branch 'master' of https://bitbucket.org/AlgorithmX2/appliedenergistics2 into rv1
Conflicts:
	container/implementations/ContainerStorageBus.java
	core/sync/packets/PacketValueConfig.java
2014-05-22 18:49:02 -05:00

205 lines
5.2 KiB
Java

package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import appeng.api.config.FuzzyMode;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigureableObject;
import appeng.container.AEBaseContainer;
import appeng.container.implementations.ContainerCellWorkbench;
import appeng.container.implementations.ContainerLevelEmitter;
import appeng.container.implementations.ContainerPatternTerm;
import appeng.container.implementations.ContainerPriority;
import appeng.container.implementations.ContainerQuartzKnife;
import appeng.container.implementations.ContainerSecurity;
import appeng.container.implementations.ContainerStorageBus;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketValueConfig extends AppEngPacket
{
final public String Name;
final public String Value;
// automatic.
public PacketValueConfig(ByteBuf stream) throws IOException {
DataInputStream dis = new DataInputStream( new ByteArrayInputStream( stream.array(), stream.readerIndex(), stream.readableBytes() ) );
Name = dis.readUTF();
Value = dis.readUTF();
// dis.close();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
Container c = player.openContainer;
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 )
{
ContainerSecurity sc = (ContainerSecurity) c;
sc.toggleSetting( Value, player );
return;
}
else if ( Name.equals( "PriorityHost.Priority" ) && c instanceof ContainerPriority )
{
ContainerPriority pc = (ContainerPriority) c;
pc.setPriority( Integer.parseInt( Value ), player );
return;
}
else if ( Name.equals( "LevelEmitter.Value" ) && c instanceof ContainerLevelEmitter )
{
ContainerLevelEmitter lvc = (ContainerLevelEmitter) c;
lvc.setLevel( Long.parseLong( Value ), player );
return;
}
else if ( Name.startsWith( "PatternTerminal." ) && c instanceof ContainerPatternTerm )
{
ContainerPatternTerm cpt = (ContainerPatternTerm) c;
if ( Name.equals( "PatternTerminal.CraftMode" ) )
{
cpt.ct.craftingMode = Value.equals( "1" );
}
else if ( Name.equals( "PatternTerminal.Encode" ) )
{
cpt.encode();
}
else if ( Name.equals( "PatternTerminal.Clear" ) )
{
cpt.clear();
}
}
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();
}
}
}
else if ( Name.startsWith( "CellWorkbench." ) && c instanceof ContainerCellWorkbench )
{
ContainerCellWorkbench ccw = (ContainerCellWorkbench) c;
if ( Name.equals( "CellWorkbench.Action" ) )
{
if ( Value.equals( "CopyMode" ) )
{
ccw.nextCopyMode();
}
else if ( Value.equals( "Partition" ) )
{
ccw.partition();
}
else if ( Value.equals( "Clear" ) )
{
ccw.clear();
}
}
else if ( Name.equals( "CellWorkbench.Fuzzy" ) )
{
ccw.setFuzzy( FuzzyMode.valueOf( Value ) );
}
}
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;
if ( Name.equals( "CustomName" ) && c instanceof AEBaseContainer )
{
((AEBaseContainer) c).customName = Value;
}
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;
}
}
}
}
// api
public PacketValueConfig(String Name, String Value) throws IOException {
this.Name = Name;
this.Value = Value;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream( bos );
dos.writeUTF( Name );
dos.writeUTF( Value );
// dos.close();
data.writeBytes( bos.toByteArray() );
configureWrite( data );
}
}