Skip to content

Commit

Permalink
Add reaction reload command and fix a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
hjake123 committed Oct 15, 2024
1 parent 78c8fc6 commit a21aeac
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Reaction(String alias, Power... powers){
}

public MutableComponent getName(){
return name;
return name.copy();
}

public Reaction setStimulus(Stimulus rxs){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class ReactionMan {
private static final ReactionMap REACTIONS = new ReactionMap();
public static ArrayList<Power> BASE_POWER_LIST = new ArrayList<>();
public static ReactionCriteriaBuilder CRITERIA_BUILDER = new ReactionCriteriaBuilder();
public static Map<String, MutableComponent> REACTION_NAME = new HashMap<>();

public ReactionMan(){
CRITERIA_BUILDER.add("curse_assimilation");
Expand Down Expand Up @@ -79,6 +78,13 @@ public List<Reaction> getReactions(){
return REACTIONS.values().stream().toList();
}

public List<String> getReactionAliases(){
if(!initialized){
constructReactions();
}
return REACTIONS.keySet().stream().toList();
}

public Reaction get(String alias){
if(!initialized){
constructReactions();
Expand Down
23 changes: 18 additions & 5 deletions src/main/java/com/hyperlynx/reactive/cmd/ReactiveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.RegisterCommandsEvent;

import java.util.List;
import java.util.stream.Collectors;

import static net.minecraft.commands.arguments.coordinates.BlockPosArgument.ERROR_NOT_LOADED;

@EventBusSubscriber(modid= ReactiveMod.MODID, bus=EventBusSubscriber.Bus.GAME)
Expand All @@ -45,8 +48,11 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
.then(Commands.literal("give_warp_bottle").then(Commands.argument("target", BlockPosArgument.blockPos())
.executes((context) -> giveWarpBottle(context.getSource(), context.getArgument("target", WorldCoordinates.class)))))

.then(Commands.literal("list_reactions")
.executes((context) -> listReactions(context.getSource())))
.then(Commands.literal("reaction")
.then(Commands.literal("list")
.executes((context) -> listReactions(context.getSource())))
.then(Commands.literal("reload")
.executes((context) -> reloadReactions())))

.then(Commands.literal("power")
.then(Commands.literal("add")
Expand All @@ -72,6 +78,11 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(command_builder);
}

private static int reloadReactions() {
ReactiveMod.REACTION_MAN.reset();
return 1;
}

private static int modifyPower(CommandSourceStack source, WorldCoordinates crucible_location, ResourceLocation power_location, Integer amount, boolean remove) throws CommandSyntaxException {
BlockPos pos = crucible_location.getBlockPos(source);
ServerLevel level = source.getLevel();
Expand Down Expand Up @@ -114,9 +125,11 @@ private static int listReactions(CommandSourceStack source) throws CommandSyntax
if(!source.isPlayer()){
throw ERROR_NO_PLAYER.create();
}
for(Reaction reaction : ReactiveMod.REACTION_MAN.getReactions()){
source.sendSuccess(() -> Component.literal(reaction.getAlias() + " : " + reaction.getName().getString()), true);
}
List<String> aliases = ReactiveMod.REACTION_MAN.getReactionAliases();
aliases.stream().sorted().forEach((alias) -> {
Reaction reaction = ReactiveMod.REACTION_MAN.get(alias);
source.sendSuccess(() -> Component.literal(alias + " : " + reaction.getName().getString()), true);
});
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/reactive/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
"reaction.reactive.size_shrink_effect": "Reduction",
"reaction.reactive.size_revert_effect": "Reduction Reversal",
"reaction.reactive.size_revert_effect_2": "Enlargement Reversal",
"reaction.reactive.slowfall": "Slow Falling",
"reaction.reactive.slowfall_effect": "Slow Falling",
"reaction.reactive.smoke_annihilation": "Noxious Fumes",
"reaction.reactive.soul_to_warp": "Soul to Warp Corruption",
"reaction.reactive.verdant_consume": "Verdant-Vital Reaction",
Expand Down

0 comments on commit a21aeac

Please sign in to comment.