Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # You may modify and distribute this filter however you wish,
- # but please give credit to WolfieMario.
- # Credits to Ceandros for the idea of an option to remove unselectable entities.
- import random
- # Implementing this since I was disappointed I couldn't chain appends on lists.
- def appendAndReturn(seq, elem):
- seq.append(elem)
- return seq
- # See appendAndReturn. Also, is there any better a place for me to declare these methods?
- # I'd like to put it at the bottom, but then it can't be called up here.
- # This is because they are called outside of methods.
- def extendAndReturn(seq1, seq2):
- seq1.extend(seq2)
- return seq1
- # Define entity classes
- entityPassive = [
- "Bat", "Chicken", "Cow", "EntityHorse", "MushroomCow", "Ozelot", "Pig",
- "Sheep", "SnowMan", "Squid", "Villager", "VillagerGolem", "Wolf"]
- entityHostile = [
- "Blaze", "CaveSpider", "Creeper", "EnderDragon", "Enderman", "Ghast", "Giant", "LavaSlime", "PigZombie",
- "Silverfish", "Skeleton", "Slime", "Spider", "Witch", "WitherBoss", "Zombie"]
- entityLiving = extendAndReturn(list(entityPassive), entityHostile)
- entityLiving.sort()
- entityProjectile = [
- "Arrow", "Snowball", "Egg", "Fireball", "SmallFireball",
- "ThrownEnderpearl", "ThrownExpBottle", "ThrownPotion", "WitherSkull"]
- entityStationary = ["EnderCrystal", "ItemFrame", "Painting", "LeashKnot"]
- entityVehicle = ["Boat", "Minecart", "MinecartRideable", "MinecartChest", "MinecartFurnace", "MinecartTNT", "MinecartHopper", "MinecartSpawner"]
- entityOther = ["Item", "XPOrb", "PrimedTnt", "FallingSand", "EyeOfEnderSignal", "FireworksRocketEntity"]
- entityNonliving = list(entityProjectile)
- entityNonliving.extend(entityVehicle)
- entityNonliving.extend(entityOther)
- entityNonliving.extend(entityStationary)
- entityTameable = {"Wolf", "Ozelot", "EntityHorse"}
- groupBuilder = ["Painting", "ItemFrame"]
- # Dictionary used to determine which entity types are to be filtered
- entityTypes = {
- "-Ignore Option-": set(),
- "-All Living-": set(entityLiving),
- "-Passive-": set(entityPassive),
- "-Hostile-": set(entityHostile),
- "-Tamed-": entityTameable,
- "-Untamed Tameable-": entityTameable,
- "-Persistent-": set(entityLiving),
- "-Not Persistent-": set(entityLiving),
- "-All Nonliving-": set(entityNonliving),
- "-Projectiles-": set(entityProjectile),
- "-Vehicles-": set(entityVehicle),
- "-Stationary-": set(entityStationary),
- "Paintings and Item Frames": set(groupBuilder),
- "Paintings, Frames, Villagers": set(appendAndReturn(groupBuilder,"Villager")),
- "Paint's, Frames, Vill's, V'Golems": set(appendAndReturn(groupBuilder,"VillagerGolem")),
- "Villagers, VillagerGolems": set(groupBuilder[2:3]),
- "VillagerGolems, SnowMen": {"VillagerGolem", "SnowMan"},
- "Farm Animals": {"Chicken", "Cow", "EntityHorse", "MushroomCow", "Pig", "Sheep"},
- "Humanoids": {"SnowMan", "Villager", "VillagerGolem", "Enderman", "Giant", "PigZombie", "Skeleton", "Witch", "Zombie"}
- }
- # Simple separator of EN dashes (looks like a solid line)
- separator = u"\u2013" * 46
- displayName = "Delete Entities"
- inputs = (
- ("Entity deletion filter by WolfieMario\n", "label"),
- (separator, "label"),
- ("Entities to delete:", "label"),
- ("Entity Group", ("-Ignore Option-", "Paintings and Item Frames", "Paintings, Frames, Villagers", "Paint's, Frames, Vill's, V'Golems",
- "Villagers, VillagerGolems", "VillagerGolems, SnowMen", "Farm Animals", "Humanoids") ),
- ("Living Entity", tuple(extendAndReturn(["-Ignore Option-", "-All Living-", "-Passive-", "-Hostile-",
- "-Tamed-", "-Untamed Tameable-", "-Persistent-", "-Not Persistent-"], entityLiving)) ),
- ("Nonliving Entity", tuple(extendAndReturn(["-Ignore Option-", "-All Nonliving-", "-Projectiles-", "-Vehicles-", "-Stationary-"], entityNonliving)) ),
- (separator, "label"),
- ("Deletion Mode", ("Only selected entities", "Only entities outside selection", "Within selected X&Z, any Y value",
- "Within selected X&Z, below Y 0", "Within selected X&Z, above Y 255", "Selected X&Z, Y < 0 or Y > 255") ),
- ("Percentage to Delete", 100)
- )
- def perform(level, box, options):
- # Grab user options
- group = options["Entity Group"]
- living = options["Living Entity"]
- nonliving = options["Nonliving Entity"]
- # Build set of entity types to filter
- types = entityTypes[group]
- if living in entityTypes:
- types = types.union(entityTypes[living])
- else:
- types = types.union({living})
- if nonliving in entityTypes:
- types = types.union(entityTypes[nonliving])
- else:
- types = types.union({nonliving})
- typeTame = 1 if living == "-Tamed-" else 2 if living == "-Untamed Tameable-" else 0
- typePersist = 1 if living == "-Persistent-" else 2 if living == "-Not Persistent-" else 0
- deleteMode = options["Deletion Mode"]
- deleteOutside = deleteMode == "Only entities outside selection"
- if deleteMode == "Within selected X&Z, any Y value":
- yRangeFunc = lambda y: True
- elif deleteMode == "Within selected X&Z, below Y 0":
- yRangeFunc = lambda y: y < 0
- elif deleteMode == "Within selected X&Z, above Y 255":
- yRangeFunc = lambda y: y >= 255
- elif deleteMode == "Selected X&Z, Y < 0 or Y > 255":
- yRangeFunc = lambda y: y < 0 or y >= 255
- else:
- yRangeFunc = lambda y: y >= box.miny and y < box.maxy
- deletionChance = options["Percentage to Delete"]
- numDeleted = 0
- # Find entities to filter, and filter them
- if deleteOutside:
- chunksToSearch = level.getAllChunkSlices()
- else:
- chunksToSearch = level.getChunkSlices(box)
- for chunk, _, _ in chunksToSearch:
- entitiesToDelete = []
- for entity in chunk.Entities:
- eType = entity["id"].value
- # Check if this is an entity we will delete; it makes sense to bail out early!
- tameNonMatch = typeTame > 0 and ( ((eType == "Wolf" or eType == "Ozelot") and (typeTame == 1 if entity["Owner"].value == "" else typeTame == 2) ) or (eType == "EntityHorse" and (typeTame == 1 if entity["Tame"].value == 0 else typeTame == 2) ) )
- persistNonMatch = typePersist > 0 and (eType in entityLiving) and (typePersist == entity["PersistenceRequired"].value + 1)
- if (eType in types) and not tameNonMatch and not persistNonMatch:
- x = entity["Pos"][0].value
- y = entity["Pos"][1].value
- z = entity["Pos"][2].value
- # Check if this entity is within our target space
- if (yRangeFunc(y) and x >= box.minx and x < box.maxx and z >= box.minz and z < box.maxz) != deleteOutside:
- if deletionChance >= 100 or random.randint(0, 99) < deletionChance:
- entitiesToDelete.append(entity)
- for entity in entitiesToDelete:
- chunk.Entities.remove(entity)
- numDeleted += 1
- # If list isn't empty
- if entitiesToDelete:
- chunk.dirty = True
- print("%d entities have been deleted." % numDeleted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement