[Feature] /bclib print dimensions
command
This commit is contained in:
parent
8f9c33e378
commit
f6aa62547f
3 changed files with 62 additions and 4 deletions
|
@ -48,6 +48,13 @@ public class CommandRegistry {
|
||||||
.requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
|
.requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
|
||||||
.executes(ctx -> DumpDatapack.dumpDatapack(ctx))
|
.executes(ctx -> DumpDatapack.dumpDatapack(ctx))
|
||||||
)
|
)
|
||||||
|
.then(Commands.literal("print")
|
||||||
|
.requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
|
||||||
|
.then(Commands.literal("dimensions")
|
||||||
|
.requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
|
||||||
|
.executes(ctx -> PrintInfo.printDimensions(ctx))
|
||||||
|
)
|
||||||
|
)
|
||||||
.then(Commands.literal("debug_ore")
|
.then(Commands.literal("debug_ore")
|
||||||
.requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
|
.requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
|
||||||
.executes(ctx -> revealOre(ctx))
|
.executes(ctx -> revealOre(ctx))
|
||||||
|
|
|
@ -13,6 +13,8 @@ import com.mojang.serialization.codecs.KeyDispatchCodec;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.Style;
|
||||||
import net.minecraft.resources.RegistryOps;
|
import net.minecraft.resources.RegistryOps;
|
||||||
import net.minecraft.tags.TagEntry;
|
import net.minecraft.tags.TagEntry;
|
||||||
import net.minecraft.tags.TagFile;
|
import net.minecraft.tags.TagFile;
|
||||||
|
@ -45,24 +47,32 @@ import java.nio.file.Files;
|
||||||
|
|
||||||
public class DumpDatapack {
|
public class DumpDatapack {
|
||||||
static int dumpDatapack(CommandContext<CommandSourceStack> ctx) {
|
static int dumpDatapack(CommandContext<CommandSourceStack> ctx) {
|
||||||
dumpDatapack(ctx.getSource().getLevel().registryAccess());
|
File base = new File(System.getProperty("user.dir"), "bclib_datapack_dump");
|
||||||
|
dumpDatapack(base, ctx.getSource().getLevel().registryAccess());
|
||||||
|
|
||||||
|
ctx.getSource().sendSuccess(
|
||||||
|
Component.literal("Succesfully written to:\n ").append(
|
||||||
|
Component.literal(base.toString()).setStyle(Style.EMPTY.withUnderlined(true))
|
||||||
|
),
|
||||||
|
false
|
||||||
|
);
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dumpDatapack(RegistryAccess registryAccess) {
|
public static void dumpDatapack(File base, RegistryAccess registryAccess) {
|
||||||
final RegistryOps<JsonElement> registryOps = RegistryOps.create(JsonOps.INSTANCE, registryAccess);
|
final RegistryOps<JsonElement> registryOps = RegistryOps.create(JsonOps.INSTANCE, registryAccess);
|
||||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
gsonBuilder = gsonBuilder.setPrettyPrinting();
|
gsonBuilder = gsonBuilder.setPrettyPrinting();
|
||||||
Gson gson = gsonBuilder.create();
|
Gson gson = gsonBuilder.create();
|
||||||
registryAccess.registries().forEach(r -> dumpDatapack(r, registryOps, gson));
|
registryAccess.registries().forEach(r -> dumpDatapack(base, r, registryOps, gson));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> void dumpDatapack(
|
private static <T> void dumpDatapack(
|
||||||
|
File base,
|
||||||
RegistryAccess.RegistryEntry<T> registry,
|
RegistryAccess.RegistryEntry<T> registry,
|
||||||
RegistryOps<JsonElement> registryOps,
|
RegistryOps<JsonElement> registryOps,
|
||||||
Gson gson
|
Gson gson
|
||||||
) {
|
) {
|
||||||
File base = new File(System.getProperty("user.dir"), "bclib_datapack_dump");
|
|
||||||
BCLib.LOGGER.info(registry.key().toString());
|
BCLib.LOGGER.info(registry.key().toString());
|
||||||
// Tag Output
|
// Tag Output
|
||||||
registry.value()
|
registry.value()
|
||||||
|
@ -261,5 +271,6 @@ public class DumpDatapack {
|
||||||
BCLib.LOGGER.error(" !!! Could not determine Codec: " + obj.getClass());
|
BCLib.LOGGER.error(" !!! Could not determine Codec: " + obj.getClass());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
40
src/main/java/org/betterx/bclib/commands/PrintInfo.java
Normal file
40
src/main/java/org/betterx/bclib/commands/PrintInfo.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package org.betterx.bclib.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
|
import net.minecraft.network.chat.Style;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
|
public class PrintInfo {
|
||||||
|
static int printDimensions(CommandContext<CommandSourceStack> ctx) {
|
||||||
|
|
||||||
|
MutableComponent result = Component.literal("World Dimensions: ")
|
||||||
|
.setStyle(Style.EMPTY.withBold(true).withColor(ChatFormatting.BLUE));
|
||||||
|
|
||||||
|
for (var serverLevel : ctx.getSource().getLevel().getServer().getAllLevels()) {
|
||||||
|
var generator = serverLevel.getChunkSource().getGenerator();
|
||||||
|
String output = "\n - " + serverLevel.dimension().location().toString() + ": " +
|
||||||
|
"\n " + generator.toString().trim() + " " +
|
||||||
|
generator
|
||||||
|
.getBiomeSource()
|
||||||
|
.toString()
|
||||||
|
.replace("\n", "\n ");
|
||||||
|
var cl = ChatFormatting.LIGHT_PURPLE;
|
||||||
|
if (serverLevel.dimension().location().equals(Level.OVERWORLD.location()))
|
||||||
|
cl = ChatFormatting.WHITE;
|
||||||
|
else if (serverLevel.dimension().location().equals(Level.NETHER.location()))
|
||||||
|
cl = ChatFormatting.RED;
|
||||||
|
if (serverLevel.dimension().location().equals(Level.END.location()))
|
||||||
|
cl = ChatFormatting.YELLOW;
|
||||||
|
Component dimComponent = Component.literal(output)
|
||||||
|
.setStyle(Style.EMPTY.withBold(false).withColor(cl));
|
||||||
|
result.append(dimComponent);
|
||||||
|
}
|
||||||
|
ctx.getSource().sendSuccess(result, false);
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue