Beispiel #1
0
def perform(level, box, options):
    premadehead = safeheads[options["Premade Heads"]]
    customhead = options["Custom Head:"]
    override = options["Override all existing custom heads"]
    empty = ""

    for (chunk, slices, point) in level.getChunkSlices(box):
        for te in chunk.TileEntities:
            x = te["x"].value
            y = te["y"].value
            z = te["z"].value

            if (x, y, z) in box:
                if override:
                    if customhead != empty:
                        te["ExtraType"] = TAG_String(customhead)

                    if customhead == empty:
                        te["ExtraType"] = TAG_String(premadehead)

                if not override:
                    if customhead != empty:
                        if te["ExtraType"].value == "":
                            te["ExtraType"] = TAG_String(customhead)

                    if customhead == empty:
                        if te["ExtraType"].value == "":
                            te["ExtraType"] = TAG_String(premadehead)

                chunk.dirty = True
def createCommandBlock(x, y, z, command):
    commandBlock = TAG_Compound()
    commandBlock["id"] = TAG_String("Control")
    commandBlock["x"] = TAG_Int(x)
    commandBlock["y"] = TAG_Int(y)
    commandBlock["z"] = TAG_Int(z)
    commandBlock["Command"] = TAG_String(command)
    commandBlock["SuccessCount"] = TAG_Int(0)
    commandBlock["LastOutput"] = TAG_String("")
    commandBlock["TrackOutput"] = TAG_Byte(0)
    return commandBlock
Beispiel #3
0
        def change_value(data):
            s, i, c, d = data
            s = int(s)
            s_idx = 0
            if s in slots_set:
#                for slot in self.data['Player']['Inventory']:
                for slot in inventory:
                    if slot['Slot'].value == s:
                        if not i or int(c) < 1:
                            del inventory[s_idx]
                            i = ""
                            c = u'0'
                            d = u'0'
                        else:
                            slot['id'].value = 'minecraft:%s'%i
                            slot['Count'].value = int(c)
                            slot['Damage'].value = int(d)
                        break
                    s_idx += 1
            else:
                new_slot = TAG_Compound()
                new_slot['Slot'] = TAG_Byte(s)
                new_slot['id'] = TAG_String('minecraft:%s'%i)
                new_slot['Count'] = TAG_Byte(int(c))
                new_slot['Damage'] = TAG_Short(int(d))
                idx = s
                for slot in inventory:
                    if slot['Slot'].value >= s:
                        idx = slot['Slot'].value
                        break
                inventory.insert(s, new_slot)
                slots_set.append(s)
            table.slots[s] = slots[s] = s, i, c, d
