Minecraft-Console-Client/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_21/JukeBoxPlayableComponent.cs
copilot-swe-agent[bot] 640a4e39b7 Fix CS9107 warnings: use base class properties instead of captured primary constructor parameters
Replace lowercase primary constructor parameter references (dataTypes.,
subComponentRegistry., itemPalette.) with PascalCase base class property
references (DataTypes., SubComponentRegistry., ItemPalette.) in method
bodies of all StructuredComponent and SubComponent subclasses.

This eliminates CS9107 warnings where subclass primary constructor
parameters shadow the base class properties they are assigned to.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-24 01:16:05 +00:00

99 lines
No EOL
3.6 KiB
C#

using System;
using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_21;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_21;
public class JukeBoxPlayableComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
public bool DirectMode { get; set; }
public string? SongName { get; set; }
public int? SongType { get; set; }
public SoundEventSubComponent? SoundEvent { get; set; }
public string? Description { get; set; }
public float? Duration { get; set; }
public int? Output { get; set; }
public bool ShowTooltip { get; set; }
public override void Parse(Queue<byte> data)
{
DirectMode = DataTypes.ReadNextBool(data);
if (!DirectMode)
SongName = DataTypes.ReadNextString(data);
if (DirectMode)
{
SongType = DataTypes.ReadNextVarInt(data);
if (SongType == 0)
{
SoundEvent =
(SoundEventSubComponent)SubComponentRegistry.ParseSubComponent(SubComponents.SoundEvent, data);
Description = DataTypes.ReadNextString(data);
Duration = DataTypes.ReadNextFloat(data);
Output = DataTypes.ReadNextVarInt(data);
}
}
ShowTooltip = DataTypes.ReadNextBool(data);
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
data.AddRange(DataTypes.GetBool(DirectMode));
if (!DirectMode)
{
if (string.IsNullOrEmpty(SongName?.Trim()))
throw new ArgumentNullException($"Can not serialize JukeBoxPlayableComponent due to SongName being null or empty!");
data.AddRange(DataTypes.GetString(SongName));
}
if (DirectMode)
{
if(SongType is null)
throw new ArgumentNullException($"Can not serialize JukeBoxPlayableComponent due to SongType being null!");
data.AddRange(DataTypes.GetVarInt((int)SongType));
if (SongType == 0)
{
if (SoundEvent is null)
throw new ArgumentNullException(
$"Can not serialize JukeBoxPlayableComponent due to SoundEvent being null");
data.AddRange(SoundEvent.Serialize());
if (string.IsNullOrEmpty(Description?.Trim()))
throw new ArgumentNullException(
$"Can not serialize JukeBoxPlayableComponent due to Description being null or empty!");
data.AddRange(DataTypes.GetString(Description));
if (Duration is null)
throw new ArgumentNullException(
$"Can not serialize JukeBoxPlayableComponent due to Duration being null!");
data.AddRange(DataTypes.GetFloat((float)Duration));
if (Output is null)
throw new ArgumentNullException(
$"Can not serialize JukeBoxPlayableComponent due to Description being null!");
data.AddRange(DataTypes.GetVarInt((int)Output));
}
}
data.AddRange(DataTypes.GetBool(ShowTooltip));
return new Queue<byte>(data);
}
}