Applied-Energistics-2-tiler.../core/sync/packets/PacketConfigButton.java

57 lines
1.7 KiB
Java
Raw Normal View History

package appeng.core.sync.packets;
2014-02-09 02:34:52 +01:00
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import appeng.api.config.Settings;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigureableObject;
import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
2014-02-09 02:34:52 +01:00
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
public class PacketConfigButton extends AppEngPacket
{
final public Settings option;
final public boolean rotationDirection;
// automatic.
2014-02-09 02:34:52 +01:00
public PacketConfigButton(ByteBuf stream) throws IOException {
option = Settings.values()[stream.readInt()];
rotationDirection = stream.readBoolean();
}
@Override
2014-02-09 02:34:52 +01:00
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
AEBaseContainer aebc = (AEBaseContainer) sender.openContainer;
if ( aebc.getTarget() instanceof IConfigureableObject )
{
IConfigManager cm = ((IConfigureableObject) aebc.getTarget()).getConfigManager();
Enum newState = Platform.rotateEnum( cm.getSetting( option ), rotationDirection, option.getPossibleValues() );
cm.putSetting( option, newState );
}
}
// api
public PacketConfigButton(Settings option, boolean rotationDirection) throws IOException {
this.option = option;
this.rotationDirection = rotationDirection;
2014-02-09 02:34:52 +01:00
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( option.ordinal() );
data.writeBoolean( rotationDirection );
2014-02-09 02:34:52 +01:00
configureWrite( data );
}
}