Beispiel #4
0
def perform(level, box, options):
    if box.width == 1 and box.height == 1 and box.length == 1 and level.blockAt(
            box.minx, box.miny, box.minz) == 0:
        level.setBlockAt(box.minx, box.miny, box.minz, 54)
        chest = TAG_Compound()
        chest["Items"] = TAG_List()
        chest["id"] = TAG_String(u'Chest')
        chest["x"] = TAG_Int(box.minx)
        chest["y"] = TAG_Int(box.miny)
        chest["z"] = TAG_Int(box.minz)
        chunk = level.getChunk(box.minx / 16, box.minz / 16)
        chunk.TileEntities.append(chest)
        chunk.dirty = True
    for (chunk, slices, point) in level.getChunkSlices(box):
        for t in chunk.TileEntities:
            x = t["x"].value
            y = t["y"].value
            z = t["z"].value
            if x >= box.minx and x < box.maxx and y >= box.miny and y < box.maxy and z >= box.minz and z < box.maxz:
                if "Items" in t:
                    foundFirework = False
                    for item in t["Items"]:
                        if item["id"].value == 401:
                            foundFirework = True
                            if not "tag" in item:
                                item["tag"] = TAG_Compound()
                            if not "Fireworks" in item["tag"]:
                                item["tag"]["Fireworks"] = TAG_Compound()
                            if not "Explosions" in item["tag"][
                                    "Fireworks"] or options[
                                        "Overwrite Existing Explosions"]:
                                item["tag"]["Fireworks"][
                                    "Explosions"] = TAG_List()
                            item["tag"]["Fireworks"]["Flight"] = TAG_Byte(
                                options["Flight"])
                            item["tag"]["Fireworks"]["Explosions"].append(
                                createExplosionFromOptions(options))
                            chunk.dirty = True
                    if not foundFirework:
                        freeSlots = getFreeSlots(t)
                        if len(freeSlots) > 0:
                            fireworkItem = TAG_Compound()
                            fireworkItem["id"] = TAG_Short(401)
                            fireworkItem["Damage"] = TAG_Short(0)
                            fireworkItem["Slot"] = TAG_Byte(freeSlots[0])
                            fireworkItem["Count"] = TAG_Byte(64)
                            fireworkItem["tag"] = TAG_Compound()
                            fireworkItem["tag"]["Fireworks"] = TAG_Compound()
                            fireworkItem["tag"]["Fireworks"][
                                "Explosions"] = TAG_List()
                            fireworkItem["tag"]["Fireworks"][
                                "Flight"] = TAG_Byte(options["Flight"])
                            fireworkItem["tag"]["Fireworks"][
                                "Explosions"].append(
                                    createExplosionFromOptions(options))
                            t["Items"].append(fireworkItem)
                            chunk.dirty = True
        def change_value(data):
            s, i, c, d = data
            s = int(s)
            s_idx = 0
            #&# Prototype for blocks/items names
            name, state = map_items.get(mclangres.untranslate(i), (i, '0'))
            if ':' not in name:
                name = 'minecraft:%s' % name
            #&#

            if s in slots_set:
                for slot in inventory:
                    if slot['Slot'].value == s:
                        if not i or int(c) < 1:
                            del inventory[s_idx]
                            i = ""
                            c = u'0'
                            d = u'0'
                        else:
                            #&# Prototype for blocks/items names
                            #slot['id'].value = 'minecraft:%s'%i
                            slot['id'].value = name
                            #&#
                            slot['Count'].value = int(c)
                            slot['Damage'].value = int(state)
                        break
                    s_idx += 1
            else:
                new_slot = TAG_Compound()
                new_slot['Slot'] = TAG_Byte(s)
                #&# Prototype for blocka/items names
                #new_slot['id'] = TAG_String('minecraft:%s'%i)
                new_slot['id'] = TAG_String(name)
                #&#
                new_slot['Count'] = TAG_Byte(int(c))
                new_slot['Damage'] = TAG_Short(int(state))
                idx = s
                for slot in inventory:
                    if slot['Slot'].value >= s:
                        idx = slot['Slot'].value
                        break
                inventory.insert(s, new_slot)
                slots_set.append(s)
            #&# Prototype for blocks/items names
#            if i == name:
#                i = name
#&#
            if s >= 100:
                n = s - 100 + 36
            else:
                n = s
            table.slots[n] = slots[n] = s, i, c, state
Beispiel #6
0
def perform(level, box, options):
    cat = options["Cats"]
    dog = options["Dogs"]
    horse = options["Horses"]
    owner = options["Owner Name"]

    for (chunk, slices, point) in level.getChunkSlices(box):
        for e in chunk.Entities:
            x = e["Pos"][0].value
            y = e["Pos"][1].value
            z = e["Pos"][2].value

            if (x, y, z) in box:
                if e["id"].value == "Wolf" and dog:
                    e["Owner"] = TAG_String(owner)
                    chunk.dirty = True
                if e["id"].value == "Ozelot" and cat:
                    e["Owner"] = TAG_String(owner)
                    chunk.dirty = True
                if e["id"].value == "EntityHorse" and horse:
                    e["Tame"] = TAG_Byte(1)
                    e["OwnerName"] = TAG_String(owner)
                    chunk.dirty = True
Beispiel #7
0

# Where does the world file go?
i = 0
worlddir = None
while not worlddir or os.path.exists(worlddir):
    i += 1
    name = "world" + " " + map_type + " " + str(i)
    worlddir = os.path.join(minecraft_save_dir, name)

print "Creating world %s" % worlddir
world = mclevel.MCInfdevOldLevel(worlddir, create=True)
from pymclevel.nbt import TAG_Int, TAG_String, TAG_Byte_Array
tags = [
    TAG_Int(0, "MapFeatures"),
    TAG_String("flat", "generatorName"),
    TAG_String("0", "generatorOptions")
]
for tag in tags:
    world.root_tag['Data'].add(tag)

peak = [10, 255, 10]

print "Creating chunks."

x_extent = len(elevation)
x_min = 0
x_max = len(elevation)

