Formatted the code and removed logs from Auto Attack

This commit is contained in:
Anon 2026-06-04 11:42:41 +02:00
parent a4ff7ae438
commit c6ca3dc13d
117 changed files with 602 additions and 585 deletions

View file

@ -12,7 +12,7 @@ public class AttributeSubComponent(DataTypes dataTypes, SubComponentRegistry sub
public double Value { get; set; }
public int Operation { get; set; }
public int Slot { get; set; }
protected override void Parse(Queue<byte> data)
{
TypeId = DataTypes.ReadNextVarInt(data);
@ -28,10 +28,10 @@ public class AttributeSubComponent(DataTypes dataTypes, SubComponentRegistry sub
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(TypeId));
data.AddRange(DataTypes.GetUUID(Uuid));
if (string.IsNullOrEmpty(Name?.Trim()))
throw new ArgumentNullException($"Can not serialize AttributeSubComponent due to Name being null or empty!");
data.AddRange(DataTypes.GetString(Name));
data.AddRange(DataTypes.GetDouble(Value));
data.AddRange(DataTypes.GetVarInt(Operation));

View file

@ -12,7 +12,7 @@ public class BlockPredicateSubcomponent(DataTypes dataTypes, SubComponentRegistr
public List<PropertySubComponent>? Properties { get; set; }
public bool HasNbt { get; set; }
public Dictionary<string, object>? Nbt { get; set; }
protected override void Parse(Queue<byte> data)
{
HasBlocks = DataTypes.ReadNextBool(data);
@ -31,7 +31,7 @@ public class BlockPredicateSubcomponent(DataTypes dataTypes, SubComponentRegistr
}
HasNbt = DataTypes.ReadNextBool(data);
if (HasNbt)
Nbt = DataTypes.ReadNextNbt(data);
}
@ -39,22 +39,22 @@ public class BlockPredicateSubcomponent(DataTypes dataTypes, SubComponentRegistr
public override Queue<byte> Serialize()
{
var data = new List<byte>();
// Block Sets
data.AddRange(DataTypes.GetBool(HasBlocks));
if (HasBlocks)
{
if(BlockSet is null)
if (BlockSet is null)
throw new ArgumentNullException($"Can not serialize a BlockPredicate when the BlockSet is empty but HasBlocks is true!");
data.AddRange(BlockSet.Serialize());
}
// Properties
data.AddRange(DataTypes.GetBool(HasProperities));
if (HasProperities)
{
if(Properties is null || Properties.Count == 0)
if (Properties is null || Properties.Count == 0)
throw new ArgumentNullException($"Can not serialize a BlockPredicate when the Properties is empty but HasProperties is true!");
data.AddRange(DataTypes.GetVarInt(Properties.Count));
@ -66,12 +66,12 @@ public class BlockPredicateSubcomponent(DataTypes dataTypes, SubComponentRegistr
data.AddRange(DataTypes.GetBool(HasNbt));
if (HasNbt)
{
if(Nbt is null)
if (Nbt is null)
throw new ArgumentNullException($"Can not serialize a BlockPredicate when the Nbt is empty but HasNbt is true!");
data.AddRange(DataTypes.GetNbt(Nbt));
}
return new Queue<byte>(data);
}
}

View file

@ -9,7 +9,7 @@ public class BlockSetSubcomponent(DataTypes dataTypes, SubComponentRegistry subC
public int Type { get; set; }
public string? TagName { get; set; }
public List<int>? BlockIds { get; set; }
protected override void Parse(Queue<byte> data)
{
Type = DataTypes.ReadNextVarInt(data);
@ -18,9 +18,9 @@ public class BlockSetSubcomponent(DataTypes dataTypes, SubComponentRegistry subC
TagName = DataTypes.ReadNextString(data);
if (Type == 0) return;
BlockIds = [];
for (var i = 0; i < Type - 1; i++)
BlockIds.Add(DataTypes.ReadNextVarInt(data));
}
@ -33,16 +33,16 @@ public class BlockSetSubcomponent(DataTypes dataTypes, SubComponentRegistry subC
{
if (string.IsNullOrEmpty(TagName?.Trim()))
throw new ArgumentNullException($"Can not serialize an empty tag name when the Block Set type is 0!");
data.AddRange(DataTypes.GetString(TagName));
}
if (Type == 0) return new Queue<byte>(data);
if(BlockIds is null || BlockIds.Count == 0)
if (BlockIds is null || BlockIds.Count == 0)
throw new ArgumentNullException($"Can not serialize an empty list of Block IDs in a Block Set when the type is not 0!");
for(var i = 0; i < Type - 1; i++)
for (var i = 0; i < Type - 1; i++)
data.AddRange(DataTypes.GetVarInt(BlockIds[i]));
return new Queue<byte>(data);

View file

@ -13,7 +13,7 @@ public class DetailsSubComponent(DataTypes dataTypes, SubComponentRegistry subCo
public bool ShowIcon { get; set; }
public bool HasHiddenEffects { get; set; }
public DetailsSubComponent? Detail { get; set; }
protected override void Parse(Queue<byte> data)
{
Amplifier = DataTypes.ReadNextVarInt(data);
@ -22,8 +22,8 @@ public class DetailsSubComponent(DataTypes dataTypes, SubComponentRegistry subCo
ShowParticles = DataTypes.ReadNextBool(data);
ShowIcon = DataTypes.ReadNextBool(data);
HasHiddenEffects = DataTypes.ReadNextBool(data);
if(HasHiddenEffects)
if (HasHiddenEffects)
Detail = (DetailsSubComponent)SubComponentRegistry.ParseSubComponent(SubComponents.Details, data);
}
@ -39,9 +39,9 @@ public class DetailsSubComponent(DataTypes dataTypes, SubComponentRegistry subCo
if (HasHiddenEffects)
{
if(Detail is null)
if (Detail is null)
throw new ArgumentNullException($"Can not serialize a DetailSubComponent1206 when the Detail is empty but HasHiddenEffects is true!");
data.AddRange(Detail.Serialize());
}

View file

@ -8,7 +8,7 @@ public class EffectSubComponent(DataTypes dataTypes, SubComponentRegistry subCom
{
public PotionEffectSubComponent TypeId { get; set; } = null!;
public float Probability { get; set; }
protected override void Parse(Queue<byte> data)
{
TypeId = (PotionEffectSubComponent)SubComponentRegistry.ParseSubComponent(SubComponents.PotionEffect, data);

View file

@ -13,7 +13,7 @@ public class FireworkExplosionSubComponent(DataTypes dataTypes, SubComponentRegi
public List<int> FadeColors { get; set; } = [];
public bool HasTrail { get; set; }
public bool HasTwinkle { get; set; }
protected override void Parse(Queue<byte> data)
{
Shape = DataTypes.ReadNextVarInt(data);
@ -21,12 +21,12 @@ public class FireworkExplosionSubComponent(DataTypes dataTypes, SubComponentRegi
for (var i = 0; i < NumberOfColors; i++)
Colors.Add(DataTypes.ReadNextInt(data));
NumberOfFadeColors = DataTypes.ReadNextVarInt(data);
for (var i = 0; i < NumberOfFadeColors; i++)
FadeColors.Add(DataTypes.ReadNextInt(data));
HasTrail = DataTypes.ReadNextBool(data);
HasTwinkle = DataTypes.ReadNextBool(data);
}
@ -45,7 +45,7 @@ public class FireworkExplosionSubComponent(DataTypes dataTypes, SubComponentRegi
foreach (var color in Colors)
data.AddRange(DataTypes.GetInt(color));
}
data.AddRange(DataTypes.GetVarInt(NumberOfFadeColors));
if (NumberOfFadeColors > 0)
{
@ -55,7 +55,7 @@ public class FireworkExplosionSubComponent(DataTypes dataTypes, SubComponentRegi
foreach (var fadeColor in FadeColors)
data.AddRange(DataTypes.GetInt(fadeColor));
}
data.AddRange(DataTypes.GetBool(HasTrail));
data.AddRange(DataTypes.GetBool(HasTwinkle));
return new Queue<byte>(data);

View file

@ -8,7 +8,7 @@ public class PotionEffectSubComponent(DataTypes dataTypes, SubComponentRegistry
{
public int TypeId { get; set; }
public DetailsSubComponent Details { get; set; } = null!;
protected override void Parse(Queue<byte> data)
{
TypeId = DataTypes.ReadNextVarInt(data);

View file

@ -11,7 +11,7 @@ public class PropertySubComponent(DataTypes dataTypes, SubComponentRegistry subC
public string? ExactValue { get; set; }
public string? MinValue { get; set; }
public string? MaxValue { get; set; }
protected override void Parse(Queue<byte> data)
{
Name = DataTypes.ReadNextString(data);
@ -34,7 +34,7 @@ public class PropertySubComponent(DataTypes dataTypes, SubComponentRegistry subC
if (string.IsNullOrEmpty(Name?.Trim()))
throw new ArgumentNullException($"Can not serialize a Property sub-component if the Name is null or empty!");
data.AddRange(DataTypes.GetString(Name));
data.AddRange(DataTypes.GetBool(IsExactMatch));
@ -42,7 +42,7 @@ public class PropertySubComponent(DataTypes dataTypes, SubComponentRegistry subC
{
if (string.IsNullOrEmpty(ExactValue?.Trim()))
throw new ArgumentNullException($"Can not serialize a Property sub-component if the ExactValue is null or empty when the type is Exact Match!");
data.AddRange(DataTypes.GetString(ExactValue));
}
else
@ -50,12 +50,12 @@ public class PropertySubComponent(DataTypes dataTypes, SubComponentRegistry subC
data.AddRange(DataTypes.GetBool(MinValue is not null));
if (MinValue is not null)
data.AddRange(DataTypes.GetString(MinValue));
data.AddRange(DataTypes.GetBool(MaxValue is not null));
if (MaxValue is not null)
data.AddRange(DataTypes.GetString(MaxValue));
}
return new Queue<byte>(data);
}
}

View file

@ -11,18 +11,18 @@ public class RuleSubComponent(DataTypes dataTypes, SubComponentRegistry subCompo
public float Speed { get; set; }
public bool HasCorrectDropForBlocks { get; set; }
public bool CorrectDropForBlocks { get; set; }
protected override void Parse(Queue<byte> data)
{
Blocks = (BlockSetSubcomponent)SubComponentRegistry.ParseSubComponent(SubComponents.BlockSet, data);
HasSpeed = DataTypes.ReadNextBool(data);
if(HasSpeed)
if (HasSpeed)
Speed = DataTypes.ReadNextFloat(data);
HasCorrectDropForBlocks = DataTypes.ReadNextBool(data);
if(HasCorrectDropForBlocks)
if (HasCorrectDropForBlocks)
CorrectDropForBlocks = DataTypes.ReadNextBool(data);
}
@ -31,13 +31,13 @@ public class RuleSubComponent(DataTypes dataTypes, SubComponentRegistry subCompo
var data = new List<byte>();
data.AddRange(Blocks.Serialize());
data.AddRange(DataTypes.GetBool(HasSpeed));
if(HasSpeed)
if (HasSpeed)
data.AddRange(DataTypes.GetFloat(Speed));
data.AddRange(DataTypes.GetBool(HasCorrectDropForBlocks));
if(HasCorrectDropForBlocks)
if (HasCorrectDropForBlocks)
data.AddRange(DataTypes.GetBool(CorrectDropForBlocks));
return new Queue<byte>(data);
}
}

View file

@ -11,7 +11,7 @@ public class AttributeSubComponent121(DataTypes dataTypes, SubComponentRegistry
public double Value { get; set; }
public int Operation { get; set; }
public int Slot { get; set; }
protected override void Parse(Queue<byte> data)
{
TypeId = DataTypes.ReadNextVarInt(data);
@ -25,10 +25,10 @@ public class AttributeSubComponent121(DataTypes dataTypes, SubComponentRegistry
{
var data = new List<byte>();
data.AddRange(DataTypes.GetVarInt(TypeId));
if (string.IsNullOrEmpty(ResourceLocation?.Trim()))
throw new ArgumentNullException($"Can not serialize AttributeSubComponent121 due to ResourceLocation being null or empty!");
data.AddRange(DataTypes.GetString(ResourceLocation));
data.AddRange(DataTypes.GetDouble(Value));
data.AddRange(DataTypes.GetVarInt(Operation));

View file

@ -10,13 +10,13 @@ public class SoundEventSubComponent(DataTypes dataTypes, SubComponentRegistry su
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);
@ -30,14 +30,14 @@ public class SoundEventSubComponent(DataTypes dataTypes, SubComponentRegistry su
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)
if (HasFixedRange)
data.AddRange(DataTypes.GetFloat(FixedRange));
return new Queue<byte>(data);