Skip to content

Commit 75b8caa

Browse files
authored
Fix a couple of nbt exceptions (#479)
1 parent 18df3a1 commit 75b8caa

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

Obsidian.API/_Interfaces/IEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface IEntity
2222

2323
public BoundingBox BoundingBox { get; }
2424
public EntityDimension Dimension { get; }
25-
public int Air { get; set; }
25+
public short Air { get; set; }
2626

2727
public float Health { get; set; }
2828

Obsidian.Nbt/NbtCompound.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public NbtCompound(string name, List<INbtTag> children) : this(name)
4646
public bool TryGetTag(string name, [MaybeNullWhen(false)] out INbtTag tag) => this.children.TryGetValue(name, out tag);
4747
public bool TryGetTag<T>(string name, [MaybeNullWhen(false)] out T tag) where T : INbtTag
4848
{
49-
if (this.children.TryGetValue(name, out var childTag) && childTag is T matchedTag)
49+
if (this.TryGetTag(name, out var childTag) && childTag is T matchedTag)
5050
{
5151
tag = matchedTag;
5252
return true;
@@ -55,19 +55,19 @@ public bool TryGetTag<T>(string name, [MaybeNullWhen(false)] out T tag) where T
5555
tag = default;
5656
return false;
5757
}
58-
public bool TryGetTagValue<TValue>(string name, [MaybeNullWhen(false)]out TValue value)
58+
59+
public bool TryGetTagValue<TValue>(string name, [MaybeNullWhen(false)] out TValue value)
5960
{
60-
if(this.GetTagValue<TValue>(name) is TValue tagValue)
61+
if (this.TryGetTag<NbtTag<TValue>>(name, out var tag))
6162
{
62-
value = tagValue;
63+
value = tag.Value;
6364
return true;
6465
}
6566

6667
value = default;
6768
return false;
6869
}
6970

70-
7171
public byte GetByte(string name) => this.GetTagValue<byte>(name);
7272

7373
public short GetShort(string name) => this.GetTagValue<short>(name);
@@ -149,11 +149,5 @@ public IEnumerator<KeyValuePair<string, INbtTag>> GetEnumerator() =>
149149

150150
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
151151

152-
private T? GetTagValue<T>(string name)
153-
{
154-
if (this.TryGetTag(name, out var tag) && tag is NbtTag<T> actualTag)
155-
return actualTag.Value;
156-
157-
throw new TagNotFoundException(name);
158-
}
152+
private T? GetTagValue<T>(string name) => this.TryGetTag(name, out var tag) && tag is NbtTag<T> actualTag ? actualTag.Value : throw new TagNotFoundException(name);
159153
}

Obsidian/Entities/Entity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class Entity : IEquatable<Entity>, IEntity
3939

4040
public EntityType Type { get; set; }
4141

42-
public int Air { get; set; } = 300;
42+
public short Air { get; set; } = 300;
4343

4444
public float Health { get; set; } = 100;
4545

Obsidian/Entities/Player.Helpers.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public async Task SaveAsync()
5151
writer.WriteInt("XpLevel", XpLevel);
5252
writer.WriteInt("XpTotal", XpTotal);
5353

54+
writer.WriteShort("Air", Air);
55+
5456
writer.WriteFloat("Health", Health);
5557

5658
writer.WriteFloat("foodExhaustionLevel", FoodExhaustionLevel);

Obsidian/Net/MinecraftStream.Reading.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public ChatMessage ReadChat()
584584
var reader = new NbtReader(this);
585585
var chatMessage = ChatMessage.Empty;
586586

587-
return !reader.TryReadNextTag<NbtCompound>(out var root) ? chatMessage : chatMessage.FromNbt(root);
587+
return !reader.TryReadNextTag<NbtCompound>(false, out var root) ? chatMessage : chatMessage.FromNbt(root);
588588
}
589589

590590
[ReadMethod]

0 commit comments

Comments
 (0)