z_min = 0
z_extent = len(elevation[0])
Beispiel #8
0
def perform(level, box, options):
    # Start Input gathering
    PLOS = options["Place Lines on signs"]
    FL = options["Filter Words"]
    SL1 = options["Sign Line #1:"]
    SL2 = options["Sign Line #2:"]
    SL3 = options["Sign Line #3:"]
    SL4 = options["Sign Line #4:"]
    FW1 = options["Filter Word #1:"]
    FW2 = options["Filter Word #2:"]
    FW3 = options["Filter Word #3:"]
    FW4 = options["Filter Word #4:"]
    RW1 = options["Replace Word #1:"]
    RW2 = options["Replace Word #2:"]
    RW3 = options["Replace Word #3:"]
    RW4 = options["Replace Word #4:"]
    # End input gathering

    if PLOS and FL:
        raise Exception(
            "Cannot Place Lines on sign and Filter Words \nIn the same filter run!"
        )
        return
    if not PLOS and not FL:
        raise Exception("What do you want me to do then?!?!")
        return

    for (chunk, slices, point) in level.getChunkSlices(box):
        for t in chunk.TileEntities:
            if t["id"].value == "Sign":
                x = t["x"].value
                y = t["y"].value
                z = t["z"].value

                if (x, y, z) in box:
                    Line1 = t["Text1"].value
                    Line2 = t["Text2"].value
                    Line3 = t["Text3"].value
                    Line4 = t["Text4"].value
                    if Line1 != "":
                        SL1 = Line1
                    if Line2 != "":
                        SL2 = Line2
                    if Line3 != "":
                        SL3 = Line3
                    if Line4 != "":
                        SL4 = Line4
                    if PLOS:
                        t["Text1"] = TAG_String(SL1)
                        t["Text2"] = TAG_String(SL2)
                        t["Text3"] = TAG_String(SL3)
                        t["Text4"] = TAG_String(SL4)
                        chunk.dirty = True

                    if FL:
                        time.sleep(0.5)
                        t["Text1"] = TAG_String(
                            replaceword(Line1, FW1, FW2, FW3, FW4, RW1, RW2,
                                        RW3, RW4))
                        t["Text2"] = TAG_String(
                            replaceword(Line2, FW1, FW2, FW3, FW4, RW1, RW2,
                                        RW3, RW4))
                        t["Text3"] = TAG_String(
                            replaceword(Line3, FW1, FW2, FW3, FW4, RW1, RW2,
                                        RW3, RW4))
                        t["Text4"] = TAG_String(
                            replaceword(Line4, FW1, FW2, FW3, FW4, RW1, RW2,
                                        RW3, RW4))
                        chunk.dirty = True
Beispiel #9
0
    world.saveInPlace()
    with open(tf, "a") as myfile:
        myfile.write("Saved %d chunks.\n" % numchunks)
        myfile.close()


with open(tf, "a") as myfile:
    myfile.write("Creating world %s\n" % worlddir)
    myfile.close()

world = mclevel.MCInfdevOldLevel(worlddir, create=True)
from pymclevel.nbt import TAG_Int, TAG_String, TAG_Byte_Array
# Set Data tags #
tags = [
    TAG_Int(0, "MapFeatures"),
    TAG_String("flat", "generatorName"),
    TAG_String("0", "generatorOptions"),
    nbt.TAG_Long(name='DayTime', value=4000)
]
for tag in tags:
    world.root_tag['Data'].add(tag)

# Set Game rules #
rule = nbt.TAG_Compound(name='GameRules',
                        value=[
                            TAG_String("false", "doDaylightCycle"),
                            TAG_String("false", "doMobSpawning")
                        ])
world.root_tag['Data'].add(rule)

