Skip to content

Commit

Permalink
Add extra flag to update the entire plot
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul1365972 authored and StackDoubleFlow committed Dec 11, 2023
1 parent 0cad0c5 commit 2ff1eee
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ These are the commands that are currently implemented:
| `//replace` | None | Replace all blocks in a selection with another |
| `//copy` | `//c` | Copy the selection to the clipboard |
| `//cut` | `//x` | Cut the selection to the clipboard |
| `//paste` | `//v` | Paste the clipboard's contents (`-a` to copy air, `-u` to also update) |
| `//paste` | `//v` | Paste the clipboard's contents (`-a` to ignore air, `-u` to also update) |
| `//undo` | None | Undoes the last action (from history) |
| `//redo` | None | Redoes the last action (from history) |
| `//rstack` | `//rs` | Stack with more options, Refer to [RedstoneTools](https://github.com/paulikauro/RedstoneTools) |
Expand All @@ -136,7 +136,7 @@ These are the commands that are currently implemented:
| `//shift` | None | Shift the selection area |
| `//flip` | `//f` | Flip the contents of the clipboard across the origin |
| `//rotate` | `//r` | Rotate the contents of the clipboard |
| `//update` | None | Updates all blocks in the selection or entire plot |
| `//update` | None | Updates all blocks in the selection (`-p` to update the entire plot) |
| `//help` | None | Displays help for WorldEdit commands |

## Acknowledgments
Expand Down
31 changes: 18 additions & 13 deletions crates/core/src/plot/worldedit/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,21 +992,26 @@ pub(super) fn execute_rstack(ctx: CommandExecuteContext<'_>) {
pub(super) fn execute_update(ctx: CommandExecuteContext<'_>) {
let start_time = Instant::now();

let pos = match (ctx.player.first_position, ctx.player.second_position) {
(None, None) => Some(ctx.plot.get_corners()),
(Some(first_pos), Some(second_pos)) => Some((first_pos, second_pos)),
_ => None,
let (first_pos, second_pos) = if ctx.has_flag('p') {
ctx.plot.get_corners()
} else {
if let (Some(first_pos), Some(second_pos)) =
(ctx.player.first_position, ctx.player.second_position)
{
(first_pos, second_pos)
} else {
ctx.player
.send_error_message("Your selection is incomplete.");
return;
}
};
if let Some((first_pos, second_pos)) = pos {
update(ctx.plot, first_pos, second_pos);

ctx.player.send_worldedit_message(&format!(
"Your selection was updated sucessfully. ({:?})",
start_time.elapsed()
));
} else {
ctx.player.send_error_message("Your selection is incomplete.");
}
update(ctx.plot, first_pos, second_pos);

ctx.player.send_worldedit_message(&format!(
"Your selection was updated sucessfully. ({:?})",
start_time.elapsed()
));
}

pub(super) fn execute_replace_container(ctx: CommandExecuteContext<'_>) {
Expand Down
5 changes: 4 additions & 1 deletion crates/core/src/plot/worldedit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{Plot, PlotWorld};
use crate::player::{PacketSender, Player, PlayerPos};
use crate::redstone;
use crate::world::storage::PalettedBitBuffer;
use crate::world::{World, for_each_block_mut_optimized};
use crate::world::{for_each_block_mut_optimized, World};
use execute::*;
use mchprs_blocks::block_entities::{BlockEntity, ContainerType};
use mchprs_blocks::blocks::Block;
Expand Down Expand Up @@ -697,6 +697,9 @@ static COMMANDS: Lazy<HashMap<&'static str, WorldeditCommand>> = Lazy::new(|| {
description: "Updates all blocks in the selection",
permission_node: "mchprs.we.update",
requires_positions: false,
flags: &[
flag!('p', None, "Update the entire plot"),
],
..Default::default()
},
"/help" => WorldeditCommand {
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/redpiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod passes;

use crate::redpiler::passes::make_default_pass_manager;
use crate::redstone;
use crate::world::{World, for_each_block_mut_optimized};
use crate::world::{for_each_block_mut_optimized, World};
use backend::JITBackend;
use mchprs_blocks::blocks::Block;
use mchprs_blocks::BlockPos;
Expand Down
5 changes: 1 addition & 4 deletions crates/core/src/redpiler/passes/identify_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ impl<W: World> Pass<W> for IdentifyNodes {

let (first_pos, second_pos) = input.bounds;

let start_pos = first_pos.min(second_pos);
let end_pos = first_pos.max(second_pos);

for_each_block_optimized(plot, start_pos, end_pos, |pos| {
for_each_block_optimized(plot, first_pos, second_pos, |pos| {
for_pos(ignore_wires, plot, graph, pos)
});
}
Expand Down

0 comments on commit 2ff1eee

Please sign in to comment.