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;
|
|
|
|
|
2014-08-05 05:33:26 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2014-01-05 09:39:48 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.Container;
|
2014-05-26 10:26:37 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
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-08-05 05:33:26 +02:00
|
|
|
import appeng.client.gui.implementations.GuiCraftingCPU;
|
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-06-29 11:06:07 +02:00
|
|
|
import appeng.container.implementations.ContainerCraftConfirm;
|
2014-06-28 07:20:12 +02:00
|
|
|
import appeng.container.implementations.ContainerCraftingCPU;
|
2014-08-05 05:33:26 +02:00
|
|
|
import appeng.container.implementations.ContainerCraftingStatus;
|
2014-01-05 09:39:48 +01:00
|
|
|
import appeng.container.implementations.ContainerLevelEmitter;
|
2014-08-03 06:53:34 +02:00
|
|
|
import appeng.container.implementations.ContainerNetworkTool;
|
2014-04-10 06:51:08 +02:00
|
|
|
import appeng.container.implementations.ContainerPatternTerm;
|
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-05-26 10:26:37 +02:00
|
|
|
import appeng.helpers.IMouseWheelItem;
|
2014-02-09 02:34:52 +01:00
|
|
|
|
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-05-26 10:26:37 +02:00
|
|
|
if ( Name.equals( "Item" ) && player.getHeldItem() != null && player.getHeldItem().getItem() instanceof IMouseWheelItem )
|
|
|
|
{
|
|
|
|
ItemStack is = player.getHeldItem();
|
|
|
|
IMouseWheelItem si = (IMouseWheelItem) is.getItem();
|
|
|
|
si.onWheel( is, Value.equals( "WheelUp" ) );
|
2014-07-11 06:46:51 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
else if ( Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftingStatus )
|
|
|
|
{
|
|
|
|
ContainerCraftingStatus qk = (ContainerCraftingStatus) c;
|
|
|
|
qk.cycleCpu( Value.equals( "Next" ) );
|
|
|
|
return;
|
|
|
|
}
|
2014-07-11 06:46:51 +02:00
|
|
|
else if ( Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftConfirm )
|
|
|
|
{
|
|
|
|
ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
|
|
|
|
qk.cycleCpu( Value.equals( "Next" ) );
|
2014-05-26 10:26:37 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-29 11:06:07 +02:00
|
|
|
else if ( Name.equals( "Terminal.Start" ) && c instanceof ContainerCraftConfirm )
|
|
|
|
{
|
|
|
|
ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
|
|
|
|
qk.startJob();
|
|
|
|
return;
|
|
|
|
}
|
2014-06-28 07:20:12 +02:00
|
|
|
else if ( Name.equals( "TileCrafting.Cancel" ) && c instanceof ContainerCraftingCPU )
|
|
|
|
{
|
|
|
|
ContainerCraftingCPU qk = (ContainerCraftingCPU) c;
|
|
|
|
qk.cancelCrafting();
|
|
|
|
return;
|
|
|
|
}
|
2014-05-26 10:26:37 +02:00
|
|
|
else if ( Name.equals( "QuartzKnife.Name" ) && c instanceof ContainerQuartzKnife )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
|
|
|
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-04-10 06:51:08 +02:00
|
|
|
else if ( Name.startsWith( "PatternTerminal." ) && c instanceof ContainerPatternTerm )
|
|
|
|
{
|
|
|
|
ContainerPatternTerm cpt = (ContainerPatternTerm) c;
|
|
|
|
if ( Name.equals( "PatternTerminal.CraftMode" ) )
|
|
|
|
{
|
2014-07-02 03:43:08 +02:00
|
|
|
cpt.ct.setCraftingRecipe( Value.equals( "1" ) );
|
2014-04-10 06:51:08 +02:00
|
|
|
}
|
|
|
|
else if ( Name.equals( "PatternTerminal.Encode" ) )
|
|
|
|
{
|
|
|
|
cpt.encode();
|
|
|
|
}
|
2014-04-17 08:15:56 +02:00
|
|
|
else if ( Name.equals( "PatternTerminal.Clear" ) )
|
|
|
|
{
|
|
|
|
cpt.clear();
|
|
|
|
}
|
2014-04-10 06:51:08 +02:00
|
|
|
}
|
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" ) )
|
|
|
|
{
|
2014-04-07 01:05:09 +02:00
|
|
|
if ( Value.equals( "CopyMode" ) )
|
|
|
|
{
|
|
|
|
ccw.nextCopyMode();
|
|
|
|
}
|
|
|
|
else if ( Value.equals( "Partition" ) )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
ccw.partition();
|
|
|
|
}
|
|
|
|
else if ( Value.equals( "Clear" ) )
|
|
|
|
{
|
|
|
|
ccw.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( Name.equals( "CellWorkbench.Fuzzy" ) )
|
|
|
|
{
|
|
|
|
ccw.setFuzzy( FuzzyMode.valueOf( Value ) );
|
|
|
|
}
|
|
|
|
}
|
2014-08-03 06:53:34 +02:00
|
|
|
else if ( c instanceof ContainerNetworkTool )
|
|
|
|
{
|
|
|
|
if ( Name.equals( "NetworkTool" ) && Value.equals( "Toggle" ) )
|
|
|
|
{
|
|
|
|
((ContainerNetworkTool) c).toggleFacadeMode();
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
2014-07-16 05:26:12 +02:00
|
|
|
else if ( Name.startsWith( "SyncDat." ) )
|
|
|
|
{
|
|
|
|
((AEBaseContainer) c).stringSync( Integer.parseInt( Name.substring( 8 ) ), Value );
|
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
else if ( Name.equals( "CraftingStatus" ) && Value.equals( "Clear" ) )
|
|
|
|
{
|
|
|
|
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
|
|
|
if ( gs instanceof GuiCraftingCPU )
|
|
|
|
((GuiCraftingCPU) gs).clearItems();
|
|
|
|
return;
|
|
|
|
}
|
2014-03-15 07:58:21 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|