From 1ec873ff59076a6bc3d691c7ec75f528fa785aa6 Mon Sep 17 00:00:00 2001 From: WakelessSloth56 Date: Thu, 12 May 2022 08:14:53 +0800 Subject: [PATCH] feat(command): remove damage source arguments --- .../common/command/AHCommandArguments.java | 7 +- .../argument/DamageSourceArgument.java | 75 ------------------- .../argument/EntityDamageSourceArgument.java | 39 ---------- .../IndirectEntityDamageSourceArgument.java | 39 ---------- 4 files changed, 1 insertion(+), 159 deletions(-) delete mode 100644 src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/DamageSourceArgument.java delete mode 100644 src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/EntityDamageSourceArgument.java delete mode 100644 src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/IndirectEntityDamageSourceArgument.java diff --git a/src/main/java/org/auioc/mcmod/arnicalib/common/command/AHCommandArguments.java b/src/main/java/org/auioc/mcmod/arnicalib/common/command/AHCommandArguments.java index 1f0db669..26733b2f 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/common/command/AHCommandArguments.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/common/command/AHCommandArguments.java @@ -3,9 +3,6 @@ import com.mojang.brigadier.arguments.ArgumentType; import org.auioc.mcmod.arnicalib.ArnicaLib; import org.auioc.mcmod.arnicalib.common.command.argument.CreativeModeTabArgument; -import org.auioc.mcmod.arnicalib.common.command.argument.DamageSourceArgument; -import org.auioc.mcmod.arnicalib.common.command.argument.EntityDamageSourceArgument; -import org.auioc.mcmod.arnicalib.common.command.argument.IndirectEntityDamageSourceArgument; import net.minecraft.commands.synchronization.ArgumentSerializer; import net.minecraft.commands.synchronization.ArgumentTypes; import net.minecraft.commands.synchronization.EmptyArgumentSerializer; @@ -17,9 +14,7 @@ private static > void register(String id, Class cla } public static void init() { - register("damage_source", DamageSourceArgument.class, new EmptyArgumentSerializer<>(DamageSourceArgument::damageSource)); - register("entity_damage_source", EntityDamageSourceArgument.class, new EmptyArgumentSerializer<>(EntityDamageSourceArgument::damageSource)); - register("indirect_entity_damage_source", IndirectEntityDamageSourceArgument.class, new EmptyArgumentSerializer<>(IndirectEntityDamageSourceArgument::damageSource)); register("creative_mode_tab", CreativeModeTabArgument.class, new EmptyArgumentSerializer<>(CreativeModeTabArgument::creativeModeTab)); } + } diff --git a/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/DamageSourceArgument.java b/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/DamageSourceArgument.java deleted file mode 100644 index ad3297f4..00000000 --- a/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/DamageSourceArgument.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.auioc.mcmod.arnicalib.common.command.argument; - -import java.util.HashMap; -import java.util.concurrent.CompletableFuture; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import org.auioc.mcmod.arnicalib.ArnicaLib; -import org.auioc.mcmod.arnicalib.utils.game.TextUtils; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.world.damagesource.DamageSource; - -public class DamageSourceArgument implements ArgumentType { - private static HashMap MAP = new HashMap(); - - public static DamageSourceArgument damageSource() { - return new DamageSourceArgument(); - } - - public static DamageSource getDamageSource(CommandContext context, String argument) throws CommandSyntaxException { - return context.getArgument(argument, DamageSource.class); - } - - @Override - public DamageSource parse(StringReader reader) throws CommandSyntaxException { - String sourceName = reader.readString(); - - if (MAP.containsKey(sourceName)) { - return MAP.get(sourceName); - } - - throw (new SimpleCommandExceptionType( - TextUtils.I18nText(ArnicaLib.i18n("argument.damage_source.invalid"), sourceName) - )).create(); - } - - @Override - public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { - return SharedSuggestionProvider.suggest(MAP.keySet(), builder); - } - - static { - { - MAP.put("inFire", DamageSource.IN_FIRE); - MAP.put("lightningBolt", DamageSource.LIGHTNING_BOLT); - MAP.put("onFire", DamageSource.ON_FIRE); - MAP.put("lava", DamageSource.LAVA); - MAP.put("hotFloor", DamageSource.HOT_FLOOR); - MAP.put("inWall", DamageSource.IN_WALL); - MAP.put("cramming", DamageSource.CRAMMING); - MAP.put("drown", DamageSource.DROWN); - MAP.put("starve", DamageSource.STARVE); - MAP.put("cactus", DamageSource.CACTUS); - MAP.put("fall", DamageSource.FALL); - MAP.put("flyIntoWall", DamageSource.FLY_INTO_WALL); - MAP.put("outOfWorld", DamageSource.OUT_OF_WORLD); - MAP.put("generic", DamageSource.GENERIC); - MAP.put("magic", DamageSource.MAGIC); - MAP.put("wither", DamageSource.WITHER); - MAP.put("anvil", DamageSource.ANVIL); - MAP.put("fallingBlock", DamageSource.FALLING_BLOCK); - MAP.put("dragonBreath", DamageSource.DRAGON_BREATH); - MAP.put("dryout", DamageSource.DRY_OUT); - MAP.put("sweetBerryBush", DamageSource.SWEET_BERRY_BUSH); - MAP.put("freeze", DamageSource.FREEZE); - MAP.put("fallingStalactite", DamageSource.FALLING_STALACTITE); - MAP.put("stalagmite", DamageSource.STALAGMITE); - } - }; -} diff --git a/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/EntityDamageSourceArgument.java b/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/EntityDamageSourceArgument.java deleted file mode 100644 index 0a127197..00000000 --- a/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/EntityDamageSourceArgument.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.auioc.mcmod.arnicalib.common.command.argument; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.function.Function; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.world.damagesource.EntityDamageSource; -import net.minecraft.world.entity.Entity; - -public class EntityDamageSourceArgument implements ArgumentType> { - private static final List LIST = List.of("sting", "mob", "player", "thorns", "explosion.player", "explosion"); - - public static EntityDamageSourceArgument damageSource() { - return new EntityDamageSourceArgument(); - } - - @SuppressWarnings("unchecked") - public static Function getDamageSource(CommandContext context, String argument) throws CommandSyntaxException { - return context.getArgument(argument, Function.class); - } - - @Override - public Function parse(StringReader reader) throws CommandSyntaxException { - String sourceName = reader.readString(); - return (entity) -> new EntityDamageSource(sourceName, entity); - } - - @Override - public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { - return SharedSuggestionProvider.suggest(LIST, builder); - } -} diff --git a/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/IndirectEntityDamageSourceArgument.java b/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/IndirectEntityDamageSourceArgument.java deleted file mode 100644 index 4c52fa95..00000000 --- a/src/main/java/org/auioc/mcmod/arnicalib/common/command/argument/IndirectEntityDamageSourceArgument.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.auioc.mcmod.arnicalib.common.command.argument; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.function.BiFunction; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.world.damagesource.IndirectEntityDamageSource; -import net.minecraft.world.entity.Entity; - -public class IndirectEntityDamageSourceArgument implements ArgumentType> { - private static final List LIST = List.of("mob", "arrow", "trident", "fireworks", "fireworks", "onFire", "fireball", "witherSkull", "thrown", "indirectMagic"); - - public static IndirectEntityDamageSourceArgument damageSource() { - return new IndirectEntityDamageSourceArgument(); - } - - @SuppressWarnings("unchecked") - public static BiFunction getDamageSource(CommandContext context, String argument) throws CommandSyntaxException { - return context.getArgument(argument, BiFunction.class); - } - - @Override - public BiFunction parse(StringReader reader) throws CommandSyntaxException { - String sourceName = reader.readString(); - return (entity, owner) -> new IndirectEntityDamageSource(sourceName, entity, owner); - } - - @Override - public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { - return SharedSuggestionProvider.suggest(LIST, builder); - } -}