Skip to content

Commit 7139f9e

Browse files
committed
fix 1.21.70 - entities
1 parent 29c4994 commit 7139f9e

File tree

10 files changed

+151
-18
lines changed

10 files changed

+151
-18
lines changed

src/MiNET/MiNET.Client/BedrockTraceHandler.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
using MiNET.Utils.Vectors;
4545
using MiNET.Worlds;
4646
using Newtonsoft.Json;
47-
using Newtonsoft.Json.Linq;
4847

4948
namespace MiNET.Client
5049
{
@@ -818,5 +817,39 @@ public override void HandleMcpeCommandOutput(McpeCommandOutput message)
818817
// Log.Warn($"Received command output: {msg}");
819818
//}
820819
}
820+
821+
private static NbtCompound entityNbt = new NbtCompound("Entities");
822+
823+
public override void HandleMcpeSyncEntityProperty(McpeSyncEntityProperty message)
824+
{
825+
var entityData = message.propertyData.NbtFile.RootTag;
826+
string entityType = entityData["type"].StringValue;
827+
828+
if (!entityNbt.Contains(entityType))
829+
{
830+
entityNbt.Add(new NbtList(entityType, NbtTagType.Compound));
831+
}
832+
833+
var entityList = entityNbt.Get<NbtList>(entityType);
834+
var compound = new NbtCompound
835+
{
836+
entityData.Clone() as NbtTag
837+
};
838+
839+
entityList.Add(compound);
840+
}
841+
842+
public override void HandleMcpeItemComponent(McpeItemComponent message)
843+
{
844+
var nbtFile = new NbtFile(entityNbt);
845+
nbtFile.UseVarInt = true;
846+
nbtFile.SaveToFile("newResources/entity_properties.nbt", NbtCompression.None);
847+
Log.Warn("Received entities properties to newResources/entity_properties.nbt\n");
848+
entityNbt.Clear();
849+
850+
var fileNameItemstates = "newResources/itemstates.json";
851+
File.WriteAllText(fileNameItemstates, JsonConvert.SerializeObject(message.entries, Formatting.Indented));
852+
Log.Warn("Received item runtime ids exported to newResources/itemstates.json\n");
853+
}
821854
}
822855
}

src/MiNET/MiNET.Client/McpeClientMessageHandlerBase.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -725,25 +725,25 @@ public virtual void HandleMcpeUpdateSubChunkBlocksPacket(McpeUpdateSubChunkBlock
725725
}
726726

727727
/// <inheritdoc />
728-
public void HandleMcpeSubChunkPacket(McpeSubChunkPacket message)
728+
public virtual void HandleMcpeSubChunkPacket(McpeSubChunkPacket message)
729729
{
730730

731731
}
732732

733733
/// <inheritdoc />
734-
public void HandleMcpeDimensionData(McpeDimensionData message)
734+
public virtual void HandleMcpeDimensionData(McpeDimensionData message)
735735
{
736736

737737
}
738738

739739
/// <inheritdoc />
740-
public void HandleMcpeUpdateAbilities(McpeUpdateAbilities message)
740+
public virtual void HandleMcpeUpdateAbilities(McpeUpdateAbilities message)
741741
{
742742
Client.permissionLevel = (PermissionLevel) message.playerPermissions;
743743
}
744744

745745
/// <inheritdoc />
746-
public void HandleMcpeUpdateAdventureSettings(McpeUpdateAdventureSettings message)
746+
public virtual void HandleMcpeUpdateAdventureSettings(McpeUpdateAdventureSettings message)
747747
{
748748

749749
}
@@ -756,32 +756,32 @@ public virtual void HandleFtlCreatePlayer(FtlCreatePlayer message)
756756
{
757757
}
758758

759-
public void HandleMcpeTrimData(McpeTrimData message)
759+
public virtual void HandleMcpeTrimData(McpeTrimData message)
760760
{
761761

762762
}
763763

764-
public void HandleMcpeOpenSign(McpeOpenSign message)
764+
public virtual void HandleMcpeOpenSign(McpeOpenSign message)
765765
{
766766

767767
}
768768

769-
public void HandleMcpeEmote(McpeEmotePacket message)
769+
public virtual void HandleMcpeEmote(McpeEmotePacket message)
770770
{
771771

772772
}
773773

