From 284b67ef41dbc3e42cf5050fbb29990b12b69e89 Mon Sep 17 00:00:00 2001 From: Sunekaer - MAC Date: Mon, 15 Jan 2024 11:37:32 +0100 Subject: [PATCH] fix other commands --- .../sunekaer/toolkit/commands/TKCommand.java | 2 +- .../commands/inventory/CopyCommand.java | 3 ++- .../toolkit/commands/items/SlayerCommand.java | 2 +- .../level/BlockDistributionCommand.java | 3 ++- .../toolkit/commands/level/ClearCommand.java | 8 ++++--- .../commands/level/KillEntitiesCommand.java | 23 +++++++++---------- .../player/TeleportDimensionSpawnCommand.java | 2 +- forge/src/main/resources/META-INF/mods.toml | 2 +- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/common/src/main/java/com/sunekaer/toolkit/commands/TKCommand.java b/common/src/main/java/com/sunekaer/toolkit/commands/TKCommand.java index f2b0f9b..bdd0eec 100644 --- a/common/src/main/java/com/sunekaer/toolkit/commands/TKCommand.java +++ b/common/src/main/java/com/sunekaer/toolkit/commands/TKCommand.java @@ -44,7 +44,7 @@ public static void register(CommandDispatcher dispatcher, Co .then(EnchantCommand.register(context)) .then(BlockDistributionCommand.register()) .then(ClearCommand.register()) - .then(KillEntitiesCommand.register()) + .then(KillEntitiesCommand.register(context)) .then(HealCommand.register()) .then(RepairItemCommand.register()) .then(NightVisionCommand.register()) diff --git a/common/src/main/java/com/sunekaer/toolkit/commands/inventory/CopyCommand.java b/common/src/main/java/com/sunekaer/toolkit/commands/inventory/CopyCommand.java index 3be46f6..5cf6e7f 100644 --- a/common/src/main/java/com/sunekaer/toolkit/commands/inventory/CopyCommand.java +++ b/common/src/main/java/com/sunekaer/toolkit/commands/inventory/CopyCommand.java @@ -13,6 +13,7 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; @@ -54,7 +55,7 @@ private static int copy(CommandContext context) throws Comma continue; } - String itemName = Objects.requireNonNull(Registry.ITEM.getKey(stack.getItem())).toString(); + String itemName = Objects.requireNonNull(BuiltInRegistries.ITEM.getKey(stack.getItem())).toString(); String withNBT = ""; CompoundTag nbt = stack.save(new CompoundTag()); diff --git a/common/src/main/java/com/sunekaer/toolkit/commands/items/SlayerCommand.java b/common/src/main/java/com/sunekaer/toolkit/commands/items/SlayerCommand.java index f797496..fa1969d 100644 --- a/common/src/main/java/com/sunekaer/toolkit/commands/items/SlayerCommand.java +++ b/common/src/main/java/com/sunekaer/toolkit/commands/items/SlayerCommand.java @@ -43,7 +43,7 @@ private static int giveItem(ServerPlayer player) { ItemEntity drop = player.drop(itemstack.copy(), false); if (drop != null) { drop.setNoPickUpDelay(); - drop.setOwner(player.getUUID()); + drop.setTarget(player.getUUID()); } } diff --git a/common/src/main/java/com/sunekaer/toolkit/commands/level/BlockDistributionCommand.java b/common/src/main/java/com/sunekaer/toolkit/commands/level/BlockDistributionCommand.java index e5ee0d0..3f12a44 100644 --- a/common/src/main/java/com/sunekaer/toolkit/commands/level/BlockDistributionCommand.java +++ b/common/src/main/java/com/sunekaer/toolkit/commands/level/BlockDistributionCommand.java @@ -11,6 +11,7 @@ import net.minecraft.commands.Commands; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.Style; @@ -58,7 +59,7 @@ private static int getOreDist(CommandSourceStack source, Player player, int size } if (state.is(ToolkitPlatform.getOresTag())) { - ResourceLocation key = Registry.BLOCK.getKey(state.getBlock()); + ResourceLocation key = BuiltInRegistries.BLOCK.getKey(state.getBlock()); blockOccurrences.add(key.toString()); } } diff --git a/common/src/main/java/com/sunekaer/toolkit/commands/level/ClearCommand.java b/common/src/main/java/com/sunekaer/toolkit/commands/level/ClearCommand.java index 85512b5..277bda2 100644 --- a/common/src/main/java/com/sunekaer/toolkit/commands/level/ClearCommand.java +++ b/common/src/main/java/com/sunekaer/toolkit/commands/level/ClearCommand.java @@ -12,6 +12,8 @@ import net.minecraft.commands.SharedSuggestionProvider; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; @@ -54,9 +56,9 @@ private static int remove(CommandSourceStack source, int size, String filter) th var removalCheck = RemovalPredicate.getFromName(filter).orElse(RemovalPredicate.JUST_ORES); Predicate customCheck = null; if (filter.startsWith("#")) { - customCheck = state -> state.is(TagKey.create(Registry.BLOCK_REGISTRY, new ResourceLocation(filter.replace("#", "")))); + customCheck = state -> state.is(TagKey.create(Registries.BLOCK, new ResourceLocation(filter.replace("#", "")))); } else if(filter.contains(":")) { - customCheck = state -> Registry.BLOCK.getKey(state.getBlock()).toString().equalsIgnoreCase(filter); + customCheck = state -> BuiltInRegistries.BLOCK.getKey(state.getBlock()).toString().equalsIgnoreCase(filter); } ServerLevel level = source.getLevel(); @@ -134,7 +136,7 @@ private static void removeChunk(ServerLevel level, ChunkPos chunkPos, Predicate< private enum RemovalPredicate { JUST_ORES(state -> state.is(ToolkitPlatform.getOresTag())), - ORES_AND_MODDED(state -> state.is(ToolkitPlatform.getOresTag()) && Registry.BLOCK.getKey(state.getBlock()).getNamespace().equals("minecraft")); + ORES_AND_MODDED(state -> state.is(ToolkitPlatform.getOresTag()) && BuiltInRegistries.BLOCK.getKey(state.getBlock()).getNamespace().equals("minecraft")); public static final List VALUES = Arrays.asList(values()); public static final String[] NAMES = VALUES.stream().map(e -> e.toString().toLowerCase()).toArray(String[]::new); diff --git a/common/src/main/java/com/sunekaer/toolkit/commands/level/KillEntitiesCommand.java b/common/src/main/java/com/sunekaer/toolkit/commands/level/KillEntitiesCommand.java index 4e240f0..bd2dee1 100644 --- a/common/src/main/java/com/sunekaer/toolkit/commands/level/KillEntitiesCommand.java +++ b/common/src/main/java/com/sunekaer/toolkit/commands/level/KillEntitiesCommand.java @@ -4,14 +4,15 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.serialization.Codec; +import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; -import net.minecraft.commands.arguments.EntitySummonArgument; +import net.minecraft.commands.arguments.ResourceArgument; import net.minecraft.commands.arguments.StringRepresentableArgument; import net.minecraft.commands.synchronization.SuggestionProviders; -import net.minecraft.core.Registry; +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.server.level.ServerLevel; import net.minecraft.util.StringRepresentable; import net.minecraft.world.entity.Entity; @@ -66,26 +67,24 @@ public static KillType getKillType(CommandContext source, St } } - public static ArgumentBuilder register() { + public static ArgumentBuilder register(CommandBuildContext arg) { return Commands.literal("kill") .requires(cs -> cs.hasPermission(2)) .then(Commands.argument("type", KillTypeArgument.killType()) .executes(context -> kill(KillTypeArgument.getKillType(context, "type"), context.getSource()))) - .then(Commands.literal("by").then(Commands.argument("entity", EntitySummonArgument.id()).suggests(SuggestionProviders.SUMMONABLE_ENTITIES).executes(context -> killByEntity(context, EntitySummonArgument.getSummonableEntity(context, "entity"))))); + .then(Commands.literal("by").then( + Commands.argument("entity", ResourceArgument.resource(arg, Registries.ENTITY_TYPE)).suggests(SuggestionProviders.SUMMONABLE_ENTITIES).executes(context -> killByEntity(context, ResourceArgument.getSummonableEntityType(context, "entity"))))); } - private static int killByEntity(CommandContext context, ResourceLocation entityId) throws CommandSyntaxException { + private static int killByEntity(CommandContext context, Holder.Reference> reference) throws CommandSyntaxException { CommandSourceStack source = context.getSource(); var level = source.getLevel(); - EntityType entityType = Registry.ENTITY_TYPE.get(entityId); - if (entityType == null) { - return -1; - } + EntityType entityType = reference.value(); - source.sendSuccess(Component.translatable("commands.toolkit.kill.start", entityId), true); + source.sendSuccess(Component.translatable("commands.toolkit.kill.start", entityType), true); var entitiesKilled = yeetEntities((player, entity) -> entity.getType().equals(entityType), level, source.getPlayerOrException()); - yeetedEntitiesMessage(source, entitiesKilled, entityId.toString()); + yeetedEntitiesMessage(source, entitiesKilled, entityType.toShortString()); return 0; } diff --git a/common/src/main/java/com/sunekaer/toolkit/commands/player/TeleportDimensionSpawnCommand.java b/common/src/main/java/com/sunekaer/toolkit/commands/player/TeleportDimensionSpawnCommand.java index f442671..ffc0d09 100644 --- a/common/src/main/java/com/sunekaer/toolkit/commands/player/TeleportDimensionSpawnCommand.java +++ b/common/src/main/java/com/sunekaer/toolkit/commands/player/TeleportDimensionSpawnCommand.java @@ -38,7 +38,7 @@ private static int teleport(CommandSourceStack source, MinecraftServer server, C for (Entity entity : entities) { BlockPos pos = entity.blockPosition(); if (!level.getWorldBorder().isWithinBounds(pos)) { - pos = level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, new BlockPos(level.getWorldBorder().getCenterX(), 0.0, level.getWorldBorder().getCenterZ())); + pos = level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, new BlockPos((int) level.getWorldBorder().getCenterX(), 0, (int) level.getWorldBorder().getCenterZ())); } int playerXp = 0; diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 52b5d19..85d2812 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -21,7 +21,7 @@ side = "BOTH" [[dependencies.toolkit]] modId = "minecraft" mandatory = true -versionRange = "[1.19.5,)" +versionRange = "[1.19.4,)" ordering = "NONE" side = "BOTH"