コード例 #1
0
        public override void OnBuild(WorldEdit worldEdit, int oldBlockId, BlockSelection blockSel, ItemStack withItemStack)
        {
            if (blockDatas == null)
            {
                LoadBlockdatas(worldEdit.sapi);
            }
            if (blockDatas.Length == 0)
            {
                return;
            }

            worldEdit.sapi.World.BlockAccessor.SetBlock(oldBlockId, blockSel.Position);

            BlockSchematic blockData = blockDatas[nextRnd];

            nextRnd = rand.Next(blockDatas.Length);

            BlockPos originPos = blockData.GetStartPos(blockSel.Position, Origin);

            blockData.Init(blockAccessRev);
            blockData.Place(blockAccessRev, worldEdit.sapi.World, originPos, ReplaceMode, worldEdit.ReplaceMetaBlocks);

            blockAccessRev.SetHistoryStateBlock(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, oldBlockId, blockAccessRev.GetStagedBlockId(blockSel.Position));
            blockAccessRev.Commit();
            blockData.PlaceEntitiesAndBlockEntities(blockAccessRev, worldEdit.sapi.World, originPos);
            blockData.PlaceDecors(blockAccessRev, originPos, true);
            blockAccessRev.CommitBlockEntityData();


            if (RandomRotate)
            {
                SetRandomAngle(worldEdit.sapi.World);
            }
            workspace.ResendBlockHighlights(worldEdit);
        }
コード例 #2
0
        private void ImportArea(string filename, BlockPos startPos, EnumOrigin origin)
        {
            string infilepath = Path.Combine(exportFolderPath, filename);

            if (!File.Exists(infilepath) && File.Exists(infilepath + ".json"))
            {
                infilepath += ".json";
            }

            if (!File.Exists(infilepath))
            {
                Bad("Can't import " + filename + ", it does not exist");
                return;
            }

            BlockSchematic blockdata = null;

            try
            {
                using (TextReader textReader = new StreamReader(infilepath))
                {
                    blockdata = JsonConvert.DeserializeObject <BlockSchematic>(textReader.ReadToEnd());
                    textReader.Close();
                }
            }
            catch (IOException e)
            {
                Good("Failed loading " + filename + " : " + e.Message);
                return;
            }

            BlockPos originPos = startPos.Copy();

            if (origin == EnumOrigin.TopCenter)
            {
                originPos.X -= blockdata.SizeX / 2;
                originPos.Y -= blockdata.SizeY;
                originPos.Z -= blockdata.SizeZ / 2;
            }
            if (origin == EnumOrigin.BottomCenter)
            {
                originPos.X -= blockdata.SizeX / 2;
                originPos.Z -= blockdata.SizeZ / 2;
            }


            IBlockAccessor blockAcccessor = api.WorldManager.GetBlockAccessorBulkUpdate(true, true, false);

            blockdata.Place(blockAcccessor, api.World, originPos);

            blockAcccessor.Commit();
        }
コード例 #3
0
        private void PasteBlockData(BlockSchematic blockData, BlockPos startPos, EnumOrigin origin)
        {
            BlockPos originPos = blockData.GetStartPos(startPos, origin);

            EnumAxis?axis = null;

            if (workspace.ImportFlipped)
            {
                axis = EnumAxis.Y;
            }

            BlockSchematic rotated = blockData.ClonePacked();

            rotated.TransformWhilePacked(sapi.World, origin, workspace.ImportAngle, axis);

            rotated.Init(workspace.revertableBlockAccess);
            rotated.Place(workspace.revertableBlockAccess, sapi.World, originPos, EnumReplaceMode.ReplaceAll, ReplaceMetaBlocks);
            workspace.revertableBlockAccess.Commit();

            blockData.PlaceEntitiesAndBlockEntities(workspace.revertableBlockAccess, sapi.World, originPos);
        }
コード例 #4
0
        private void PasteSchematic(BlockSchematic blockData, BlockPos startPos, EnumOrigin origin = EnumOrigin.MiddleCenter)
        {
            BlockPos originPos = blockData.GetStartPos(startPos, origin);

            blockData.Place(sapi.World.BlockAccessor, sapi.World, originPos);
        }