private static void ProcessSleepers(Prefab prefab, World world, Vector3i dest) { for (var index = 0; index < prefab.SleeperVolumesStart.Count; ++index) { if (!prefab.SleeperVolumeUsed[index]) { continue; } var volStart = prefab.SleeperVolumesStart[index]; var volSize = prefab.SleeperVolumesSize[index]; var volMax = volStart + volSize; var volStartDest = volStart + dest; var volMaxDest = volMax + dest; var chunkXz1 = World.toChunkXZ(volStartDest.x); var chunkXz2 = World.toChunkXZ(volMaxDest.x); var chunkXz3 = World.toChunkXZ(volStartDest.z); var chunkXz4 = World.toChunkXZ(volMaxDest.z); var volume = SleeperVolume.Create(prefab.SleeperVolumesGroup[index], volStartDest, volMaxDest, dest, prefab.SleeperVolumeGameStageAdjust[index]); var volKey = world.AddSleeperVolume(volume); AddSleeperSpawns(prefab, index, dest, volume, volStart, volMax); for (var chunkX = chunkXz1; chunkX <= chunkXz2; ++chunkX) { for (var chunkZ = chunkXz3; chunkZ <= chunkXz4; ++chunkZ) { var chunkSync = (Chunk)world.GetChunkSync(chunkX, 0, chunkZ); if (chunkSync != null) { chunkSync.GetSleeperVolumes().Add(volKey); } } } } }
public BCMSleeperVolume(int index, [NotNull] SleeperVolume volume, [NotNull] World world) { Index = index; var volumeGroup = typeof(SleeperVolume).GetField(VolumeGroupFieldName, BindingFlags.NonPublic | BindingFlags.Instance); if (volumeGroup != null) { if (!(volumeGroup.GetValue(volume) is string name)) { return; } Group = name; } Position = new BCMVector3(volume.mins); Extent = new BCMVector3(volume.maxs); Size = new BCMVector3(volume.maxs - volume.mins + Vector3i.one); var timer = typeof(SleeperVolume).GetField(TimerFieldName, BindingFlags.NonPublic | BindingFlags.Instance); if (timer == null) { return; } if (!(timer.GetValue(volume) is ulong timerValue)) { return; } if (timerValue > world.worldTime) { RespawnTimer = Math.Round((timerValue - world.worldTime) / 24000f, 2); } }
private static void ProcessSleepers(Prefab prefab, WorldBase world, Chunk chunk, Vector3i dest) { var chunkPosMin = Vector3i.zero; var chunkPosMax = Vector3i.zero; if (chunk != null) { chunkPosMin = chunk.GetWorldPos(); chunkPosMax = chunkPosMin + new Vector3i(16, 256, 16); } for (var index = 0; index < prefab.SleeperVolumesStart.Count; ++index) { if (!prefab.SleeperVolumeUsed[index]) { continue; } var volStart = prefab.SleeperVolumesStart[index]; var volSize = prefab.SleeperVolumesSize[index]; var volMax = volStart + volSize; var volStartDest = volStart + dest; var volMaxDest = volMax + dest; if (chunk != null) { if ((volStartDest.x >= chunkPosMax.x || volMaxDest.x <= chunkPosMin.x || volStartDest.y >= chunkPosMax.y || volMaxDest.y <= chunkPosMin.y || volStartDest.z >= chunkPosMax.z ? 1 : (volMaxDest.z <= chunkPosMin.z ? 1 : 0)) != 0) { continue; } var volKey = world.FindSleeperVolume(volStartDest, volMaxDest); if (volKey == -1) { var volume = SleeperVolume.Create(prefab.SleeperVolumesGroup[index], volStartDest, volMaxDest, dest, prefab.SleeperVolumeGameStageAdjust[index]); volKey = world.AddSleeperVolume(volume); AddSleeperSpawns(prefab, index, dest, volume, volStart, volMax); } chunk.GetSleeperVolumes().Add(volKey); } else { var chunkXz1 = World.toChunkXZ(volStartDest.x); var chunkXz2 = World.toChunkXZ(volMaxDest.x); var chunkXz3 = World.toChunkXZ(volStartDest.z); var chunkXz4 = World.toChunkXZ(volMaxDest.z); var volume = SleeperVolume.Create(prefab.SleeperVolumesGroup[index], volStartDest, volMaxDest, dest, prefab.SleeperVolumeGameStageAdjust[index]); var volKey = world.AddSleeperVolume(volume); AddSleeperSpawns(prefab, index, dest, volume, volStart, volMax); for (var chunkX = chunkXz1; chunkX <= chunkXz2; ++chunkX) { for (var chunkZ = chunkXz3; chunkZ <= chunkXz4; ++chunkZ) { ((Chunk)world.GetChunkSync(chunkX, 0, chunkZ))?.GetSleeperVolumes().Add(volKey); } } } } }
public BCMSleeperVolumeDetialed(int index, SleeperVolume volume, World world) : base(index, volume, world) { var spawns = typeof(SleeperVolume).GetField("VH", BindingFlags.NonPublic | BindingFlags.Instance); if (spawns != null) { if (!(spawns.GetValue(volume) is List <SleeperVolume.SpawnPoint> spawnPoints)) { return; } SpawnPoints = spawnPoints.Select(sp => new BCMSpawnPoint(sp)).ToList(); } //todo: list active spawns and counters }
private static void AddSleeperSpawns(Prefab prefab, int idx, Vector3i dest, SleeperVolume volume, Vector3i volStart, Vector3i volMax) { var startX = Mathf.Max(volStart.x, 0); var startY = Mathf.Max(volStart.y, 0); var startZ = Mathf.Max(volStart.z, 0); var sizeX = Mathf.Min(prefab.size.x, volMax.x); var sizeY = Mathf.Min(prefab.size.y, volMax.y); var sizeZ = Mathf.Min(prefab.size.z, volMax.z); for (var x = startX; x < sizeX; ++x) { var destX = x + dest.x; for (var z = startZ; z < sizeZ; ++z) { var destZ = z + dest.z; for (var y = startY; y < sizeY; ++y) { var blockValue = prefab.GetBlock(x, y, z); var block = Block.list[blockValue.type]; if (!block.IsSleeperBlock) { continue; } var flag = false; var point = new Vector3i(x, y, z); for (var index = 0; index < prefab.SleeperVolumesStart.Count; ++index) { if (index == idx || !prefab.SleeperVolumeUsed[index] || !prefab.SleeperIsLootVolume[index] || !prefab.CheckSleeperVolumesContainPoint(index, point)) { continue; } flag = true; break; } if (!flag) { volume.AddSpawnPoint(destX, y + dest.y, destZ, (BlockSleeper)block, blockValue); } } } } }