67 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package net.minecraft.network.protocol.game;
 | |
| 
 | |
| import net.minecraft.network.FriendlyByteBuf;
 | |
| import net.minecraft.network.codec.StreamCodec;
 | |
| import net.minecraft.network.protocol.Packet;
 | |
| import net.minecraft.network.protocol.PacketType;
 | |
| import net.minecraft.world.entity.Entity;
 | |
| import net.minecraft.world.entity.vehicle.MinecartCommandBlock;
 | |
| import net.minecraft.world.level.BaseCommandBlock;
 | |
| import net.minecraft.world.level.Level;
 | |
| import org.jetbrains.annotations.Nullable;
 | |
| 
 | |
| public class ServerboundSetCommandMinecartPacket implements Packet<ServerGamePacketListener> {
 | |
| 	public static final StreamCodec<FriendlyByteBuf, ServerboundSetCommandMinecartPacket> STREAM_CODEC = Packet.codec(
 | |
| 		ServerboundSetCommandMinecartPacket::write, ServerboundSetCommandMinecartPacket::new
 | |
| 	);
 | |
| 	private final int entity;
 | |
| 	private final String command;
 | |
| 	private final boolean trackOutput;
 | |
| 
 | |
| 	public ServerboundSetCommandMinecartPacket(int entity, String command, boolean trackOutput) {
 | |
| 		this.entity = entity;
 | |
| 		this.command = command;
 | |
| 		this.trackOutput = trackOutput;
 | |
| 	}
 | |
| 
 | |
| 	private ServerboundSetCommandMinecartPacket(FriendlyByteBuf buffer) {
 | |
| 		this.entity = buffer.readVarInt();
 | |
| 		this.command = buffer.readUtf();
 | |
| 		this.trackOutput = buffer.readBoolean();
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Writes the raw packet data to the data stream.
 | |
| 	 */
 | |
| 	private void write(FriendlyByteBuf buffer) {
 | |
| 		buffer.writeVarInt(this.entity);
 | |
| 		buffer.writeUtf(this.command);
 | |
| 		buffer.writeBoolean(this.trackOutput);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public PacketType<ServerboundSetCommandMinecartPacket> type() {
 | |
| 		return GamePacketTypes.SERVERBOUND_SET_COMMAND_MINECART;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Passes this Packet on to the NetHandler for processing.
 | |
| 	 */
 | |
| 	public void handle(ServerGamePacketListener handler) {
 | |
| 		handler.handleSetCommandMinecart(this);
 | |
| 	}
 | |
| 
 | |
| 	@Nullable
 | |
| 	public BaseCommandBlock getCommandBlock(Level level) {
 | |
| 		Entity entity = level.getEntity(this.entity);
 | |
| 		return entity instanceof MinecartCommandBlock ? ((MinecartCommandBlock)entity).getCommandBlock() : null;
 | |
| 	}
 | |
| 
 | |
| 	public String getCommand() {
 | |
| 		return this.command;
 | |
| 	}
 | |
| 
 | |
| 	public boolean isTrackOutput() {
 | |
| 		return this.trackOutput;
 | |
| 	}
 | |
| }
 |