public WallsCommand(User user, string blockType) : base(user) { if (!this.UserSession.Selection.IsSet()) { throw new WorldEditCommandException("Please set both points first!"); } this.blockType = BlockUtils.GetBlockType(blockType) ?? throw new WorldEditCommandException($"No BlockType with name {blockType} found!"); }
public ReplaceCommand(User user, string findType, string replaceType) : base(user) { if (!this.UserSession.Selection.IsSet()) { throw new WorldEditCommandException("Please set both points first!"); } this.blockTypeToFind = BlockUtils.GetBlockType(findType) ?? throw new WorldEditCommandException($"No BlockType with name {findType} found!"); this.blockTypeToReplace = null; if (replaceType != string.Empty) { this.blockTypeToReplace = BlockUtils.GetBlockType(replaceType) ?? throw new WorldEditCommandException($"No BlockType with name {replaceType} found!"); } }
public static void Set(User user, string pTypeName) { try { WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.FirstPos == null || weud.SecondPos == null) { user.Player.SendTemporaryMessage($"Please set both Points with the Wand Tool first!"); return; } Type blockType = BlockUtils.GetBlockType(pTypeName); if (blockType == null) { user.Player.SendTemporaryMessage($"No BlockType with name {pTypeName} found!"); return; } var vectors = weud.GetSortedVectors(); weud.StartEditingBlocks(); long changedBlocks = 0; for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X) { for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++) { for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z) { var pos = new Vector3i(x, y, z); weud.AddBlockChangedEntry(Eco.World.World.GetBlock(pos), pos); WorldEditManager.SetBlock(blockType, pos); changedBlocks++; } } } user.Player.SendTemporaryMessage($"{changedBlocks} blocks changed."); } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Replace(User user, string pTypeNames = "") { try { string[] splitted = pTypeNames.Split(' '); string toFind = splitted[0].ToLower(); string toReplace = string.Empty; if (splitted.Length >= 2) { toReplace = pTypeNames.Split(' ')[1].ToLower(); } WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.FirstPos == null || weud.SecondPos == null) { user.Player.SendTemporaryMessage($"Please set both points with the Wand Tool first!"); return; } Type blockTypeToFind = BlockUtils.GetBlockType(toFind); if (blockTypeToFind == null) { user.Player.SendTemporaryMessage($"No BlockType with name {toFind} found!"); return; } Type blockTypeToReplace = null; if (toReplace != string.Empty) { blockTypeToReplace = BlockUtils.GetBlockType(toReplace); if (blockTypeToReplace == null) { user.Player.SendTemporaryMessage($"No BlockType with name { toReplace } found!"); return; } } var vectors = weud.GetSortedVectors(); long changedBlocks = 0; //if toReplace is string empty we will replace everything except empty with toFind type weud.StartEditingBlocks(); if (toReplace != string.Empty) { for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X) { for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++) { for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z) { var pos = new Vector3i(x, y, z); var block = Eco.World.World.GetBlock(pos); if (block != null && block.GetType() == blockTypeToFind) { weud.AddBlockChangedEntry(block, pos); WorldEditManager.SetBlock(blockTypeToReplace, pos); changedBlocks++; } } } } } else { for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X) { for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++) { for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z) { var pos = new Vector3i(x, y, z); var block = Eco.World.World.GetBlock(pos); if (block != null && block.GetType() != typeof(EmptyBlock)) { weud.AddBlockChangedEntry(block, pos); WorldEditManager.SetBlock(blockTypeToFind, pos); changedBlocks++; } } } } } user.Player.SendTemporaryMessage($"{changedBlocks} blocks changed."); } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }