Created
May 4, 2014 07:37
-
-
Save dotStart/aa152c4f340fddb6cfe1 to your computer and use it in GitHub Desktop.
Clone Command Block MCEdit filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clone Command Block MCEdit Filter | |
================================= | |
This filter helps you to clone big structures from one position to any other | |
position in the level (as long as it is loaded). To achieve this it splits up | |
the zone in smaller 15x15x15 chunks which may be copied even though the overall | |
structure has more than 4096 blocks. | |
Usage | |
----- | |
* Select the source structure | |
* Select the clone filter and select the mode "source" | |
* Filter the region | |
* Select the target region (same size!) | |
* Select the clone filter and select the mode "target" | |
* Filter the region | |
* Select the clone filter and select the mode "generate" | |
* Click Filter | |
* Save the resulting schematic | |
* Load it and place it where ever you want | |
Please note that you will have to save a schematic and load it again to use the | |
filter accordingly. This is sadly a problem I couldn't work around (yet). But due | |
to this method you will be able to place the command blocks correctly wherever you | |
want without selecting a region which needs to be big enough for the filter to work. | |
One additional note: I'm using 15x15x15 zones here to work around a problem I discovered | |
within the /clone command. Even though the block limit (4096 blocks) would suggest that | |
the maximum size of a zone is 16x16x16 it will not work with this code (I might be missing | |
something small here). That said the code seems to run perfectly with a zone of 15x15x15. | |
If you ever experience any problems with this region size, you may change the ```COMMAND_CHUNK_SIZE``` | |
constant to shrink or expand all sub-zones. | |
Please leave a comment below if you know a way to directly open a schematic in the | |
editor the same way to copy tool does or something similarly easy to use. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Copyright (C) 2014 Evil-Co <http://wwww.evil-co.com> | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
# import leveleditor | |
import math | |
import mcplatform | |
import mcedit | |
from pymclevel import MCSchematic | |
from pymclevel import TAG_Byte, TAG_Compound, TAG_Int, TAG_String | |
# MCEdit information | |
# displayName = "Create Clone Command Blocks" | |
inputs = ( | |
("Mode:", ("source", "target", "generate")), | |
) | |
# Constants | |
COMMAND_CHUNK_SIZE = 15; | |
# Global Variables | |
try: | |
sourceBox | |
except NameError: | |
sourceBox = None | |
try: | |
targetBox | |
except NameError: | |
targetBox = None | |
# | |
# Filter method | |
# | |
def perform(level, box, options): | |
# import globals | |
global sourceBox, targetBox | |
# store source location | |
if (options["Mode:"] == "source"): | |
sourceBox = box; | |
# store target location | |
elif (options["Mode:"] == "target"): | |
targetBox = box; | |
# process | |
else: | |
# get sizes | |
sourceSizeX, sourceSizeY, sourceSizeZ = sourceBox.size | |
targetSizeX, targetSizeY, targetSizeZ = targetBox.size | |
# check for errors | |
if (sourceSizeX > targetSizeX or sourceSizeY > targetSizeY or sourceSizeZ > targetSizeZ): | |
raise Exception ("The target volume is smaller than the source volume (source: " + str (sourceSizeX) + ", " + str (sourceSizeY) + ", " + str (sourceSizeZ) + "; target: " + str (targetSizeX) + ", " + str (targetSizeY) + ", " + str (targetSizeZ) + ")") | |
# get sizes | |
sizeX = (sourceBox.maxx - sourceBox.minx) | |
sizeY = (sourceBox.maxy - sourceBox.miny) | |
sizeZ = (sourceBox.maxz - sourceBox.minz) | |
# get sub volumes | |
volumeX = int (math.ceil ((float (sizeX) / float (COMMAND_CHUNK_SIZE)))) | |
volumeY = int (math.ceil ((float (sizeY) / float (COMMAND_CHUNK_SIZE)))) | |
volumeZ = int (math.ceil ((float (sizeZ) / float (COMMAND_CHUNK_SIZE)))) | |
# create schematic | |
schematic = MCSchematic ((volumeX, volumeY, volumeZ), mats = level.materials) | |
# generate a lot of command blocks | |
for x in xrange (0, volumeX): | |
for y in xrange (0, volumeY): | |
for z in xrange (0, volumeZ): | |
# calculate chunk position | |
sourceStartX = (sourceBox.minx + (COMMAND_CHUNK_SIZE * x)) | |
sourceStartY = (sourceBox.miny + (COMMAND_CHUNK_SIZE * y)) | |
sourceStartZ = (sourceBox.minz + (COMMAND_CHUNK_SIZE * z)) | |
sourceEndX = (sourceStartX + COMMAND_CHUNK_SIZE) | |
sourceEndY = (sourceStartY + COMMAND_CHUNK_SIZE) | |
sourceEndZ = (sourceStartZ + COMMAND_CHUNK_SIZE) | |
targetStartX = (targetBox.minx + (COMMAND_CHUNK_SIZE * x)) | |
targetStartY = (targetBox.miny + (COMMAND_CHUNK_SIZE * y)) | |
targetStartZ = (targetBox.minz + (COMMAND_CHUNK_SIZE * z)) | |
# cap sizes | |
if (sourceEndX > sourceBox.maxx): | |
sourceEndX = sourceBox.maxx | |
if (sourceEndY > sourceBox.maxy): | |
sourceEndY = sourceBox.maxy | |
if (sourceEndZ > sourceBox.maxz): | |
sourceEndZ = sourceBox.maxz | |
# create command | |
command = "/clone {} {} {} {} {} {} {} {} {}".format (sourceStartX, sourceStartY, sourceStartZ, sourceEndX, sourceEndY, sourceEndZ, targetStartX, targetStartY, targetStartZ) | |
# create block | |
schematic.setBlockAt (x, y, z, 137) | |
schematic.setBlockDataAt (x, y, z, 0) | |
# create TileEntity | |
tileEntity = TAG_Compound () | |
tileEntity["id"] = TAG_String ("Control") | |
tileEntity["x"] = TAG_Int (x) | |
tileEntity["y"] = TAG_Int (y) | |
tileEntity["z"] = TAG_Int (z) | |
tileEntity["Command"] = TAG_String (command) | |
tileEntity["TackOutput"] = TAG_Byte (0) | |
schematic.TileEntities.append (tileEntity) | |
# Display schematic | |
# editor.addCopiedSchematic (schematic) | |
# Save as schematic | |
schematic_file = mcplatform.askSaveFile ((mcplatform.lastSchematicsDir or mcplatform.schematicsDir), "Save Schematic As...", "", "Schematic\0*.schematic\0\0", ".schematic") | |
# Catch errors | |
if schematic_file == None: | |
print "ERROR: No schematic filename provided!" | |
return | |
# Save | |
schematic.saveToFile(schematic_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment