package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import javax.annotation.Nullable;
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 java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;

public class ServerboundSetCommandMinecartPacket implements Packet<ServerGamePacketListener> {
    private int entity;
    private String command;
    private boolean trackOutput;
    
    public ServerboundSetCommandMinecartPacket() {
    }
    
    public ServerboundSetCommandMinecartPacket(final int integer, final String string, final boolean boolean3) {
        this.entity = integer;
        this.command = string;
        this.trackOutput = boolean3;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.entity = kv.readVarInt();
        this.command = kv.readUtf(32767);
        this.trackOutput = kv.readBoolean();
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeVarInt(this.entity);
        kv.writeUtf(this.command);
        kv.writeBoolean(this.trackOutput);
    }
    
    @Override
    public void handle(final ServerGamePacketListener pl) {
        pl.handleSetCommandMinecart(this);
    }
    
    @Nullable
    public BaseCommandBlock getCommandBlock(final Level bjw) {
        final Entity akq3 = bjw.getEntity(this.entity);
        if (akq3 instanceof MinecartCommandBlock) {
            return ((MinecartCommandBlock)akq3).getCommandBlock();
        }
        return null;
    }
    
    public String getCommand() {
        return this.command;
    }
    
    public boolean isTrackOutput() {
        return this.trackOutput;
    }
}
