def createExplosionFromOptions(options): explosion = TAG_Compound() if options["Flicker"]: flickerVal = 1 else: flickerVal = 0 explosion["Flicker"] = TAG_Byte(flickerVal) if options["Trail"]: trailVal = 1 else: trailVal = 0 explosion["Trail"] = TAG_Byte(trailVal) typeVal = fireworkTypes[options["Type"]] explosion["Type"] = TAG_Byte(typeVal) colors = [] rang = range(1, 4) for i in rang: color = getColor(options, i) colors.append(color.rgb) explosion["Colors"] = TAG_Int_Array(colors) return explosion
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
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 perform(level, box, options): # go through all chunk slices which our box is in for (chunk, slices, point) in level.getChunkSlices(box): # go through all Tile Entities in a chunk (Chest is Tile Entity) for tileEntity in chunk.TileEntities: # the slices are not precisely cut for our box, so we need to check if tile entity is in our box x = tileEntity[ "x"].value # it's important not to forget '.value' because tileEntity["x"] refers to NBT tag y = tileEntity["y"].value z = tileEntity["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: # we're only looking for chests, so we need to check if this is a chest. # Tile Entity IDs can be found at minecraftwiki.net on page Chunk Format if tileEntity["id"].value == "Chest": # Now, we can do 3 things: add an item to the chest, edit the existing item, delete the existing item. # ---------------------------------------------------------------------------------------------------- # 1.) Add an item # To add an item to the chest, we need to have its TAG_Compound first. I'll create the item here: # ---------------------------------------------------------------------------------------------------- item = TAG_Compound() item["id"] = TAG_Short(1) # here comes the item ID item["Damage"] = TAG_Short(0) # here comes the damage/data item["Count"] = TAG_Byte(1) # count (usually 0 - 64) item["Slot"] = TAG_Byte( 0 ) # this is ugly, because you may replace an existing item, but we'll assume our chest is empty for now. # We need to make sure there's already a TAG_List called "Items" so we can append our item safely if not "Items" in tileEntity: tileEntity["Items"] = TAG_List() tileEntity["Items"].append(item) # ---------------------------------------------------------------------------------------------------- # 2.) Edit an item # To edit an item in chest, we need to find the target item first, so we need to look through all items in the chest and see if it's what we're looking for. # In this example, I'll look for Diamond Pick(id 278) and change them to diamond hoes(293) >:) # ---------------------------------------------------------------------------------------------------- if "Items" in tileEntity: for item in tileEntity["Items"]: if item["id"].value == 278: item["id"].value = 293 # ---------------------------------------------------------------------------------------------------- # 3.) Delete an item # As in the previous example, we need to find the item to be deleted at first and then delete it. # In this example, I'll delete all music discs from the chest. # ---------------------------------------------------------------------------------------------------- if "Items" in tileEntity: index = 0 for item in tileEntity["Items"]: if item["id"].value >= 2256 and item[ "id"].value <= 2267: del tileEntity["Items"][index] ++index # Cleanup: After you edit a chest, you need to tell MCEdit that you changed it. It's done by flagging the current chunk as "dirty". 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
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
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