From 1995378d497931a1dd900108a93cf54c71c028c9 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Mon, 7 Dec 2020 15:43:04 +0000 Subject: [PATCH] Added a debug command to spawn all the blocks --- .../common/ActuallyAdditions.java | 14 ++++++ .../common/commands/DebugCommand.java | 45 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/common/commands/DebugCommand.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java index 75e94561a..4da7d128b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java @@ -2,11 +2,13 @@ package de.ellpeck.actuallyadditions.common; import de.ellpeck.actuallyadditions.client.ClientSetup; import de.ellpeck.actuallyadditions.common.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.common.commands.DebugCommand; import de.ellpeck.actuallyadditions.common.config.Config; import de.ellpeck.actuallyadditions.common.container.ActuallyContainers; import de.ellpeck.actuallyadditions.common.items.ActuallyItems; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderTypeLookup; +import net.minecraft.command.Commands; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; @@ -16,6 +18,7 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -47,13 +50,17 @@ public class ActuallyAdditions { eventBus.addListener(this::setup); eventBus.addListener(this::clientSetup); + MinecraftForge.EVENT_BUS.addListener(this::serverLoad); MinecraftForge.EVENT_BUS.register(this); } private void setup(FMLCommonSetupEvent event) { + } private void clientSetup(FMLClientSetupEvent event) { + ClientSetup.setup(); + RenderTypeLookup.setRenderLayer(ActuallyBlocks.CRYSTAL_CLUSTER_VOID.get(), RenderType.getTranslucent()); RenderTypeLookup.setRenderLayer(ActuallyBlocks.CRYSTAL_CLUSTER_ENORI.get(), RenderType.getTranslucent()); RenderTypeLookup.setRenderLayer(ActuallyBlocks.CRYSTAL_CLUSTER_RESTONIA.get(), RenderType.getTranslucent()); @@ -62,4 +69,11 @@ public class ActuallyAdditions { RenderTypeLookup.setRenderLayer(ActuallyBlocks.CRYSTAL_CLUSTER_EMERADIC.get(), RenderType.getTranslucent()); RenderTypeLookup.setRenderLayer(ActuallyBlocks.GREENHOUSE_GLASS.get(), RenderType.getCutout()); } + + private void serverLoad(FMLServerStartingEvent event) { + event.getServer().getCommandManager().getDispatcher().register( + Commands.literal(MOD_ID) + .then(DebugCommand.register()) + ); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/commands/DebugCommand.java b/src/main/java/de/ellpeck/actuallyadditions/common/commands/DebugCommand.java new file mode 100644 index 000000000..42b9a7235 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/common/commands/DebugCommand.java @@ -0,0 +1,45 @@ +package de.ellpeck.actuallyadditions.common.commands; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import de.ellpeck.actuallyadditions.common.blocks.ActuallyBlocks; +import net.minecraft.block.Block; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fml.RegistryObject; + +import java.util.Collection; + +public class DebugCommand { + public static LiteralArgumentBuilder register() { + return Commands.literal("debug-spawn") + .requires(commandSource -> commandSource.hasPermissionLevel(2)) + .executes(DebugCommand::execute); + } + + private static int execute(CommandContext context) throws CommandSyntaxException { + ServerPlayerEntity player = context.getSource().asPlayer(); + + Collection> entries = ActuallyBlocks.BLOCKS.getEntries(); + + int x = player.getPosition().getX(), z = player.getPosition().getZ(); + int row = 0, col = 0; + for (RegistryObject block: entries) { + if (row > 10) { + col += 1; + row = 0; + } + + context.getSource().getWorld().setBlockState(new BlockPos( + x + (2 * row), player.getPosition().getY(), z + (2 * col) + ), block.get().getDefaultState()); + + row ++; + } + + return 1; + } +}