Skip to content

Commit

Permalink
fix other commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunekaer committed Jan 15, 2024
1 parent 64c8152 commit 284b67e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void register(CommandDispatcher<CommandSourceStack> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,7 +55,7 @@ private static int copy(CommandContext<CommandSourceStack> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<BlockState> 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();
Expand Down Expand Up @@ -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<RemovalPredicate> VALUES = Arrays.asList(values());
public static final String[] NAMES = VALUES.stream().map(e -> e.toString().toLowerCase()).toArray(String[]::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,26 +67,24 @@ public static KillType getKillType(CommandContext<CommandSourceStack> source, St
}
}

public static ArgumentBuilder<CommandSourceStack, ?> register() {
public static ArgumentBuilder<CommandSourceStack, ?> 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<CommandSourceStack> context, ResourceLocation entityId) throws CommandSyntaxException {
private static int killByEntity(CommandContext<CommandSourceStack> context, Holder.Reference<EntityType<?>> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ side = "BOTH"
[[dependencies.toolkit]]
modId = "minecraft"
mandatory = true
versionRange = "[1.19.5,)"
versionRange = "[1.19.4,)"
ordering = "NONE"
side = "BOTH"

Expand Down

0 comments on commit 284b67e

Please sign in to comment.