mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Preliminary 1.21 Support
This commit is contained in:
parent
7bd213a154
commit
f83e7c5707
18 changed files with 588 additions and 55 deletions
|
|
@ -0,0 +1,99 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components.Subcomponents._1_21;
|
||||
|
||||
public class SoundEventSubComponent(DataTypes dataTypes, SubComponentRegistry subComponentRegistry) : SubComponent(dataTypes, subComponentRegistry)
|
||||
{
|
||||
public int Type { get; set; }
|
||||
public string? SoundName { get; set; }
|
||||
public bool HasFixedRange { get; set; }
|
||||
public float FixedRange { get; set; }
|
||||
|
||||
protected override void Parse(Queue<byte> data)
|
||||
{
|
||||
Type = dataTypes.ReadNextVarInt(data);
|
||||
|
||||
if (Type != 0) return;
|
||||
|
||||
SoundName = dataTypes.ReadNextString(data);
|
||||
HasFixedRange = dataTypes.ReadNextBool(data);
|
||||
|
||||
if (HasFixedRange)
|
||||
FixedRange = dataTypes.ReadNextFloat(data);
|
||||
}
|
||||
|
||||
public override Queue<byte> Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddRange(DataTypes.GetVarInt(Type));
|
||||
|
||||
if (Type != 0) return new Queue<byte>(data);
|
||||
|
||||
if (string.IsNullOrEmpty(SoundName?.Trim()))
|
||||
throw new ArgumentNullException($"Can not serialize SoundEventSubComponent due to SoundName being null or empty!");
|
||||
|
||||
data.AddRange(DataTypes.GetString(SoundName));
|
||||
data.AddRange(DataTypes.GetBool(HasFixedRange));
|
||||
|
||||
if(HasFixedRange)
|
||||
data.AddRange(DataTypes.GetFloat(FixedRange));
|
||||
|
||||
return new Queue<byte>(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,4 +11,5 @@ public abstract class SubComponents
|
|||
public const string Details = "Details";
|
||||
public const string Rule = "Rule";
|
||||
public const string FireworkExplosion = "FireworkExplosion";
|
||||
public const string SoundEvent = "SoundEvent";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue