Skip to content

Commit

Permalink
Upgrade XP/Points command, Dhi better be happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeryn99 committed Dec 17, 2023
1 parent cfba0ad commit ec9d508
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import whocraft.tardis_refined.TardisRefined;
import whocraft.tardis_refined.command.sub.export.ExportDesktopCommand;
import whocraft.tardis_refined.command.sub.InteriorCommand;
import whocraft.tardis_refined.command.sub.LevelCommand;
import whocraft.tardis_refined.command.sub.export.ExportDesktopCommand;
import whocraft.tardis_refined.common.util.Platform;

public class TardisRefinedCommand {
Expand All @@ -14,9 +15,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(Commands.literal(TardisRefined.MODID).requires(commandSource -> commandSource.hasPermission(Platform.getServer().getOperatorUserPermissionLevel()))
.then(InteriorCommand.register(dispatcher))
.then(Commands.literal("data").then(Commands.literal("export").then(ExportDesktopCommand.register(dispatcher))))

);

.then(Commands.literal("level").then(LevelCommand.register(dispatcher))));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package whocraft.tardis_refined.command.sub;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.DimensionArgument;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import whocraft.tardis_refined.common.capability.TardisLevelOperator;
import whocraft.tardis_refined.common.capability.upgrades.UpgradeHandler;
import whocraft.tardis_refined.common.util.CommandHelper;

public class LevelCommand {

public static ArgumentBuilder<CommandSourceStack, ?> register(CommandDispatcher<CommandSourceStack> dispatcher) {
return Commands.argument("dimension", DimensionArgument.dimension()).suggests(CommandHelper.SUGGEST_TARDISES)
.then(Commands.literal("get-points").executes(LevelCommand::getDimensionPoints))
.then(Commands.literal("set-points").then(Commands.argument("points", IntegerArgumentType.integer()).executes(LevelCommand::setDimensionPoints)))
.then(Commands.literal("add-points").then(Commands.argument("points", IntegerArgumentType.integer()).executes(LevelCommand::addDimensionPoints)))
.then(Commands.literal("get-xp").executes(LevelCommand::getDimensionXp))
.then(Commands.literal("set-xp").then(Commands.argument("xp", IntegerArgumentType.integer()).executes(LevelCommand::setDimensionXp)))
.then(Commands.literal("add-xp").then(Commands.argument("xp", IntegerArgumentType.integer()).executes(LevelCommand::addDimensionXp)));

}

private static int getDimensionPoints(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerLevel dimension = DimensionArgument.getDimension(context, "dimension");

TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> {
int points = tardisLevelOperator.getUpgradeHandler().getUpgradePoints();
context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " levels: " + points));
});

return Command.SINGLE_SUCCESS;
}

private static int setDimensionPoints(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerLevel dimension = DimensionArgument.getDimension(context, "dimension");
int points = IntegerArgumentType.getInteger(context, "points");

TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> {
tardisLevelOperator.getUpgradeHandler().setUpgradePoints(points);
context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " points set to " + points));
});

return Command.SINGLE_SUCCESS;
}

private static int addDimensionPoints(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerLevel dimension = DimensionArgument.getDimension(context, "dimension");
int points = IntegerArgumentType.getInteger(context, "points");

TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> {
UpgradeHandler upgradeHandler = tardisLevelOperator.getUpgradeHandler();
upgradeHandler.setUpgradePoints(upgradeHandler.getUpgradePoints() + points);
context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " points set to " + upgradeHandler.getUpgradePoints()));
});

return Command.SINGLE_SUCCESS;
}

private static int addDimensionXp(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerLevel dimension = DimensionArgument.getDimension(context, "dimension");
int points = IntegerArgumentType.getInteger(context, "points");

TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> {
UpgradeHandler upgradeHandler = tardisLevelOperator.getUpgradeHandler();
upgradeHandler.setUpgradeXP(upgradeHandler.getUpgradeXP() + points);
context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " points set to " + upgradeHandler.getUpgradeXP()));
});

return Command.SINGLE_SUCCESS;
}

private static int getDimensionXp(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerLevel dimension = DimensionArgument.getDimension(context, "dimension");

TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> {
int xp = tardisLevelOperator.getUpgradeHandler().getUpgradeXP();
context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " xp: " + xp));
});

return Command.SINGLE_SUCCESS;
}

private static int setDimensionXp(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
ServerLevel dimension = DimensionArgument.getDimension(context, "dimension");
int points = IntegerArgumentType.getInteger(context, "xp");

TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> {
tardisLevelOperator.getUpgradeHandler().setUpgradePoints(points);
context.getSource().sendSystemMessage(Component.literal("Tardis: " + dimension.toString().split(":")[1] + " xp set to " + points));
});

return Command.SINGLE_SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void addUpgradeXP(int upgradeXP) {
this.upgradeXP = XP_PER_UPGRADE_POINT - Mth.abs(this.upgradeXP);
}

this.upgradePoints = Mth.clamp(this.upgradePoints, 0, 99);
this.upgradePoints = Mth.clamp(this.upgradePoints, 0, Integer.MAX_VALUE);

}

Expand All @@ -110,8 +110,7 @@ public int getNeededXPForNextPoint() {
}

public void setUpgradePoints(int upgradePoints) {
this.upgradePoints = Mth.clamp(upgradePoints, 0, 99);

this.upgradePoints = Mth.clamp(upgradePoints, 0, Integer.MAX_VALUE);
}

public int getUpgradePoints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static Map<ResourceLocation, List<ShellPattern>> registerDefaultPatterns(
addDefaultPattern(ShellTheme.BIG_BEN.getId(), "gothic", false);

Map<ResourceLocation, List<ShellPattern>> patternsByCollection = new HashMap<>();
DEFAULT_PATTERNS.entrySet().forEach(entry -> patternsByCollection.put(entry.getKey(), entry.getValue()));
patternsByCollection.putAll(DEFAULT_PATTERNS);

return patternsByCollection;
}
Expand Down

0 comments on commit ec9d508

Please sign in to comment.