fill in old stubs regaridng chunk stuff & another inv fix

This commit is contained in:
sylvessa
2026-04-13 20:55:02 -05:00
committed by itsRevela
parent a9c735e7aa
commit f9cac6395b
10 changed files with 158 additions and 9 deletions

View File

@@ -191,7 +191,58 @@ public class Chunk
/// <returns>The entities.</returns>
public Entity.Entity[] getEntities()
{
return Array.Empty<Entity.Entity>();
if (NativeBridge.GetChunkEntities == null) return Array.Empty<Entity.Entity>();
int dimId = _world.getDimensionId();
int count = NativeBridge.GetChunkEntities(dimId, _chunkX, _chunkZ, out IntPtr buf);
if (count <= 0 || buf == IntPtr.Zero) return Array.Empty<Entity.Entity>();
var result = new Entity.Entity[count];
try
{
int[] data = new int[count * 3];
Marshal.Copy(buf, data, 0, count * 3);
for (int i = 0; i < count; i++)
{
int entityId = data[i * 3];
int mappedType = data[i * 3 + 1];
int isLiving = data[i * 3 + 2];
var entityType = Enum.IsDefined(typeof(Entity.EntityType), mappedType)
? (Entity.EntityType)mappedType
: Entity.EntityType.UNKNOWN;
if (entityType == Entity.EntityType.PLAYER)
{
var player = FourKit.GetPlayerByEntityId(entityId);
if (player != null)
{
result[i] = player;
continue;
}
}
if (isLiving == 1)
{
result[i] = new Entity.LivingEntity(entityId, entityType, dimId, 0, 0, 0);
}
else
{
var entity = new Entity.Entity();
entity.SetEntityIdInternal(entityId);
entity.SetEntityTypeInternal(entityType);
entity.SetDimensionInternal(dimId);
result[i] = entity;
}
}
}
finally
{
Marshal.FreeCoTaskMem(buf);
}
return result;
}
/// <summary>

View File

@@ -149,11 +149,11 @@ public static partial class FourKitHost
}
[UnmanagedCallersOnly]
public static void SetWorldEntityCallbacks(IntPtr getWorldEntities)
public static void SetWorldEntityCallbacks(IntPtr getWorldEntities, IntPtr getChunkEntities)
{
try
{
NativeBridge.SetWorldEntityCallbacks(getWorldEntities);
NativeBridge.SetWorldEntityCallbacks(getWorldEntities, getChunkEntities);
}
catch (Exception ex)
{

View File

@@ -174,7 +174,9 @@ public class Inventory : IEnumerable<ItemStack>
if (_items[slot] == null)
{
int added = Math.Min(64, remaining);
setItem(slot, new ItemStack(toAdd.getType(), added, toAdd.getDurability()));
var newItem = new ItemStack(toAdd.getType(), added, toAdd.getDurability());
newItem.setItemMetaInternal(toAdd.getItemMetaInternal()?.clone());
setItem(slot, newItem);
remaining -= added;
}
}

View File

@@ -222,6 +222,9 @@ internal static class NativeBridge
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int NativeGetWorldEntitiesDelegate(int dimId, out IntPtr outBuf);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int NativeGetChunkEntitiesDelegate(int dimId, int chunkX, int chunkZ, out IntPtr outBuf);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int NativeGetSkyLightDelegate(int dimId, int x, int y, int z);
@@ -306,6 +309,7 @@ internal static class NativeBridge
internal static NativeRegenerateChunkDelegate? RegenerateChunk;
internal static NativeRefreshChunkDelegate? RefreshChunk;
internal static NativeGetWorldEntitiesDelegate? GetWorldEntities;
internal static NativeGetChunkEntitiesDelegate? GetChunkEntities;
internal static NativeGetSkyLightDelegate? GetSkyLight;
internal static NativeGetBlockLightDelegate? GetBlockLight;
internal static NativeGetBiomeIdDelegate? GetBiomeId;
@@ -422,9 +426,10 @@ internal static class NativeBridge
RefreshChunk = Marshal.GetDelegateForFunctionPointer<NativeRefreshChunkDelegate>(refreshChunk);
}
internal static void SetWorldEntityCallbacks(IntPtr getWorldEntities)
internal static void SetWorldEntityCallbacks(IntPtr getWorldEntities, IntPtr getChunkEntities)
{
GetWorldEntities = Marshal.GetDelegateForFunctionPointer<NativeGetWorldEntitiesDelegate>(getWorldEntities);
GetChunkEntities = Marshal.GetDelegateForFunctionPointer<NativeGetChunkEntitiesDelegate>(getChunkEntities);
}
internal static void SetBlockInfoCallbacks(IntPtr getSkyLight, IntPtr getBlockLight, IntPtr getBiomeId, IntPtr setBiomeId)