public static void OnTryChangeBlockUser(ModLoader.OnTryChangeBlockData userData) { if (userData.TypeNew == ItemTypes.IndexLookup.GetIndex("Ulfric.ColonyAddOns.Blocks.AppleBasket") && userData.TypeOld == BuiltinBlocks.Air) { Logger.Log("Check if area is clear for AppleFarmer"); Vector3Int position = userData.Position; int xlen = 7; int zlen = 7; int radius = 3; //set NW corner Vector3Int nwcorner = new Vector3Int(position.x - radius, position.y, position.z - radius); Vector3Int secorner = new Vector3Int(position.x + radius, position.y, position.z + radius); bool blocked = false; for (int x = 0; x <= xlen; x++) { for (int z = 0; z <= zlen; z++) { if (World.TryGetTypeAt(nwcorner.Add(x, 0, z), out ushort val) && val != BuiltinBlocks.Air) { blocked = true; } } } if (blocked) { Chat.Send(userData.RequestedByPlayer, "Apple Farmer 9 x 9 area is blocked."); } else { AreaJobTracker.CreateNewAreaJob("Ulfric.ColonyAddOns.AreaJobs.AppleFarm", userData.RequestedByPlayer, nwcorner, secorner); ThreadManager.InvokeOnMainThread(delegate() { ServerManager.TryChangeBlock(position, userData.TypeNew); }, 0.1f); } } if (userData.TypeOld == ItemTypes.IndexLookup.GetIndex("Ulfric.ColonyAddOns.Blocks.AppleBasket") && userData.TypeNew == BuiltinBlocks.Air) { Logger.Log("Remove job"); Vector3Int position = userData.Position; int xlen = 7; int zlen = 7; int radius = 3; //set NW corner Vector3Int nwcorner = new Vector3Int(position.x - radius, position.y, position.z - radius); Vector3Int secorner = new Vector3Int(position.x + radius, position.y, position.z + radius); AreaJobTracker.RemoveJobAt(nwcorner, secorner); } }