774-
public void HandleMcpeEmoteList(McpeEmoteList message)
774+
public virtual void HandleMcpeEmoteList(McpeEmoteList message)
775775
{
776776

777777
}
778778

779-
public void HandleMcpePermissionRequest(McpePermissionRequest message)
779+
public virtual void HandleMcpePermissionRequest(McpePermissionRequest message)
780780
{
781781

782782
}
783783

784-
public void HandleMcpePlayerFog(McpePlayerFog message)
784+
public virtual void HandleMcpePlayerFog(McpePlayerFog message)
785785
{
786786

787787
}
@@ -791,7 +791,7 @@ public virtual void HandleMcpeAnimateEntity(McpeAnimateEntity message)
791791
Log.Warn($"Got entity animation {message.animationName}");
792792
}
793793

794-
public void HandleMcpeServerboundLoadingScreen(McpeServerboundLoadingScreen message)
794+
public virtual void HandleMcpeSyncEntityProperty(McpeSyncEntityProperty message)
795795
{
796796

797797
}

src/MiNET/MiNET.Console/minet.zip

938 Bytes
Binary file not shown.

src/MiNET/MiNET/Entities/Entity.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ public virtual void SpawnToPlayers(Player[] players)
663663
addEntity.speedX = Velocity.X;
664664
addEntity.speedY = Velocity.Y;
665665
addEntity.speedZ = Velocity.Z;
666-
addEntity.syncdata = new PropertySyncData() { intProperties = new Dictionary<uint, int>() { { 0, 0 } } }; //todo
667666
addEntity.attributes = GetEntityAttributes();
668667

669668
Level.RelayBroadcast(players, addEntity);

src/MiNET/MiNET/MiNET.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
44
<PackageId>MiNET-CobwebSMP</PackageId>
5-
<Version>1.13.0.26</Version>
5+
<Version>1.13.0.27</Version>
66
<Authors>gurun</Authors>
77
<Company>Niclas Olofsson</Company>
88
<Description>MiNET - a Minecraft PocketEdition Server</Description>
@@ -30,6 +30,7 @@
3030
<EmbeddedResource Include="Resources\itemstates.json" />
3131
<EmbeddedResource Include="Resources\item_id_map.json" />
3232
<EmbeddedResource Include="Resources\block_meta_map.json" />
33+
<EmbeddedResource Include="Resources\entity_properties.nbt" />
3334
</ItemGroup>
3435
<ItemGroup>
3536
<PackageReference Include="jose-jwt" Version="5.1.1" />

src/MiNET/MiNET/Net/MCPE Protocol.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ public interface IMcpeClientMessageHandler
250250
void HandleMcpePermissionRequest(McpePermissionRequest message);
251251
void HandleMcpePlayerFog(McpePlayerFog message);
252252
void HandleMcpeAnimateEntity(McpeAnimateEntity message);
253+
void HandleMcpeSyncEntityProperty(McpeSyncEntityProperty message);
253254
}
254255

255256
public class McpeClientMessageDispatcher
@@ -658,6 +659,9 @@ public bool HandlePacket(Packet message)
658659
case McpeAnimateEntity msg:
659660
_messageHandler.HandleMcpeAnimateEntity(msg);
660661
break;
662+
case McpeSyncEntityProperty msg:
663+
_messageHandler.HandleMcpeSyncEntityProperty(msg);
664+
break;
661665
default:
662666
return false;
663667
}
@@ -1039,6 +1043,8 @@ public static Packet Create(short messageId, ReadOnlyMemory<byte> buffer, string
10391043
return McpePlayerFog.CreateObject().Decode(buffer);
10401044
case 0x8D:
10411045
return McpeAnvilDamage.CreateObject().Decode(buffer);
1046+
case 0xa5:
1047+
return McpeSyncEntityProperty.CreateObject().Decode(buffer);
10421048
}
10431049
}
10441050

@@ -11005,4 +11011,51 @@ protected override void ResetPacket()
1100511011
}
1100611012

