From 679b9d203df99f2bc3daa587a8096d8c9e5e023c Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Fri, 13 Nov 2020 21:46:11 +0100 Subject: [PATCH] Add -w flag to butcher for water mobs beb784e0ffe1d8a8cf678912dbd6207e96afcfc8 Co-Authored-By: Lewis B <17665267+lewisjb@users.noreply.github.com> --- .../sk89q/worldedit/bukkit/BukkitEntityProperties.java | 6 ++++++ .../java/com/sk89q/worldedit/command/BrushCommands.java | 5 ++++- .../java/com/sk89q/worldedit/command/UtilityCommands.java | 5 ++++- .../com/sk89q/worldedit/command/util/CreatureButcher.java | 8 +++++++- .../sk89q/worldedit/entity/metadata/EntityProperties.java | 7 +++++++ .../sk89q/worldedit/fabric/FabricEntityProperties.java | 6 ++++++ .../com/sk89q/worldedit/forge/ForgeEntityProperties.java | 6 ++++++ .../sk89q/worldedit/sponge/SpongeEntityProperties.java | 5 +++++ 8 files changed, 45 insertions(+), 3 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityProperties.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityProperties.java index f0ae173bb..08d2a2f84 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityProperties.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityProperties.java @@ -40,6 +40,7 @@ import org.bukkit.entity.Projectile; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Tameable; import org.bukkit.entity.Villager; +import org.bukkit.entity.WaterMob; import org.bukkit.entity.minecart.ExplosiveMinecart; import static com.google.common.base.Preconditions.checkNotNull; @@ -147,4 +148,9 @@ class BukkitEntityProperties implements EntityProperties { public boolean isPasteable() { return !(entity instanceof Player || entity instanceof ComplexEntityPart); } + + @Override + public boolean isWaterCreature() { + return entity instanceof WaterMob; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 20a85deed..916a93ae5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -1003,7 +1003,9 @@ public class BrushCommands { @Switch(name = 'f', desc = "Also kill all friendly mobs (Applies the flags `-abgnpt`)") boolean killFriendly, @Switch(name = 'r', desc = "Also destroy armor stands") - boolean killArmorStands, InjectedValueAccess context) throws WorldEditException { + boolean killArmorStands, + @Switch(name = 'w', desc = "Also kill water mobs") + boolean killWater, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); CreatureButcher flags = new CreatureButcher(player); @@ -1015,6 +1017,7 @@ public class BrushCommands { flags.or(CreatureButcher.Flags.AMBIENT, killAmbient, "worldedit.butcher.ambient"); flags.or(CreatureButcher.Flags.TAGGED, killWithName, "worldedit.butcher.tagged"); flags.or(CreatureButcher.Flags.ARMOR_STAND, killArmorStands, "worldedit.butcher.armorstands"); + flags.or(CreatureButcher.Flags.WATER, killWater, "worldedit.butcher.water"); set(context, new ButcherBrush(flags)).setSize(radius); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 17daf0287..47acd5d54 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -569,7 +569,9 @@ public class UtilityCommands { @Switch(name = 'f', desc = "Also kill all friendly mobs (Applies the flags `-abgnpt`)") boolean killFriendly, @Switch(name = 'r', desc = "Also destroy armor stands") - boolean killArmorStands) throws WorldEditException { + boolean killArmorStands, + @Switch(name = 'w', desc = "Also kill water mobs") + boolean killWater) throws WorldEditException { LocalConfiguration config = we.getConfiguration(); if (radius == null) { @@ -595,6 +597,7 @@ public class UtilityCommands { flags.or(CreatureButcher.Flags.AMBIENT, killAmbient, "worldedit.butcher.ambient"); flags.or(CreatureButcher.Flags.TAGGED, killWithName, "worldedit.butcher.tagged"); flags.or(CreatureButcher.Flags.ARMOR_STAND, killArmorStands, "worldedit.butcher.armorstands"); + flags.or(CreatureButcher.Flags.WATER, killWater, "worldedit.butcher.water"); int killed = killMatchingEntities(radius, actor, flags::createFunction); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java index 9524f99f8..d19ad7087 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java @@ -36,8 +36,9 @@ public class CreatureButcher { public static final int GOLEMS = 1 << 3; public static final int AMBIENT = 1 << 4; public static final int TAGGED = 1 << 5; - public static final int FRIENDLY = PETS | NPCS | ANIMALS | GOLEMS | AMBIENT | TAGGED; public static final int ARMOR_STAND = 1 << 6; + public static final int WATER = 1 << 7; + public static final int FRIENDLY = PETS | NPCS | ANIMALS | GOLEMS | AMBIENT | TAGGED | WATER; private Flags() { } @@ -73,6 +74,7 @@ public class CreatureButcher { boolean killAmbient = (flags & Flags.AMBIENT) != 0; boolean killTagged = (flags & Flags.TAGGED) != 0; boolean killArmorStands = (flags & Flags.ARMOR_STAND) != 0; + boolean killWaterCreatures = (flags & Flags.WATER) != 0; EntityProperties type = entity.getFacet(EntityProperties.class); @@ -116,6 +118,10 @@ public class CreatureButcher { return false; } + if (!killWaterCreatures && type.isWaterCreature()) { + return false; + } + entity.remove(); return true; }; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityProperties.java b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityProperties.java index 8f987d6d6..eae08e3fa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityProperties.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityProperties.java @@ -161,4 +161,11 @@ public interface EntityProperties { * @return true if pasteable */ boolean isPasteable(); + + /** + * Test whether the entity is a water creature. + * + * @return true if water creature + */ + boolean isWaterCreature(); } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricEntityProperties.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricEntityProperties.java index 2be4ebd02..32a76023d 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricEntityProperties.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricEntityProperties.java @@ -35,6 +35,7 @@ import net.minecraft.entity.decoration.ItemFrameEntity; import net.minecraft.entity.decoration.painting.PaintingEntity; import net.minecraft.entity.mob.AmbientEntity; import net.minecraft.entity.mob.MobEntity; +import net.minecraft.entity.mob.WaterCreatureEntity; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.passive.TameableEntity; import net.minecraft.entity.passive.GolemEntity; @@ -148,4 +149,9 @@ public class FabricEntityProperties implements EntityProperties { public boolean isPasteable() { return !(entity instanceof ServerPlayerEntity || entity instanceof EnderDragonEntity); } + + @Override + public boolean isWaterCreature() { + return entity instanceof WaterCreatureEntity; + } } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityProperties.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityProperties.java index fa994dcb9..08a982dbd 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityProperties.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityProperties.java @@ -41,6 +41,7 @@ import net.minecraft.entity.item.minecart.AbstractMinecartEntity; import net.minecraft.entity.passive.AmbientEntity; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.passive.TameableEntity; +import net.minecraft.entity.passive.WaterMobEntity; import net.minecraft.entity.passive.GolemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; @@ -148,4 +149,9 @@ public class ForgeEntityProperties implements EntityProperties { public boolean isPasteable() { return !(entity instanceof ServerPlayerEntity || entity instanceof EnderDragonPartEntity); } + + @Override + public boolean isWaterCreature() { + return entity instanceof WaterMobEntity; + } } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntityProperties.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntityProperties.java index c1fcb0f55..18766d98e 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntityProperties.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntityProperties.java @@ -149,4 +149,9 @@ public class SpongeEntityProperties implements EntityProperties { public boolean isPasteable() { return !(entity instanceof Player || entity instanceof ComplexLivingPart); } + + @Override + public boolean isWaterCreature() { + return false; // TODO api8 + } }