mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-18 14:15:12 +00:00
Started work on upgrading to 1.16.1. Not in a compilable state yet
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.network.server;
|
||||
|
||||
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.util.NBTUtil;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Queue an event on a {@link ServerComputer}.
|
||||
*
|
||||
* @see dan200.computercraft.shared.computer.core.ClientComputer#queueEvent(String)
|
||||
* @see ServerComputer#queueEvent(String)
|
||||
*/
|
||||
public class QueueEventServerMessage extends ComputerServerMessage
|
||||
{
|
||||
private String event;
|
||||
private Object[] args;
|
||||
|
||||
public QueueEventServerMessage( int instanceId, @Nonnull String event, @Nullable Object[] args )
|
||||
{
|
||||
super( instanceId );
|
||||
this.event = event;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public QueueEventServerMessage()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes( @Nonnull PacketByteBuf buf )
|
||||
{
|
||||
super.toBytes( buf );
|
||||
buf.writeString( event );
|
||||
buf.writeCompoundTag( args == null ? null : NBTUtil.encodeObjects( args ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes( @Nonnull PacketByteBuf buf )
|
||||
{
|
||||
super.fromBytes( buf );
|
||||
event = buf.readString( Short.MAX_VALUE );
|
||||
|
||||
CompoundTag args = buf.readCompoundTag();
|
||||
this.args = args == null ? null : NBTUtil.decodeObjects( args );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handle( @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
|
||||
{
|
||||
computer.queueEvent( event, args );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user