Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.Codec;
import com.sunekaer.toolkit.Toolkit;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
Expand All @@ -13,6 +14,8 @@
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.entity.Entity;
Expand All @@ -30,6 +33,10 @@
import java.util.function.BiPredicate;

public class KillEntitiesCommand {
public static final TagKey<EntityType<?>> KILL_PROTECTED = TagKey.create(
Registries.ENTITY_TYPE,
ResourceLocation.fromNamespaceAndPath(Toolkit.MOD_ID, "kill_protected"));

enum KillType implements StringRepresentable {
all((p, entity) -> !(entity instanceof AbstractMinecart) && !entity.getUUID().equals(p.getUUID())),
animals((p, entity) -> entity instanceof Animal),
Expand Down Expand Up @@ -83,7 +90,7 @@ private static int killByEntity(CommandContext<CommandSourceStack> context, Hold
EntityType<?> entityType = reference.value();

source.sendSuccess(() -> Component.translatable("commands.toolkit.kill.start", entityType), true);
var entitiesKilled = yeetEntities((player, entity) -> entity.getType().equals(entityType), level, source.getPlayerOrException());
var entitiesKilled = yeetEntities((player, entity) -> entity.getType().equals(entityType), level, source.getPlayerOrException(), false);
yeetedEntitiesMessage(source, entitiesKilled, entityType.toShortString());

return 0;
Expand All @@ -102,7 +109,7 @@ private static int kill(KillType type, CommandSourceStack source) throws Command
entitiesKilled++;
}
} else {
entitiesKilled += yeetEntities(type.checker, level, source.getPlayerOrException());
entitiesKilled += yeetEntities(type.checker, level, source.getPlayerOrException(), true);
}

yeetedEntitiesMessage(source, entitiesKilled, typeName);
Expand All @@ -118,7 +125,7 @@ private static void yeetedEntitiesMessage(CommandSourceStack source, int yeetedA
}
}

private static int yeetEntities(BiPredicate<Player, Entity> tester, ServerLevel level, Player player) {
private static int yeetEntities(BiPredicate<Player, Entity> tester, ServerLevel level, Player player, boolean respectProtection) {
int entitiesKilled = 0;
Iterable<Entity> entities = level.getAllEntities();

Expand All @@ -131,6 +138,10 @@ private static int yeetEntities(BiPredicate<Player, Entity> tester, ServerLevel
continue;
}

if (respectProtection && entity.getType().is(KILL_PROTECTED)) {
continue;
}

if (tester.test(player, entity)) {
entity.remove(Entity.RemovalReason.KILLED);
entitiesKilled ++;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
{ "id": "aeronautics:propeller_bearing_contraption", "required": false }
]
}
3 changes: 3 additions & 0 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ architectury {
}

repositories {
maven {
url "https://maven.neoforged.net/releases"
}
maven {
url "https://maven.saps.dev/mirror"
}
Expand Down