Skip to content

Commit 08c2278

Browse files
committed
map API fixes
1 parent aa914da commit 08c2278

File tree

4 files changed

+34
-60
lines changed

4 files changed

+34
-60
lines changed

src/MiNET/MiNET.Console/minet.zip

169 KB
Binary file not shown.

src/MiNET/MiNET/Entities/ImageProviders/MapImageProvider.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
@@ -49,12 +49,12 @@ public virtual byte[] GetData(MapInfo mapInfo, bool forced)
4949

5050
if (MapData == null)
5151
{
52-
return null;
52+
return GenerateColors(mapInfo);
5353
}
5454

5555
if (MapData.Length != (mapInfo.Col * mapInfo.Row * 4))
5656
{
57-
return null;
57+
return GenerateColors(mapInfo);
5858
}
5959

6060
if (!_alreadySent)

src/MiNET/MiNET/Entities/World/MapEntity.cs

Lines changed: 30 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,24 @@ public MapEntity(Level level, long mapId = EntityManager.EntityIdUndefined) : ba
5151
EntityId = level.EntityManager.AddEntity(this) + 0xFFFF;
5252
}
5353

54-
//ImageProvider = new MapImageProvider();
55-
ImageProvider = new RandomColorMapImageProvider();
54+
ImageProvider = new MapImageProvider();
5655

57-
var mapInfo = new MapInfo
56+
if (MapInfo == null)
5857
{
59-
MapId = EntityId,
60-
UpdateType = 0,
61-
Scale = 0,
62-
X = 0,
63-
Z = 0,
64-
Col = 128,
65-
Row = 128,
66-
XOffset = 0,
67-
ZOffset = 0
68-
};
69-
70-
MapInfo = mapInfo;
58+
var mapInfo = new MapInfo
59+
{
60+
MapId = EntityId,
61+
UpdateType = 0,
62+
Scale = 0,
63+
X = 0,
64+
Z = 0,
65+
Col = 128,
66+
Row = 128,
67+
XOffset = 0,
68+
ZOffset = 0
69+
};
70+
MapInfo = mapInfo;
71+
}
7172
}
7273

7374
public override void SpawnToPlayers(Player[] players)
@@ -82,57 +83,29 @@ public override void DespawnFromPlayers(Player[] players)
8283

8384
public override void OnTick(Entity[] entities)
8485
{
85-
//if (Level.TickTime % 2 != 0) return;
86+
if (Level.TickTime % 2 != 0) return;
8687

87-
// if no image provider, do nothing
8888
if (ImageProvider == null) return;
8989

90-
MapInfo.Decorators = new MapDecorator[0];
91-
//MapInfo.Decorators = new MapDecorator[1];
92-
//for (int i = 0; i < MapInfo.Decorators.Length; i++)
93-
//{
94-
// var decorator = new MapDecorator
95-
// {
96-
// Rotation = (byte) (Level.TickTime % 16),
97-
// Icon = (byte) 1,
98-
// X = (byte) (Level.TickTime % 255),
99-
// Z = (byte) (Level.TickTime % 255),
100-
// Label = "",
101-
// Color = BitConverter.ToUInt32(new byte[] {0xff, 0xff, 0xff, 0xff}, 0),
102-
// };
103-
104-
// MapInfo.Decorators[i] = decorator;
105-
//}
106-
107-
var data = ImageProvider.GetData(MapInfo, false);
108-
if (data != null)
90+
if (MapInfo.Decorators == null)
10991
{
110-
MapInfo.Data = data;
111-
112-
MapInfo.UpdateType = initialized ? (byte) 2 : (byte) 8;
113-
114-
var mapInfo = (MapInfo) MapInfo.Clone();
115-
116-
var msg = McpeClientboundMapItemData.CreateObject();
117-
msg.mapinfo = mapInfo;
118-
Level.RelayBroadcast(msg);
119-
initialized = true;
120-
return;
92+
MapInfo.Decorators = new MapDecorator[0];
12193
}
12294

123-
var packet = ImageProvider.GetClientboundMapItemData(MapInfo);
124-
if (packet != null)
95+
if (MapInfo.Data == null)
12596
{
126-
Level.RelayBroadcast(packet);
127-
128-
return;
97+
MapInfo.Data = ImageProvider.GetData(MapInfo, false);
12998
}
99+
100+
MapInfo.UpdateType = initialized ? (byte) 2 : (byte) 8;
130101

131-
var batchPacket = ImageProvider.GetBatch(MapInfo, false);
132-
if (batchPacket != null)
133-
{
134-
Level.RelayBroadcast(batchPacket);
135-
}
102+
var mapInfo = (MapInfo) MapInfo.Clone();
103+
104+
var msg = McpeClientboundMapItemData.CreateObject();
105+
msg.mapinfo = mapInfo;
106+
Level.RelayBroadcast(msg);
107+
initialized = true;
108+
return;
136109
}
137110

138111
public virtual void AddToMapListeners(Player player, long mapId)

src/MiNET/MiNET/MiNET.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
5252
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.3" />
5353
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
54+
<PackageReference Include="System.Drawing.Common" Version="8.0.3" />
5455
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="8.0.0" />
5556
</ItemGroup>
5657
<ItemGroup>

0 commit comments

Comments
 (0)