1100711013
}
11014+
11015+
public partial class McpeSyncEntityProperty : Packet<McpeSyncEntityProperty>
11016+
{
11017+
public Nbt propertyData; // = null;
11018+
11019+
public McpeSyncEntityProperty()
11020+
{
11021+
Id = 0xa5;
11022+
IsMcpe = true;
11023+
}
11024+
11025+
protected override void EncodePacket()
11026+
{
11027+
base.EncodePacket();
11028+
11029+
BeforeEncode();
11030+
11031+
Write(propertyData);
11032+
11033+
AfterEncode();
11034+
}
11035+
11036+
partial void BeforeEncode();
11037+
partial void AfterEncode();
11038+
11039+
protected override void DecodePacket()
11040+
{
11041+
base.DecodePacket();
11042+
11043+
BeforeDecode();
11044+
11045+
propertyData = ReadNbt();
11046+
11047+
AfterDecode();
11048+
}
11049+
11050+
partial void BeforeDecode();
11051+
partial void AfterDecode();
11052+
11053+
protected override void ResetPacket()
11054+
{
11055+
base.ResetPacket();
11056+
11057+
propertyData = default(Nbt);
11058+
}
11059+
11060+
}
1100811061
}

src/MiNET/MiNET/Net/Packet.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,10 +2168,6 @@ public Itemstates ReadItemstates()
21682168
});
21692169
}
21702170

2171-
var fileNameItemstates = "newResources/itemstates.json";
2172-
File.WriteAllText(fileNameItemstates, JsonConvert.SerializeObject(result, Formatting.Indented));
2173-
Log.Warn("Received item runtime ids exported to newResources/itemstates.json\n");
2174-
21752171
return result;
21762172
}
21772173

src/MiNET/MiNET/Player.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,8 @@ public void Start(object o)
11411141

11421142
SendStartGame();
11431143

1144+
SendEntityProperties();
1145+
11441146
SendItemComponents();
11451147

11461148
SendAvailableEntityIdentifiers();
@@ -3485,6 +3487,39 @@ public void SendItemComponents()
34853487
SendPacket(itemComponent);
34863488
}
34873489

3490+
public void SendEntityProperties()
3491+
{
3492+
using (var stream = new MemoryStream(ResourceUtil.ReadEntityProperties().ToArray()))
3493+
{
3494+
var nbt = Packet.ReadNbtCompound(stream, true);
3495+
foreach (var entityTypeTag in nbt)
3496+
{
3497+
if (entityTypeTag is NbtList entityList)
3498+
{
3499+
foreach (var entityData in entityList)
3500+
{
3501+
if (entityData is NbtCompound compound)
3502+
{
3503+
Nbt entityNbt = new Nbt
3504+
{
3505+
NbtFile = new NbtFile
3506+
{
3507+
BigEndian = false,
3508+
UseVarInt = true,
3509+
RootTag = compound.Get<NbtCompound>("")
3510+
}
3511+
};
3512+
3513+
McpeSyncEntityProperty entityProperty = McpeSyncEntityProperty.CreateObject();
3514+
entityProperty.propertyData = entityNbt;
3515+
SendPacket(entityProperty);
3516+
}
3517+
}
3518+
}
3519+
}
3520+
}
3521+
}
3522+
34883523
/// <summary>
34893524
/// Sends the set spawn position packet.
34903525
/// </summary>
1.14 KB
Binary file not shown.

src/MiNET/MiNET/Utils/ResourceUtil.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ namespace MiNET.Utils
3030
{
3131
public static class ResourceUtil
3232
{
33+
private static MemoryStream EntityProperties;
34+
3335
public static T ReadResource<T>(string filename, Type namespaceProvider = null, string subFolder = null)
3436
{
3537
if (namespaceProvider == null)
@@ -48,5 +50,19 @@ public static T ReadResource<T>(string filename, Type namespaceProvider = null,
4850
return JsonConvert.DeserializeObject<T>(reader.ReadToEnd());
4951
}
5052
}
53+
54+
public static MemoryStream ReadEntityProperties()
55+
{
56+
if (EntityProperties == null)
57+
{
58+
var assembly = Assembly.GetExecutingAssembly();
59+
using (var resourceStream = assembly.GetManifestResourceStream("MiNET.Resources.entity_properties.nbt"))
60+
{
61+
EntityProperties = new MemoryStream();
62+
resourceStream.CopyTo(EntityProperties);
63+
}
64+
}
65+
return EntityProperties;
66+
}
5167
}
5268
}

0 commit comments

Comments
 (0)