Skip to content

Commit 0d12358

Browse files
committed
Entity fixes
1 parent aaa52ac commit 0d12358

File tree

18 files changed

+200
-284
lines changed

18 files changed

+200
-284
lines changed

src/MiNET/MiNET.Client/McpeClientMessageHandlerBase.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#endregion
2525

2626
using System;
27+
using System.Collections;
2728
using System.Collections.Generic;
2829
using System.Numerics;
2930
using System.Security.Cryptography;
@@ -33,9 +34,12 @@
3334
using MiNET.Net;
3435
using MiNET.Utils;
3536
using MiNET.Utils.Cryptography;
37+
using MiNET.Utils.Metadata;
3638
using MiNET.Utils.Vectors;
39+
using Newtonsoft.Json;
3740
using Org.BouncyCastle.Crypto.Parameters;
3841
using Org.BouncyCastle.Security;
42+
using static MiNET.Entities.Entity;
3943

4044
namespace MiNET.Client
4145
{
@@ -286,6 +290,9 @@ public virtual void HandleMcpeHurtArmor(McpeHurtArmor message)
286290

287291
public virtual void HandleMcpeSetEntityData(McpeSetEntityData message)
288292
{
293+
//Log.Warn(JsonConvert.SerializeObject(message, Formatting.Indented));
294+
295+
289296
/*if (message.metadata[0] == null) { return; }
290297
MetadataLong metadataLong = message.metadata[0] as MetadataLong;
291298
byte[] bytes = BitConverter.GetBytes(metadataLong.Value);

src/MiNET/MiNET/Entities/Agent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region LICENSE
1+
#region LICENSE
22

33
// The contents of this file are subject to the Common Public Attribution
44
// License Version 1.0. (the "License"); you may not use this file except in
@@ -44,10 +44,10 @@ public Agent(Level level) : base(EntityType.Agent, level)
4444
public override MetadataDictionary GetMetadata()
4545
{
4646
MetadataDictionary metadata = base.GetMetadata();
47-
metadata[0] = new MetadataLong(549755846656); // 1000000000000000000000001000000000000000; AlwaysShowName
47+
metadata[(int) MetadataFlags.EntityFlags] = new MetadataLong(549755846656); // 1000000000000000000000001000000000000000; AlwaysShowName
4848
if (Owner != null)
4949
{
50-
metadata[5] = new MetadataLong(Owner.EntityId);
50+
metadata[(int) MetadataFlags.Owner] = new MetadataLong(Owner.EntityId);
5151
}
5252
return metadata;
5353
}

src/MiNET/MiNET/Entities/Camera.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public Camera(Level level) : base(EntityType.Camera, level)
5252
public override MetadataDictionary GetMetadata()
5353
{
5454
var metadata = base.GetMetadata();
55-
metadata[40] = new MetadataString(InteractionLabel);
55+
metadata[(int) MetadataFlags.NpcData] = new MetadataString(InteractionLabel);
5656
return metadata;
5757
}
5858

src/MiNET/MiNET/Entities/Entity.cs

Lines changed: 115 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ public class Entity
7474
public bool IsOutOfWater => !IsInWater;
7575
public int PotionColor { get; set; }
7676
public int Variant { get; set; }
77-
public int EatingHaystack { get; set; }
78-
7977
public long Age { get; set; }
8078
public double Scale { get; set; } = 1.0;
8179
public virtual double Height { get; set; } = 1;
@@ -115,44 +113,143 @@ public Entity(int entityTypeId, Level level) : this((EntityType) entityTypeId, l
115113
public enum MetadataFlags
116114
{
117115
EntityFlags = 0,
116+
StructuralInt = 1,
118117
Variant = 2,
119118
Color = 3,
120-
HideNameTag = 3,
121119
NameTag = 4,
122120
Owner = 5,
121+
Target = 6,
123122
AvailableAir = 7,
124123
PotionColor = 8,
124+
Unknown = 9,
125+
Unknown2 = 10,
126+
Hurt = 11,
127+
HurtDirection = 12,
128+
RowTimeLeft = 13,
129+
RowTimeRight = 14,
125130
ExperienceValue = 15,
126-
EatingHaystack = 16,
127-
FireworksType = 16,
128-
MaybeAge = 24,
131+
TileRuntimeId = 16,
132+
Offset = 17,
133+
CustomDisplay = 18,
134+
Swell = 19,
135+
OldSwel = 20,
136+
SwellDirection = 21,
137+
ChargeAmount = 22,
138+
CarryBlockRumtimeId = 23,
139+
EntityAge = 24,
140+
UsingItem = 25,
129141
PlayerFlags = 26,
142+
PlayerIndex = 27,
130143
BedPosition = 28,
131-
Scale = 38, //todo still exist?
144+
XPower = 29,
145+
YPower = 30,
146+
ZPower = 31,
147+
AuxPower = 32,
148+
FishX = 33,
149+
FishY = 34,
150+
FishAngle = 35,
151+
AuxValueData = 36,
152+
LeashHolder = 37,
153+
Scale = 38,
154+
HasNpc = 39,
155+
NpcData = 40,
156+
Actions = 41,
132157
MaxAir = 42,
133158
Markings = 43,
134-
CollisionBoxWidth = 53, //todo still exist?
135-
CollisionBoxHeight = 54, //todo still exist?
136-
159+
ContainerType = 44,
160+
ContainerSize = 45,
161+
ContainerStrenght = 46,
162+
BlockTarget = 47,
163+
InvulnerableTicks = 48,
164+
TargetA = 49,
165+
TargetB = 50,
166+
TargetC = 51,
167+
AerialAttack = 52,
168+
CollisionBoxWidth = 53,
169+
CollisionBoxHeight = 54,
137170
DataFuseLength = 55,
138-
139171
RiderSeatPosition = 56,
140172
RiderRotationLocked = 57,
141173
RiderMaxRotation = 58,
142174
RiderMinRotation = 59,
175+
RiderRotationOffset = 60,
176+
DataRadius = 61,
177+
DataWaiting = 62,
178+
DataParticle = 63,
179+
PeekId = 64,
180+
AttachFace = 65,
181+
Attached = 66,
182+
AttachPos = 67,
183+
TradeTarget = 68,
184+
Career = 69,
185+
HasCommandBlock = 70,
186+
CommandName = 71,
187+
LastCommandOutput = 72,
188+
TrackCommandOutput = 73,
189+
Unknown5 = 74,
190+
Strenght = 75,
191+
MaxStrenght = 76,
192+
DataCastingColor = 77,
193+
DataLifetimeTicks = 78,
194+
PoseIndex = 79,
195+
DataTickOffset = 80,
143196
AlwaysShowNameTag = 81,
144-
145-
EntityFlags2 = 91, // same treatment as 0 flags, perhaps
146-
147-
ButtonText = 99,
197+
Color2Index = 82,
198+
AuthorName = 83,
199+
Score = 84,
200+
BalloonAnchor = 86,
201+
BubbleTime = 87,
202+
Agent = 88,
203+
SittingAmount = 89,
204+
SittingAmountPrevious = 90,
205+
EatingCounter = 91,
206+
Unknown6 = 92,
207+
LayingAmount = 93,
208+
LayingAmountPrevious = 94,
209+
DataDuration = 95,
210+
DataSpawnTime = 96,
211+
DataChangeRate = 97,
212+
DataChangeOnPickup = 98,
213+
DataPickupCount = 99,
214+
InteractTect = 100,
215+
TradeTier = 101,
216+
MaxTradeTier = 102,
217+
TradeExperience = 103,
218+
SkinIn = 104,
219+
SpawningFrames = 105,
220+
CommandBockTickDelay = 106,
221+
CommandBlockOnFirstTick = 107,
222+
AmbientSoundInterval = 108,
223+
AmbientSoundIntervalRange = 109,
224+
AmbientSoundEventName = 110,
225+
FallDamageMultiplier = 111,
226+
NameRawText = 112,
227+
CanRideTarget = 113,
228+
LowCuredDiscount = 114,
229+
HighCuredDiscount = 115,
230+
NearbyCuredDiscount = 116,
231+
NearbyCuredDiscountTime = 117,
232+
Hitbox = 118,
233+
IsBuoyant = 119,
234+
FreezingEffectStrenght = 120,
235+
BuoyancyData = 121,
236+
GoatHornCount = 122,
237+
BaseRuntimeId = 123,
238+
MovementSoundDistanceOffset = 124,
239+
HeartbeatSoundDistanceOffset = 125,
240+
HeartbeatSoundEvent = 126,
241+
LastDeathPosition = 127,
242+
LastDeathDimension = 128,
243+
HasDied = 129,
244+
CollisionBox = 130,
245+
VisibleMobEffects = 131,
246+
Count = 132,
148247
}
149248

150249
public virtual MetadataDictionary GetMetadata()
151250
{
152251
MetadataDictionary metadata = new MetadataDictionary();
153252
metadata[(int) MetadataFlags.EntityFlags] = new MetadataLong(GetDataValue());
154-
metadata[1] = new MetadataInt(1);
155-
metadata[(int) MetadataFlags.HideNameTag] = new MetadataByte(!HideNameTag);
156253
metadata[(int) MetadataFlags.NameTag] = new MetadataString(NameTag ?? string.Empty);
157254
metadata[(int) MetadataFlags.AvailableAir] = new MetadataShort(HealthManager.Air);
158255
metadata[(int) MetadataFlags.PotionColor] = new MetadataInt(PotionColor);
@@ -302,7 +399,6 @@ private static string FlagsToString(long input)
302399
public bool IsBaby { get; set; }
303400
public bool IsConverting { get; set; }
304401
public bool IsCritical { get; set; }
305-
public bool IsShowName => !HideNameTag;
306402
public bool IsAlwaysShowName { get; set; }
307403
public bool IsNoAi => NoAi;
308404
public bool HaveAi => !NoAi;
@@ -453,7 +549,6 @@ public enum DataFlags
453549
Timer2 = 116,
454550
Timer3 = 117,
455551
BodyRotationBlocked = 118,
456-
Count = 119
457552
}
458553

459554
protected virtual BitArray GetFlags()
@@ -473,7 +568,7 @@ protected virtual BitArray GetFlags()
473568
bits[(int) DataFlags.Baby] = IsBaby;
474569
bits[(int) DataFlags.Converting] = IsConverting;
475570
bits[(int) DataFlags.Critcal] = IsCritical;
476-
bits[(int) DataFlags.ShowName] = IsShowName;
571+
bits[(int) DataFlags.ShowName] = !HideNameTag;
477572
bits[(int) DataFlags.AlwaysShowName] = IsAlwaysShowName;
478573
bits[(int) DataFlags.NoAi] = IsNoAi;
479574
bits[(int) DataFlags.Silent] = IsSilent;

src/MiNET/MiNET/Entities/Hostile/Dragon.cs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region LICENSE
1+
#region LICENSE
22

33
// The contents of this file are subject to the Common Public Attribution
44
// License Version 1.0. (the "License"); you may not use this file except in
@@ -47,46 +47,7 @@ public Dragon(Level level) : base(EntityType.Dragon, level)
4747

4848
public override MetadataDictionary GetMetadata()
4949
{
50-
Log.Warn("Metadata");
51-
MetadataDictionary metadata = new MetadataDictionary();
52-
//metadata[38] = new MetadataLong(0);
53-
//metadata[39] = new MetadataFloat(1f);
54-
//metadata[44] = new MetadataShort(300);
55-
56-
//MetadataDictionary metadata = new MetadataDictionary();
57-
metadata[0] = new MetadataLong(8388608); // 100000000000000000000000; Sitting
58-
metadata[1] = new MetadataInt(1);
59-
metadata[2] = new MetadataInt(0);
60-
metadata[3] = new MetadataByte(0);
61-
metadata[4] = new MetadataString("");
62-
metadata[5] = new MetadataLong(-1);
63-
metadata[7] = new MetadataShort(300);
64-
metadata[8] = new MetadataInt(0);
65-
metadata[9] = new MetadataByte(0);
66-
metadata[10] = new MetadataByte(0);
67-
metadata[22] = new MetadataByte(0);
68-
metadata[38] = new MetadataLong(0);
69-
metadata[39] = new MetadataFloat(1f);
70-
metadata[43] = new MetadataShort(300);
71-
metadata[44] = new MetadataInt(0);
72-
metadata[45] = new MetadataByte(0);
73-
metadata[46] = new MetadataInt(0);
74-
metadata[47] = new MetadataInt(0);
75-
metadata[54] = new MetadataFloat(13f);
76-
metadata[55] = new MetadataFloat(4f);
77-
metadata[58] = new MetadataByte(0);
78-
metadata[59] = new MetadataFloat(0f);
79-
metadata[60] = new MetadataFloat(0f);
80-
metadata[70] = new MetadataByte(0);
81-
metadata[71] = new MetadataString("");
82-
metadata[72] = new MetadataString("");
83-
metadata[73] = new MetadataByte(1);
84-
metadata[74] = new MetadataByte(0);
85-
metadata[75] = new MetadataInt(0);
86-
metadata[76] = new MetadataInt(0);
87-
metadata[77] = new MetadataInt(0);
88-
metadata[78] = new MetadataInt(-1);
89-
50+
MetadataDictionary metadata = base.GetMetadata();
9051
return metadata;
9152
}
9253
}

src/MiNET/MiNET/Entities/Hostile/ElderGuardian.cs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region LICENSE
1+
#region LICENSE
22

33
// The contents of this file are subject to the Common Public Attribution
44
// License Version 1.0. (the "License"); you may not use this file except in
@@ -40,44 +40,9 @@ public ElderGuardian(Level level) : base(EntityType.ElderGuardian, level)
4040
Height = 1.9;
4141
IsElder = true;
4242
}
43-
44-
// Metadata:
45-
//[0] long 7 536870912,
46-
//[1] int 2 1,
47-
//[2] int 2 0,
48-
//[3] byte 0 0,
49-
//[4] string 4 ,
50-
//[5] long 7 1,
51-
//[6] long 7 0,
52-
//[7] short 1 300,
53-
//[8] int 2 0,
54-
//[9] byte 0 0,
55-
//[38] long 7 0,
56-
//[39] float 3 1,
57-
//[44] short 1 300,
58-
//[45] int 2 0,
59-
//[46] byte 0 0,
60-
//[47] int 2 0,
61-
//[53] float 3 1,99,
62-
//[54] float 3 1,99,
63-
//[56] vector3 8 <0� 0� 0>,
64-
//[57] byte 0 0,
65-
//[58] float 3 0,
66-
//[59] float 3 0
67-
6843
public override MetadataDictionary GetMetadata()
6944
{
7045
MetadataDictionary metadata = base.GetMetadata();
71-
//MetadataDictionary metadata = new MetadataDictionary();
72-
metadata[0] = new MetadataLong(GetDataValue());
73-
metadata[39] = new MetadataFloat(1.0f);
74-
metadata[44] = new MetadataShort(300);
75-
metadata[53] = new MetadataFloat(1.99f);
76-
metadata[54] = new MetadataFloat(1.99f);
77-
metadata[57] = new MetadataByte(0);
78-
metadata[58] = new MetadataFloat(0);
79-
metadata[59] = new MetadataFloat(0);
80-
8146
return metadata;
8247
}
8348
}

0 commit comments

Comments
 (0)