# The code tracks the peak [x,y,z]
def perform(level, box, options):
	forward_offset = options['Forward offset']
	right_offset = options['Right offset']
	up_offset = options['Up offset']
	relative_position = options['Relative position']
	generate_surrounding_box = options['Generate surrounding box']
	if generate_surrounding_box:
		forward_offset += 1
		up_offset += 1
	if relative_position == 'North':
		execution_center = ((box.minx + box.maxx) // 2 - right_offset, box.miny - up_offset + 2, box.maxz + forward_offset - 1)
	elif relative_position == 'East':
		execution_center = (box.minx - forward_offset, box.miny - up_offset + 2, (box.minz + box.maxz) // 2 - right_offset)
	elif relative_position == 'South':
		execution_center = ((box.minx + box.maxx) // 2 + right_offset, box.miny - up_offset + 2, box.minz - forward_offset)
	elif relative_position == 'West':
		execution_center = (box.maxx + forward_offset - 1, box.miny - up_offset + 2, (box.minz + box.maxz) // 2 + right_offset)
	include_air = options['Include air']
	include_blocks = options['Include blocks']
	include_null_block_data = options['Include null block data']
	include_entities = options['Include entities']
	include_commandblockoutput_command = options['Include "gamerule commandBlockOutput false" command']
	include_logadmincommands_command = options['Include "gamerule logAdminCommands false" command']
	add_initialization_commands = options['Add initialization commands']
	add_finalization_commands = options['Add finalization commands']
	block_to_enqueue_input = re.split(r'\s*,\s*', options['Blocks to enqueue'].strip())
	blocks_to_enqueue = []
	for block_id in xrange(0, len(materials.block_map) - 1):
		if materials.block_map[block_id] in block_to_enqueue_input:
			blocks_to_enqueue.append(block_id)
	nbt_tags_to_ignore = re.split(r'\s*,\s*', options['NBT tags to ignore']) + ['x', 'y', 'z']
	save_command_to_file = options['Save the command to a file instead of to a Command Block']
	ignore_maximum_command_block_command_length = options['Ignore maximum Command Block command length']
	box_wall_material_block = options['Box wall material block']
	box_wall_material_data = options['Box wall material data value']
	box_floor_material_block = options['Box floor material block']
	box_floor_material_data = options['Box floor material data value']
	box_ceiling_material_block = options['Box ceiling material block']
	box_ceiling_material_data = options['Box ceiling material data value']
	add_box_signs = options['Add box signs']

	add_credits = True

	command = 'summon minecraft:falling_block ~ ~1 ~ {id:"minecraft:falling_block",Block:"minecraft:redstone_block",Time:1,Passengers:[{id:"minecraft:falling_block",Block:"minecraft:activator_rail",Time:1,Passengers:['
	unformatted_command = command
	first_element = True

	if include_commandblockoutput_command:
		command_part = '{id:"minecraft:commandblock_minecart",Command:"gamerule commandBlockOutput false"}'
		command += '\n\t' + command_part
		unformatted_command += command_part
		first_element = False

	if include_logadmincommands_command:
		if not first_element:
			command += ','
			unformatted_command += ','
		first_element = False
		command_part = '{id:"minecraft:commandblock_minecart",Command:"gamerule logAdminCommands false"}'
		command += '\n\t' + command_part
		unformatted_command += command_part

	if add_initialization_commands:
		file = mcplatform.askOpenFile('Select the text file containing the initialization commands...', False, ['txt'])
		if file is not None:
			input = open(file)
			if input is not None:
				for line in input.read().splitlines():
					if not first_element:
						command += ','
						unformatted_command += ','
					first_element = False
					command_part = '{id:"minecraft:commandblock_minecart",Command:"' + escape_string(line) + '"}'
					command += '\n\t' + command_part
					unformatted_command += command_part
				input.close()

	if include_blocks:
		if include_air:
			air_blocks = []
			for x in xrange(box.minx, box.maxx):
				air_blocks.append([])
				for y in xrange(box.miny, box.maxy):
					air_blocks[x - box.minx].append([])
					for z in xrange(box.minz, box.maxz):
						air_blocks[x - box.minx][y - box.miny].append(True)
			for cuboid in subdivide_in_cuboids(air_blocks, 32768, False, True, False):
				if not first_element:
					command += ','
					unformatted_command += ','
				first_element = False
				if volume(cuboid[0][0], cuboid[0][1], cuboid[0][2], cuboid[1][0], cuboid[1][1], cuboid[1][2]) == 1:
					command_part = '{id:"minecraft:commandblock_minecart",Command:"setblock ~' + str(cuboid[0][0] + box.minx - execution_center[0]) + ' ~' + str(cuboid[0][1] + box.miny - execution_center[1]) + ' ~' + str(cuboid[0][2] + box.minz - execution_center[2]) + ' minecraft:air'
				else:
					command_part = '{id:"minecraft:commandblock_minecart",Command:"fill ~' + str(cuboid[0][0] + box.minx - execution_center[0]) + ' ~' + str(cuboid[0][1] + box.miny - execution_center[1]) + ' ~' + str(cuboid[0][2] + box.minz - execution_center[2]) + ' ~' + str(cuboid[1][0] + box.minx - execution_center[0]) + ' ~' + str(cuboid[1][1] + box.miny - execution_center[1]) + ' ~' + str(cuboid[1][2] + box.minz - execution_center[2]) + ' minecraft:air'
				if include_null_block_data:
					command_part += ' 0'
				command_part += '"}'
				command += '\n\t' + command_part
				unformatted_command += command_part

		blocks = []
		for x in xrange(box.minx, box.maxx):
			blocks.append([])
			for y in xrange(box.miny, box.maxy):
				blocks[x - box.minx].append([])
				for z in xrange(box.minz, box.maxz):
					blocks[x - box.minx][y - box.miny].append((level.blockAt(x, y, z), level.blockDataAt(x, y, z), level.tileEntityAt(x, y, z)))
		enqueued = []
		for x in xrange(0, len(blocks)):
			for y in xrange(0, len(blocks[x])):
				for z in xrange(0, len(blocks[x][y])):
					block = blocks[x][y][z]
					if block[0] >= 1:
						for cuboid in subdivide_in_cuboids(blocks, 32768, False, block, (-1, 0, None)):
							if volume(cuboid[0][0], cuboid[0][1], cuboid[0][2], cuboid[1][0], cuboid[1][1], cuboid[1][2]) == 1:
								command_part = '{id:"minecraft:commandblock_minecart",Command:"setblock ~' + str(cuboid[0][0] + box.minx - execution_center[0]) + ' ~' + str(cuboid[0][1] + box.miny - execution_center[1]) + ' ~' + str(cuboid[0][2] + box.minz - execution_center[2]) + ' ' + materials.block_map[block[0]]
							else:
								command_part = '{id:"minecraft:commandblock_minecart",Command:"fill ~' + str(cuboid[0][0] + box.minx - execution_center[0]) + ' ~' + str(cuboid[0][1] + box.miny - execution_center[1]) + ' ~' + str(cuboid[0][2] + box.minz - execution_center[2]) + ' ~' + str(cuboid[1][0] + box.minx - execution_center[0]) + ' ~' + str(cuboid[1][1] + box.miny - execution_center[1]) + ' ~' + str(cuboid[1][2] + box.minz - execution_center[2]) + ' ' + materials.block_map[block[0]]
							if include_null_block_data or block[1] != 0 or (block[1] == 0 and block[2] is not None):
								command_part += ' ' + str(block[1])
							if block[2] is not None:
								command_part += ' replace ' + escape_string(nbt_to_string(block[2], nbt_tags_to_ignore))
							command_part += '"}'
							if block[0] not in blocks_to_enqueue:
								if not first_element:
									command += ','
									unformatted_command += ','
								first_element = False
								command += '\n\t' + command_part
								unformatted_command += command_part
							else:
								enqueued.append(command_part)
		for enqueued_command in enqueued:
			if not first_element:
				command += ','
				unformatted_command += ','
			first_element = False
			command += '\n\t' + enqueued_command
			unformatted_command += enqueued_command

	if include_entities:
		for (chunk, slices, point) in level.getChunkSlices(box):
			for entity in chunk.Entities:
				entity_x = entity['Pos'][0].value
				entity_y = entity['Pos'][1].value
				entity_z = entity['Pos'][2].value
				if (entity_x, entity_y, entity_z) in box:
					if not first_element:
						command += ','
						unformatted_command += ','
					first_element = False
					command_part = '{id:"minecraft:commandblock_minecart",Command:"summon ' + str(entity['id'].value) + ' ~' + str((Decimal(entity_x - execution_center[0]) - Decimal('0.5')).normalize()) + ' ~' + str((Decimal(entity_y - execution_center[1]) - Decimal('0.0625')).normalize()) + ' ~' + str((Decimal(entity_z - execution_center[2]) - Decimal('0.5')).normalize()) + ' ' + escape_string(nbt_to_string(entity, nbt_tags_to_ignore)) + '"}'
					command += '\n\t' + command_part
					unformatted_command += command_part

	if generate_surrounding_box:
		if volume(box.minx - 1, box.miny - 1, box.minz - 1, box.maxx, box.maxy, box.maxz) <= 32768:
			if not first_element:
				command += ','
				unformatted_command += ','
			first_element = False
			command_part = '{id:"minecraft:commandblock_minecart",Command:"fill ~' + str(box.minx - 1 - execution_center[0]) + ' ~' + str(box.miny - 1 - execution_center[1]) + ' ~' + str(box.minz - 1 - execution_center[2]) + ' ~' + str(box.maxx - execution_center[0]) + ' ~' + str(box.maxy - execution_center[1]) + ' ~' + str(box.maxz - execution_center[2]) + ' ' + escape_string(box_wall_material_block) + ' ' + str(box_wall_material_data) + ' outline"}'
			command += '\n\t' + command_part
			unformatted_command += command_part
		else:
			wall_blocks = []
			for x in xrange(0, box.maxx - box.minx + 2):
				wall_blocks.append([])
				for y in xrange(0, box.maxy - box.miny):
					wall_blocks[x].append([])
					for z in xrange(0, box.maxz - box.minz + 2):
						if x == 0 or x == box.maxx - box.minx + 1 or z == 0 or z == box.maxz - box.minz + 1:
							wall_blocks[x][y].append(True)
						else:
							wall_blocks[x][y].append(False)
			for cuboid in subdivide_in_cuboids(wall_blocks, 32768, False, True, False):
				if not first_element:
					command += ','
					unformatted_command += ','
				first_element = False
				command_part = '{id:"minecraft:commandblock_minecart",Command:"fill ~' + str(cuboid[0][0] - 1 + box.minx - execution_center[0]) + ' ~' + str(cuboid[0][1] + box.miny - execution_center[1]) + ' ~' + str(cuboid[0][2] - 1 + box.minz - execution_center[2]) + ' ~' + str(cuboid[1][0] - 1 + box.minx - execution_center[0]) + ' ~' + str(cuboid[1][1] + box.miny - execution_center[1]) + ' ~' + str(cuboid[1][2] - 1 + box.minz - execution_center[2]) + ' ' + escape_string(box_wall_material_block)
				if include_null_block_data or box_wall_material_data != 0:
					command_part += ' ' + str(box_wall_material_data)
				command_part += '"}'
				command += '\n\t' + command_part
				unformatted_command += command_part

		if add_box_signs:
			file = mcplatform.askOpenFile('Select the text file containing the signs to put on front of the box...', False, ['txt'])
			if file is not None:
				input = open(file)
				if input is not None:
					signs = OrderedDict()
					signs_line = 0
					coordinate = (0, 0)
					for line in input.read().splitlines():
						if signs_line == 0:
							if line != '':
								coordinates = re.split(r'\s*,\s*', line.strip())
								coordinate = (int(coordinates[0]), int(coordinates[1]))
								signs[coordinate] = []
								signs_line += 1
						else:
							signs[coordinate].append(line)
							signs_line += 1
						if signs_line == 9:
							signs_line = 0

					for coordinate, sign in signs.items():
						if relative_position == 'North':
							world_coordinate = (box.minx - 1 + coordinate[0] - execution_center[0], box.miny - 1 + coordinate[1] - execution_center[1], box.maxz + 1 - execution_center[2])
							sign_data = 3
						elif relative_position == 'East':
							world_coordinate = (box.minx - 2 - execution_center[0], box.miny - 1 + coordinate[1] - execution_center[1], box.minz - 1 + coordinate[0] - execution_center[2])
							sign_data = 4
						elif relative_position == 'South':
							world_coordinate = (box.maxx - coordinate[0] - execution_center[0], box.miny - 1 + coordinate[1] - execution_center[1], box.minz - 2 - execution_center[2])
							sign_data = 2
						else:
							world_coordinate = (box.maxx + 1 - execution_center[0], box.miny - 1 + coordinate[1] - execution_center[1], box.maxz - coordinate[0] - execution_center[2])
							sign_data = 5

						if not first_element:
							command += ','
							unformatted_command += ','
						first_element = False
						command_part = '{id:"minecraft:commandblock_minecart",Command:"setblock ~' + str(world_coordinate[0]) + ' ~' + str(world_coordinate[1]) + ' ~' + str(world_coordinate[2]) + ' minecraft:wall_sign ' + str(sign_data) + ' replace {'
						for i in xrange(0, min(4, len(sign))):
							sign_text = sign[i]
							sign_command = sign[i + 4] if len(sign) > i + 4 and len(sign[i + 4]) > 0 else ''
							if i > 0:
								command_part += ','
							command_part += 'Text' + str(i + 1) + r':\"'
							if sign_text.startswith('{'):
								if sign_command != '':
									command_part += escape_string(escape_string('{"text":"","extra":[' + sign_text + ']'))
								else:
									command_part += escape_string(escape_string(sign_text))
							elif sign_text.startswith('['):
								if sign_command != '':
									command_part += escape_string(escape_string('{"text":"","extra":' + sign_text))
								else:
									command_part += escape_string(escape_string(sign_text))
							elif sign_text.startswith('"'):
								if sign_command != '':
									command_part += escape_string(escape_string('{"text":' + sign_text))
								else:
									command_part += escape_string(escape_string(sign_text))
							else:
								if sign_command != '':
									command_part += escape_string(escape_string('{"text":"' + escape_string(sign_text) + '"'))
								else:
									command_part += escape_string(escape_string('"' + sign_text + '"'))
							if sign_command != '':
								command_part += escape_string(escape_string(',"clickEvent":{"action":"run_command","value":"' + escape_string(sign_command) + '"}}'))
							command_part += r'\"'
						command_part += '}"}'
						command += '\n\t' + command_part
						unformatted_command += command_part

		floor_ceiling_blocks = []
		for x in xrange(0, box.maxx - box.minx + 2):
			floor_ceiling_blocks.append([])
			floor_ceiling_blocks[x].append([])
			for z in xrange(0, box.maxz - box.minz + 2):
				floor_ceiling_blocks[x][0].append(True)
		for cuboid in subdivide_in_cuboids(floor_ceiling_blocks, 32768, False, True, False):
			if not first_element:
				command += ','
				unformatted_command += ','
			first_element = False
			command_part = '{id:"minecraft:commandblock_minecart",Command:"fill ~' + str(cuboid[0][0] - 1 + box.minx - execution_center[0]) + ' ~' + str(cuboid[0][1] - 1 + box.miny - execution_center[1]) + ' ~' + str(cuboid[0][2] - 1 + box.minz - execution_center[2]) + ' ~' + str(cuboid[1][0] - 1 + box.minx - execution_center[0]) + ' ~' + str(cuboid[1][1] - 1 + box.miny - execution_center[1]) + ' ~' + str(cuboid[1][2] - 1 + box.minz - execution_center[2]) + ' ' + escape_string(box_floor_material_block)
			if include_null_block_data or box_floor_material_data != 0:
				command_part += ' ' + str(box_floor_material_data)
			command_part += '"}'
			command += '\n\t' + command_part
			unformatted_command += command_part

			command_part = '{id:"minecraft:commandblock_minecart",Command:"fill ~' + str(cuboid[0][0] - 1 + box.minx - execution_center[0]) + ' ~' + str(cuboid[0][1] + box.maxy - execution_center[1]) + ' ~' + str(cuboid[0][2] - 1 + box.minz - execution_center[2]) + ' ~' + str(cuboid[1][0] - 1 + box.minx - execution_center[0]) + ' ~' + str(cuboid[1][1] + box.maxy - execution_center[1]) + ' ~' + str(cuboid[1][2] - 1 + box.minz - execution_center[2]) + ' ' + escape_string(box_ceiling_material_block)
			if include_null_block_data or box_ceiling_material_data != 0:
				command_part += ' ' + str(box_ceiling_material_data)
			command_part += '"}'
			command += ',\n\t' + command_part
			unformatted_command += ',' + command_part

	if add_finalization_commands:
		file = mcplatform.askOpenFile('Select the text file containing the finalization commands...', False, ['txt'])
		if file is not None:
			input = open(file)
			if input is not None:
				for line in input.read().splitlines():
					if not first_element:
						command += ','
						unformatted_command += ','
					first_element = False
					command_part = '{id:"minecraft:commandblock_minecart",Command:"' + escape_string(line) + '"}'
					command += '\n\t' + command_part
					unformatted_command += command_part
				input.close()

	if add_credits:
		if not first_element:
			command += ','
			unformatted_command += ','
		first_element = False
		command_part = '{id:"minecraft:commandblock_minecart",Command:"' + escape_string('tellraw @p {"color":"yellow","text":"Generated with Mamo\'s ","extra":[{"color":"blue","underlined":true,"text":"Structure spawner generator","clickEvent":{"action":"open_url","value":"https://github.com/xMamo/Structure-spawner-generator"},"hoverEvent":{"action":"show_text","value":"Click here if you want this filter too!"}},"."]}') + '"}'
		command += '\n\t' + command_part
		unformatted_command += command_part

	if not first_element:
		command += ','
		unformatted_command += ','
	command_part = r'{id:"minecraft:commandblock_minecart",Command:"setblock ~ ~1 ~ minecraft:command_block 0 replace {auto:1b,Command:\"fill ~ ~-3 ~ ~ ~ ~ minecraft:air'
	if include_null_block_data:
		command_part += ' 0'
	command_part += r'\"}"}'
	command += '\n\t' + command_part
	unformatted_command += command_part
	command_part = '{id:"minecraft:commandblock_minecart",Command:"kill @e[type=minecraft:commandblock_minecart,r=0]"}'
	command += ",\n\t" + command_part + '\n]}]}'
	unformatted_command += "," + command_part + ']}]}'

	if not ignore_maximum_command_block_command_length and len(unformatted_command) > 32500:
		editor.Notify('Unfortunately no command could be generated, as it would be longer than the Command Block command length limit of 32500 characters.')
		return

	command_output = None
	if save_command_to_file:
		output_file = mcplatform.askSaveFile(None, 'Select the text file to which you want to save the command...', 'command.txt', 'Text file (*.txt)\0*.txt\0\0', None)
		if output_file is not None:
			command_output = open(output_file, mode = 'w')

	if save_command_to_file and command_output is not None:
		command_output.write((command + '\n').encode('UTF-8'))
		command_output.flush()
		command_output.close()
	else:
		schematic = MCSchematic((1, 1, 1), None, None, level.materials)
		schematic.setBlockAt(0, 0, 0, 137)
		command_block = TAG_Compound()
		command_block['id'] = TAG_String('minecraft:command_block')
		command_block['x'] = TAG_Int(0)
		command_block['y'] = TAG_Int(0)
		command_block['z'] = TAG_Int(0)
		command_block['Command'] = TAG_String(unformatted_command)
		schematic.addTileEntity(command_block)
		editor.addCopiedSchematic(schematic)
Beispiel #11
0
def perform(level, box, options):
    char2Replace = options["Character to Replace"]
    chests = options["Chests"]
    disp = options["Dispensers"]
    drop = options["Droppers"]
    cmds = options["Command Blocks"]
    name = options["Operate on Names"]
    lore = options["Operate on Lore"]

    for (chunk, slices, point) in level.getChunkSlices(box):
        for t in chunk.TileEntities:
            x = t["x"].value
            y = t["y"].value
            z = t["z"].value

            if (x, y, z) in box:
                if t["id"].value == "Control" and cmds:
                    command = t["Command"].value
                    new = command.replace(char2Replace, formatChar)
                    t["Command"] = TAG_String(new)
                if t["id"].value == "Chest" and chests:
                    for itemStack in t["Items"]:
                        if "tag" in item:
                            if "display" in item["tag"]:
                                if "Name" in item["tag"]["display"] and name:
                                    itemName = item["tag"]["display"][
                                        "Name"].value
                                    newItemName = itemName.replace(
                                        char2Replace, formatChar)
                                    item["tag"]["display"][
                                        "Name"] = TAG_String(newItemName)
                                if "Lore" in item["tag"]["display"] and lore:
                                    loreLines = item["tag"]["display"]["Lore"]
                                    for line in loreLines:
                                        line.replace(char2Replace, formatChar)
                                    item["tag"]["display"]["Lore"] = TAG_List()
                                    for aLine in loreLines:
                                        item["tag"]["display"]["Lore"].append(
                                            aLine)
                if t["id"].value == "Trap" and disp:
                    for itemStack in t["Items"]:
                        if "tag" in item:
                            if "display" in item["tag"]:
                                if "Name" in item["tag"]["display"] and name:
                                    itemName = item["tag"]["display"][
                                        "Name"].value
                                    newItemName = itemName.replace(
                                        char2Replace, formatChar)
                                    item["tag"]["display"][
                                        "Name"] = TAG_String(newItemName)
                                if "Lore" in item["tag"]["display"] and lore:
                                    loreLines = item["tag"]["display"]["Lore"]
                                    for line in loreLines:
                                        line.replace(char2Replace, formatChar)
                                    item["tag"]["display"]["Lore"] = TAG_List()
                                    for aLine in loreLines:
                                        item["tag"]["display"]["Lore"].append(
                                            aLine)
                if t["id"].value == "Dropper" and drop:
                    for itemStack in t["Items"]:
                        if "tag" in item:
                            if "display" in item["tag"]:
                                if "Name" in item["tag"]["display"] and name:
                                    itemName = item["tag"]["display"][
                                        "Name"].value
                                    newItemName = itemName.replace(
                                        char2Replace, formatChar)
                                    item["tag"]["display"][
                                        "Name"] = TAG_String(newItemName)
                                if "Lore" in item["tag"]["display"] and lore:
                                    loreLines = item["tag"]["display"]["Lore"]
                                    for line in loreLines:
                                        line.replace(char2Replace, formatChar)
                                    item["tag"]["display"]["Lore"] = TAG_List()
                                    for aLine in loreLines:
                                        item["tag"]["display"]["Lore"].append(
                                            aLine)
        chunk.dirty = True