Beispiel #1
0
        public static WorldEditBlock CreateEmpty(Vector3i originalPosition, Vector3i offsetPosition)
        {
            Vector3i       relativePosition = originalPosition - offsetPosition;
            WorldEditBlock worldEditBlock   = new WorldEditBlock();

            worldEditBlock.Position         = relativePosition;
            worldEditBlock.OffsetPosition   = offsetPosition;
            worldEditBlock.OriginalPosition = originalPosition;
            worldEditBlock.BlockType        = typeof(EmptyBlock);
            return(worldEditBlock);
        }
Beispiel #2
0
        public static WorldEditBlock Create(Block block, Vector3i originalPosition, Vector3i offsetPosition)
        {
            Vector3i relativePosition = originalPosition - offsetPosition;

            WorldEditBlock worldEditBlock = new WorldEditBlock();

            worldEditBlock.Position         = relativePosition;
            worldEditBlock.OffsetPosition   = offsetPosition;
            worldEditBlock.OriginalPosition = originalPosition;
            worldEditBlock.BlockType        = block.GetType();


            switch (block)
            {
            case PlantBlock plantBlock:
            case TreeBlock treeBlock:
                //Log.Debug($"{worldEditBlock.BlockType.ToString()} at {originalPosition} is a PlantBlock or TreeBlock");
                Plant plant = EcoSim.PlantSim.GetPlant(originalPosition);
                if (plant != null)
                {
                    worldEditBlock.Position  = plant.Position.XYZi - offsetPosition;
                    worldEditBlock.BlockData = WorldEditPlantBlockData.From(plant);
                }
                else
                {
                    worldEditBlock.BlockType = typeof(EmptyBlock);
                }
                break;

            case WorldObjectBlock objectBlock:
                //Log.Debug($"{worldEditBlock.BlockType.ToString()} at {originalPosition} is a WorldObjectBlock");
                WorldObject worldObject = objectBlock.WorldObjectHandle.Object;
                worldEditBlock.BlockData = WorldEditWorldObjectBlockData.From(worldObject);
                relativePosition         = worldObject.Position3i - offsetPosition;
                worldEditBlock.Position  = relativePosition;
                break;

            case EmptyBlock emptyBlock:
                //Log.Debug($"{worldEditBlock.BlockType.ToString()} at {originalPosition} is a EmptyBlock");
                break;

            default:
                //Log.Debug($"{worldEditBlock.BlockType.ToString()} at {originalPosition} is a Block");
                System.Reflection.ConstructorInfo constuctor = worldEditBlock.BlockType.GetConstructor(Type.EmptyTypes);
                if (constuctor == null)
                {
                    throw new ArgumentOutOfRangeException(message: "Block type is not supported", paramName: worldEditBlock.BlockType.FullName);
                }
                if (BlockContainerManager.Obj.IsBlockContained(originalPosition))
                {
                    worldEditBlock.BlockType = typeof(EmptyBlock);
                    WorldObject obj = ServiceHolder <IWorldObjectManager> .Obj.All.Where(x => x.Position3i.Equals(originalPosition)).FirstOrDefault();

                    if (obj != null)
                    {
                        worldEditBlock.BlockType = typeof(WorldObjectBlock);
                        worldEditBlock.BlockData = WorldEditWorldObjectBlockData.From(obj);
                        relativePosition         = obj.Position3i - offsetPosition;
                        worldEditBlock.Position  = relativePosition;
                    }
                }
                break;
            }

            return(worldEditBlock);
        }