I always ask the Builders of the Maizuma Creative Server what they would like to see added to the server and always get the same answer, World Edit.
Because our server is 100% Vanilla Minecraft, we won't add any Plugins or Mods. But that doesn't prevent us from adding World Edit, using command blocks!
Observation: Since command blocks started getting more advanced, World Edit has been a very generic term people used to show new creations that help building. What we mean by saying we will add "World Edit" is to add as many tools as we can to help our builders get the same experience as a server with mods or plugins.
Well, amongst various building tools we plan to add, today we will talk about a Custom Fill Command.
Like most servers, only the administrators have access to commands at the MCS. Other players can't use handy tools like the Fill command, so I made a custom one specially for that situation!
Fill Command - Force Mode
There are two modes in this tool. The first is "force", which acts like a normal fill, replacing all the blocks in an area to a selected one.
The said area is delimited by two position markers placed by the player, using a custom spawn egg. The egg will summon a generic entity at first, which will be specified depending on other position markers around it.
When you first place the marker, it'll turn itself into POS1 (Position 1). It will then start showing a 20x20x20 particle box, where you can place the second position.
The First Position, showing a particle box where you can place the second
If the marker is placed inside the box, it'll turn itself into POS2 (Position 2). It will also look for and delete any other previous POS2 in the area, so there's always only one of these.
If the marker is placed outside the box, it'll delete itself for being at an invalid position.
On top of that, if you place the POS2 at the same block as the POS1, they will both delete themselves so you can stop using the Fill tool.
To start filling, just placing another POS2 at the same place as the current POS2.Basically, placing the POS2 at the POS1 will delete both; placing POS2 at another POS2 with start filling; and placing the POS2 anywhere else will move the second position. Watch everything better in this GFY!
To choose the used block, place it at the POS1. You can use any block, even air.
The actual filling uses 3 clocks, for the Z, X and Y directions.
The first clock starts with an armour stand called FillZ at the POS1. Every clock cicle, all the FillZs will be teleported +1 block in the Z direction and a new one is summoned. We do that so that the age order of the FillZs is: the newest at the POS1, getting older the farther away you go.
The clock will stop when a FillZ is at the same X coordinate as the POS2, meaning it reached the limit of the fill area. It will then make all the FillZs clone the block behind them to their position.
Because the clones happen at the same time, the order execution will be from the newest to the oldest, meaning it will start cloning from the POS1, where the used block is, until the end when all the FillZs have the block cloned at them. This is done simply by using the following command:
/execute @e[tag=POS1] ~ ~ ~1 /execute @e[tag=FillZ,dz=18] ~ ~ ~ /clone ~ ~ ~-1 ~ ~ ~-1 ~ ~ ~
The same happens with the next clock, in the X direction, now summoning FillXs from the FillZs.
In the end, the "floor" of the fill area will be filled with your chosen block.
The last clock doesn't summon new entities. Every cicle it will teleport the already existing ones upwards and clone the blocks below them up, until it reaches the same height as the POS2.
After all that, the entire area from POS1 to POS2 will be filled with your chosen block!
And to show it better, here's another beautiful GFY of it working!
Entities showing the process of filling an area. Note that those are normally insivible
There is also a system to prevent two people from using a Fill at the same time, as it can cause problems. Apart from that, the system is pretty much it!
Fill Command - Replace Mode
Of course this wouldn't be complete without a replace mode.
It does pretty much what it says. You select a old block to be replaced and new one to take its place.
This mode works like the Force one, however, instead of straight out cloning the used block, it will first check if the block the entity (FillZ or FillX) is at should be replaced.
To do that, we will use the fearsome /stats command. With this, we can execute a /testforblocks command to compare if the block the entity is at is the same as the block to be replaced.
If the blocks are the same, the score of the entity in an objective will be set to 1; if not, it'll be set to 0. With the result, we clone the new block only at the entities with a score of 1.
And why not again, a third GFY to show this mode working!
Before and after using the Replace Mode of the Custom Fill Command
The process is not hard, however there are two things we have to be wary of.
First, when you set up a stat for the entity, you have to give it a score. It doesn't matter the amount, I usualy do /scoreboard players add @e[entity] <objective> 0 and it works great.
Also, we can't simply have the used block at POS1, like in the Force mode, and choose when to or not to clone it. The /testforblock and /clone commands have the limitation of accepting coordinates relative to only one location, so we need to have the used blocks (old and new) at absolute coords and then compare/ clone them back from there.
Welp, that's all I had to talk about.
As always, thank you for reading and I hope to see you soon!