Esempio n. 1
0
        public override void OnBuild(WorldEdit.WorldEdit worldEdit, int oldBlockId, BlockSelection blockSel, ItemStack withItemStack)
        {
            if (treeGenerators == null)
            {
                treeGenerators = new TreeGeneratorsUtil(worldEdit.sapi);
            }

            if (TreeVariant == null)
            {
                worldEdit.Bad("Please select a tree variant first.");
                return;
            }

            //blockAccessRev.SetBlock(oldBlockId, blockSel.Position, withItemStack);
            worldEdit.sapi.World.BlockAccessor.SetBlock(oldBlockId, blockSel.Position);
            blockSel.Position.Add(blockSel.Face.Opposite); // - prevented trees from growing o.O   - seems to work again and with this disabled trees float in the air 0.O

            blockAccessRev.ReadFromStagedByDefault = true;

            treeGenerators.ReloadTreeGenerators();
            treeGenerators.RunGenerator(new AssetLocation(TreeVariant), blockAccessRev, blockSel.Position, MinTreeSize + (float)rand.NextDouble() * (MaxTreeSize - MinTreeSize));

            blockAccessRev.SetHistoryStateBlock(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, oldBlockId, blockAccessRev.GetStagedBlockId(blockSel.Position));
            blockAccessRev.Commit();
        }
Esempio n. 2
0
        public override void OnBuild(WorldEdit.WorldEdit worldEdit, ushort oldBlockId, BlockSelection blockSel, ItemStack withItemStack)
        {
            if (treeGenerators == null)
            {
                treeGenerators = new TreeGeneratorsUtil(worldEdit.sapi);
            }

            if (TreeVariant == null)
            {
                worldEdit.Bad("Please select a tree variant first.");
                return;
            }

            //blockAccessRev.SetBlock(oldBlockId, blockSel.Position, withItemStack);
            worldEdit.sapi.World.BlockAccessor.SetBlock(oldBlockId, blockSel.Position);
            blockSel.Position.Add(blockSel.Face.GetOpposite());

            blockAccessRev.ReadFromStagedByDefault = true;

            treeGenerators.ReloadTreeGenerators();
            treeGenerators.RunGenerator(new AssetLocation(TreeVariant), blockAccessRev, blockSel.Position.DownCopy(), MinTreeSize + (float)rand.NextDouble() * (MaxTreeSize - MinTreeSize));

            blockAccessRev.SetHistoryStateBlock(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, oldBlockId, blockAccessRev.GetStagedBlockId(blockSel.Position));
            blockAccessRev.Commit();
        }
Esempio n. 3
0
        public override void StartServerSide(ICoreServerAPI m)
        {
            this.api       = m;
            treeGenerators = new TreeGeneratorsUtil(m);

            m.RegisterCommand("wgen", "World generator tools", "[testmap|genmap|testnoise|chunk|region|pos|tree]", CmdWgen, Privilege.controlserver);

            m.Event.SaveGameLoaded += OnGameWorldLoaded;
            if (api.Server.CurrentRunPhase == EnumServerRunPhase.RunGame)
            {
                OnGameWorldLoaded();
            }

            //  api.WorldManager.AutoGenerateChunks = false;
        }
Esempio n. 4
0
        public WgenTreeSupplier(ICoreServerAPI api)
        {
            treeGenerators = new TreeGeneratorsUtil(api);

            this.api = api;
        }
Esempio n. 5
0
        public override bool OnWorldEditCommand(WorldEdit.WorldEdit worldEdit, CmdArgs args)
        {
            if (treeGenerators == null)
            {
                treeGenerators = new TreeGeneratorsUtil(worldEdit.sapi);
            }

            string cmd = args.PopWord();

            switch (cmd)
            {
            case "tsizemin":
            {
                float size = 0.7f;
                if (args.Length > 0)
                {
                    float.TryParse(args[0], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out size);
                }
                MinTreeSize = size;

                worldEdit.Good("Tree Min Size=" + size + " set.");

                return(true);
            }

            case "tsizemax":
            {
                float size = 0.7f;
                if (args.Length > 0)
                {
                    float.TryParse(args[0], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out size);
                }
                MaxTreeSize = size;

                worldEdit.Good("Tree Max Size=" + size + " set.");

                return(true);
            }

            case "tsize":
            {
                float min = 0.7f;
                if (args.Length > 0)
                {
                    float.TryParse(args[0], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out min);
                }
                MinTreeSize = min;

                float max = 1.3f;
                if (args.Length > 1)
                {
                    float.TryParse(args[1], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out max);
                }
                MaxTreeSize = max;

                worldEdit.Good("Tree Min Size=" + min + ", max size =" + MaxTreeSize + " set.");

                return(true);
            }

            case "trnd":
                return(true);

            case "tv":
                int index = 0;

                string variant = args.PopWord();

                bool numeric = int.TryParse(variant, NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out index);

                treeGenerators.ReloadTreeGenerators();

                if (numeric)
                {
                    var val = treeGenerators.GetGenerator(index);
                    if (val.Key == null)
                    {
                        worldEdit.Bad("No such tree variant found.");
                        return(true);
                    }

                    TreeVariant = val.Key.ToShortString();
                    worldEdit.Good("Tree variant " + val.Key + " set.");
                }
                else
                {
                    if (variant != null && treeGenerators.GetGenerator(new AssetLocation(variant)) != null)
                    {
                        TreeVariant = variant;
                        worldEdit.Good("Tree variant " + variant + " set.");
                    }
                    else
                    {
                        worldEdit.Bad("No such tree variant found.");
                    }
                }

                return(true);
            }

            return(false);
        }