1. How can i find cupboard based on a given Vector3 position with the new buidling 3.0.

    This is what i used before the update:
    Code:
            private BuildingPrivlidge GetCupboard(Vector3 position)
            {
                List<Collider> colliders = Facepunch.Pool.GetList<Collider>();
                Vis.Colliders(position, 0.1f, colliders, LayerMask.GetMask("Trigger"));
                foreach (Collider collider in colliders)
                {
                    BuildingPrivlidge tc = collider.GetComponentInParent<BuildingPrivlidge>();                if (tc == null)
                        continue;                return tc;
                }
                return null;
            }
    
     
  2. Wtf???? Why you use GetComponentInParent? it's very slow
    Use ToBaseEntity
     
  3. Now you mentioned it... This is pretty old code from a very old plugin i have running haha :)
     
  4. From what i know, it's necessary to find the nearest BuildingBlock, get Building from BuildingManager by its ID and check if this structure has TC.
    There could be better ways, probably, but i haven't found them yet.
     
  5. I can find all building blocks that belongs to a cupboard, but isn't that expensive to loop over each building entity?
     
  6. Yes it is, but you always can break this process to multiple batches.
     
  7. Haven't tested it yet, but it seems FacePunch uses the following code to check for building priv's based on OBB input;

    Code:
      public BuildingPrivlidge GetBuildingPrivilege(OBB obb)
      {
        BuildingBlock buildingBlock1 = (BuildingBlock) null;
        BuildingPrivlidge buildingPrivlidge = (BuildingPrivlidge) null;
        System.Collections.Generic.List<BuildingBlock> list = Facepunch.Pool.GetList<BuildingBlock>();
        Vis.Entities<BuildingBlock>(obb.position, 16f + obb.extents.magnitude, list, 2097152, QueryTriggerInteraction.Collide);
        for (int index = 0; index < list.Count; ++index)
        {
          BuildingBlock buildingBlock2 = list[index];
          if (buildingBlock2.isServer == this.isServer && buildingBlock2.IsOlderThan((BaseEntity) buildingBlock1) && (double) obb.Distance(buildingBlock2.WorldSpaceBounds()) <= 16.0)
          {
            BuildingManager.Building building = buildingBlock2.GetBuilding();
            if (building != null)
            {
              BuildingPrivlidge buildingPrivilege = building.GetDominatingBuildingPrivilege();
              if (!((UnityEngine.Object) buildingPrivilege == (UnityEngine.Object) null))
              {
                buildingBlock1 = buildingBlock2;
                buildingPrivlidge = buildingPrivilege;
              }
            }
          }
        }
        Facepunch.Pool.FreeList<BuildingBlock>(ref list);
        return buildingPrivlidge;
      }
    
     
  8. Do you have any proof for this? In my rather small amount of testing, ToBaseEntity almost always seemed slower.
     
  9. Sorry, you're right
    [​IMG]