From 905f8e017f03164b1766972f13932dfa88c6c4b3 Mon Sep 17 00:00:00 2001 From: marcus8448 Date: Sat, 25 May 2024 15:45:21 -0700 Subject: [PATCH] cleanup: commands add a keybinding for celestial map --- .../assets/galacticraft/lang/en_us.json | 10 +- .../java/dev/galacticraft/mod/Constant.java | 2 +- .../galacticraft/mod/GalacticraftClient.java | 5 +- .../galacticraft/mod/api/config/Config.java | 2 + .../galacticraft/mod/client/GCKeyBinds.java | 17 +- .../ingame/CelestialSelectionScreen.java | 2 +- .../network/GCClientPacketReceiver.java | 2 +- .../mod/command/DimensionTpCommand.java | 137 ++++++++++ .../galacticraft/mod/command/GCCommands.java | 234 +----------------- .../mod/command/GCHoustonCommand.java | 90 +++++++ .../galacticraft/mod/config/ConfigImpl.java | 22 +- .../mod/data/GCTranslationProvider.java | 10 +- .../mod/events/ClientEventHandler.java | 7 +- .../mod/structure/dungeon/Corridor.java | 26 +- .../mod/structure/dungeon/RoomBoss.java | 44 ++-- .../mod/structure/dungeon/RoomEmpty.java | 26 +- .../mod/structure/dungeon/RoomEntrance.java | 12 +- .../mod/structure/dungeon/RoomTreasure.java | 38 ++- .../galacticraft/mod/util/Translations.java | 12 +- 19 files changed, 362 insertions(+), 336 deletions(-) create mode 100644 src/main/java/dev/galacticraft/mod/command/DimensionTpCommand.java create mode 100644 src/main/java/dev/galacticraft/mod/command/GCHoustonCommand.java diff --git a/src/main/generated/assets/galacticraft/lang/en_us.json b/src/main/generated/assets/galacticraft/lang/en_us.json index 7cfb665fd..b8a6c8314 100644 --- a/src/main/generated/assets/galacticraft/lang/en_us.json +++ b/src/main/generated/assets/galacticraft/lang/en_us.json @@ -244,15 +244,12 @@ "chat.galacticraft.rocket.warning": "Press again to launch.", "commands.galacticraft.debug.registry.dump": "Dumped: %s", "commands.galacticraft.debug.registry.id": "%s - %s: %s", - "commands.galacticraft.dimensiontp.failure.already_in_dimension": "Already inside dimension %s", - "commands.galacticraft.dimensiontp.failure.entity": "Invalid entity", "commands.galacticraft.dimensiontp.success.multiple": "Teleported %s entities to %s", - "commands.galacticraft.dimensiontp.success.pos": "Teleported to %s at (%d, %d, %d)", "commands.galacticraft.dimensiontp.success.single": "Teleported to %s", + "commands.galacticraft.gchouston.cannot_detect_signal": "We cannot locate your signal! Are you sure you're in space?", "commands.galacticraft.gchouston.confirm": "Er, Houston, we have a problem... (Run this command again to confirm teleport)", "commands.galacticraft.gchouston.on_earth_already": "I don't need to be rescued!", "commands.galacticraft.gchouston.success": "You have been rescued. Better luck next time...", - "commands.galacticraft.opencelestialscreen.requires_player": "Requires Player", "commands.galacticraft.oxygen.get.area.full": "Area is filled with oxygen", "commands.galacticraft.oxygen.get.area.none": "Area contains no oxygen", "commands.galacticraft.oxygen.get.area.partial": "Area partially contains oxygen", @@ -260,9 +257,10 @@ "commands.galacticraft.oxygen.get.single.oxygen": "Oxygen exists at block", "commands.galacticraft.oxygen.set.multiple": "Set oxygen at blocks", "commands.galacticraft.oxygen.set.single": "Set oxygen at block", - "commands.galacticraft.require_player": "Command requires player", "config.galacticraft.client": "Client", "config.galacticraft.client.skybox": "Skybox", + "config.galacticraft.commands": "Commands", + "config.galacticraft.commands.enable_gc_houston": "Enable /gchouston", "config.galacticraft.debug": "Debug", "config.galacticraft.debug.hide_alpha_warning": "Hide Alpha Warning", "config.galacticraft.debug.logging": "Debug Logging", @@ -270,6 +268,7 @@ "config.galacticraft.energy.machines": "Machines", "config.galacticraft.energy.machines.circuit_fabricator_energy_consumption_rate": "Circuit Fabricator Energy Consumption Rate/t", "config.galacticraft.energy.machines.coal_generator_energy_production_rate": "Coal Generator Energy Production Rate/t", + "config.galacticraft.energy.machines.electric_compressor_energy_consumption_rate": "Electric Compressor Energy Consumption Rate/t", "config.galacticraft.energy.machines.electric_furnace_energy_consumption_rate": "Electric Furnace Energy Consumption Rate/t", "config.galacticraft.energy.machines.energy_storage_module_storage_size": "Energy Storage Module Energy Storage Size", "config.galacticraft.energy.machines.energy_storage_size": "Default Machine Energy Storage Size", @@ -478,6 +477,7 @@ "itemGroup.galacticraft.blocks": "Galacticraft Blocks", "itemGroup.galacticraft.items": "Galacticraft Items", "itemGroup.galacticraft.machines": "Galacticraft Machines", + "key.galacticraft.open_celestial_screen": "Open Celestial Map", "key.galacticraft.rocket.inventory": "Open Rocket Inventory", "planet.galacticraft.asteroids": "Asteroids", "planet.galacticraft.asteroids.description": "", diff --git a/src/main/java/dev/galacticraft/mod/Constant.java b/src/main/java/dev/galacticraft/mod/Constant.java index 6ecc687a5..479d5ad3e 100644 --- a/src/main/java/dev/galacticraft/mod/Constant.java +++ b/src/main/java/dev/galacticraft/mod/Constant.java @@ -808,7 +808,7 @@ interface Structure { interface Command { String HOUSTON = "gchouston"; String DIMENSION_TP = "dimensiontp"; - String DIMENSION_TP_ALIAS = "dimtp"; + String DIMTP = "dimtp"; String OPEN_CELESTIAL_SCREEN = "opencelestialscreen"; } diff --git a/src/main/java/dev/galacticraft/mod/GalacticraftClient.java b/src/main/java/dev/galacticraft/mod/GalacticraftClient.java index b9e7434ce..be28f725f 100644 --- a/src/main/java/dev/galacticraft/mod/GalacticraftClient.java +++ b/src/main/java/dev/galacticraft/mod/GalacticraftClient.java @@ -57,7 +57,6 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; @@ -181,6 +180,8 @@ public void onInitializeClient() { }); + ModelLoadingPlugin.register(GCModelLoader.INSTANCE); + Constant.LOGGER.info("Client initialization complete. (Took {}ms.)", System.currentTimeMillis() - startInitTime); } @@ -189,8 +190,6 @@ public void onInitializeClient() { * should be safe to do general initialization here. */ public static void init() { -// ModelLoadingPlugin.register(GCModelLoader.INSTANCE); - var helper = ResourceManagerHelper.get(PackType.CLIENT_RESOURCES); helper.registerReloadListener(RocketTextureManager.INSTANCE); helper.registerReloadListener(GCModelLoader.INSTANCE); diff --git a/src/main/java/dev/galacticraft/mod/api/config/Config.java b/src/main/java/dev/galacticraft/mod/api/config/Config.java index 78b170648..6b5728278 100644 --- a/src/main/java/dev/galacticraft/mod/api/config/Config.java +++ b/src/main/java/dev/galacticraft/mod/api/config/Config.java @@ -59,6 +59,8 @@ public interface Config { double bossHealthMultiplier(); + boolean enableGcHouston(); + void load(); void save(); diff --git a/src/main/java/dev/galacticraft/mod/client/GCKeyBinds.java b/src/main/java/dev/galacticraft/mod/client/GCKeyBinds.java index 5077a0fc3..3fcd8de83 100644 --- a/src/main/java/dev/galacticraft/mod/client/GCKeyBinds.java +++ b/src/main/java/dev/galacticraft/mod/client/GCKeyBinds.java @@ -22,14 +22,29 @@ package dev.galacticraft.mod.client; +import dev.galacticraft.mod.client.gui.screen.ingame.CelestialSelectionScreen; import dev.galacticraft.mod.util.Translations; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.KeyMapping; +import net.minecraft.client.Minecraft; import org.lwjgl.glfw.GLFW; public class GCKeyBinds { - public static final KeyMapping OPEN_ROCKET_INVENTORY = KeyBindingHelper.registerKeyBinding(new KeyMapping(Translations.Keybindings.ROCKET_INVENTORY, GLFW.GLFW_KEY_F, "key.categories.inventory")); + public static final KeyMapping OPEN_CELESTIAL_SCREEN = new KeyMapping(Translations.Keybindings.OPEN_CELESTIAL_SCREEN, GLFW.GLFW_KEY_M, KeyMapping.CATEGORY_MISC); + public static final KeyMapping OPEN_ROCKET_INVENTORY = new KeyMapping(Translations.Keybindings.ROCKET_INVENTORY, GLFW.GLFW_KEY_F, KeyMapping.CATEGORY_INVENTORY); public static void register() { + KeyBindingHelper.registerKeyBinding(OPEN_CELESTIAL_SCREEN); + KeyBindingHelper.registerKeyBinding(OPEN_ROCKET_INVENTORY); + } + + public static void handleKeybinds(Minecraft client) { + if (client.level != null && client.player != null) { + if (client.screen == null) { + while (OPEN_CELESTIAL_SCREEN.consumeClick()) { + client.setScreen(new CelestialSelectionScreen(true, null, false, null)); + } + } + } } } diff --git a/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/CelestialSelectionScreen.java b/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/CelestialSelectionScreen.java index 025c3c6a5..ef380bc02 100644 --- a/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/CelestialSelectionScreen.java +++ b/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/CelestialSelectionScreen.java @@ -104,7 +104,7 @@ public class CelestialSelectionScreen extends Screen { protected static final ResourceLocation TEXTURE_1 = Constant.id("textures/gui/celestial_selection_1.png"); protected static int BORDER_SIZE = 0; protected static int BORDER_EDGE_SIZE = 0; - protected final boolean mapMode; + public final boolean mapMode; private final @Nullable RocketData data; public final boolean canCreateStations; protected float zoom = 0.0F; diff --git a/src/main/java/dev/galacticraft/mod/client/network/GCClientPacketReceiver.java b/src/main/java/dev/galacticraft/mod/client/network/GCClientPacketReceiver.java index 0185fb825..e192b88cf 100644 --- a/src/main/java/dev/galacticraft/mod/client/network/GCClientPacketReceiver.java +++ b/src/main/java/dev/galacticraft/mod/client/network/GCClientPacketReceiver.java @@ -67,7 +67,7 @@ public static void register() { boolean mapMode = buf.readBoolean(); client.execute(() -> client.setScreen(new CelestialSelectionScreen(mapMode, RocketData.fromNbt(GCItems.ROCKET.getDefaultInstance().getTag()), true, null))); } - default -> Constant.LOGGER.error("No screen found!"); + default -> Constant.LOGGER.error("No screen found with id '{}'!", screen); } }); diff --git a/src/main/java/dev/galacticraft/mod/command/DimensionTpCommand.java b/src/main/java/dev/galacticraft/mod/command/DimensionTpCommand.java new file mode 100644 index 000000000..2e4a920f5 --- /dev/null +++ b/src/main/java/dev/galacticraft/mod/command/DimensionTpCommand.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.galacticraft.mod.command; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.galacticraft.mod.Constant; +import dev.galacticraft.mod.network.GCScreenType; +import dev.galacticraft.mod.util.Translations; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.DimensionArgument; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.commands.arguments.coordinates.BlockPosArgument; +import net.minecraft.commands.arguments.coordinates.Vec3Argument; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.Collections; + +public class DimensionTpCommand { + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(Commands.literal(Constant.Command.DIMENSION_TP) + .requires(stack -> stack.hasPermission(2)) + .executes(DimensionTpCommand::openCelestialScreen) + .then(Commands.argument("dimension", DimensionArgument.dimension()) + .executes(ctx -> teleportToDimension(ctx, Collections.singleton(ctx.getSource().getPlayerOrException()), null)) + .then(Commands.argument("players", EntityArgument.players()) + .executes(ctx -> teleportToDimension(ctx, EntityArgument.getPlayers(ctx, "players"), null)) + .then(Commands.argument("pos", Vec3Argument.vec3(true)) + .executes(ctx -> teleportToDimension(ctx, EntityArgument.getPlayers(ctx, "players"), Vec3Argument.getVec3(ctx, "pos"))))) + .then(Commands.argument("pos", BlockPosArgument.blockPos()) + .executes(ctx -> teleportToDimension(ctx, Collections.singleton(ctx.getSource().getPlayerOrException()), Vec3Argument.getVec3(ctx, "pos"))) + ) + ) + ); + + dispatcher.register(Commands.literal(Constant.Command.DIMTP) + .redirect(dispatcher.getRoot().getChild(Constant.Command.DIMENSION_TP)) + ); + } + + private static int teleportToDimension(CommandContext context, @NotNull Collection players, @Nullable Vec3 pos) throws CommandSyntaxException { + ServerLevel level = DimensionArgument.getDimension(context, "dimension"); + + int success = 0; + for (ServerPlayer player : players) { + success += tryTeleport(level, player, pos) ? 1 : 0; + } + + if (success > 0) { + if (success == 1) { + context.getSource().sendSuccess(() -> Component.translatable(Translations.DimensionTp.SUCCESS_SINGLE, level.dimension().location()), true); + } else { + int tmp = success; + context.getSource().sendSuccess(() -> Component.translatable(Translations.DimensionTp.SUCCESS_MULTIPLE, tmp, level.dimension().location()), true); + } + return success; + } + return -1; + } + + private static boolean tryTeleport(ServerLevel level, ServerPlayer player, @Nullable Vec3 pos) { + if (pos == null) pos = getValidTeleportPos(level, player); + player.teleportTo(level, + pos.x, + pos.y, + pos.z, + player.getYRot(), + player.getXRot() + ); + return true; + } + + private static int openCelestialScreen(CommandContext context) throws CommandSyntaxException { + var player = context.getSource().getPlayerOrException(); + + var buf = PacketByteBufs.create(); + buf.writeEnum(GCScreenType.CELESTIAL); + buf.writeBoolean(false); + ServerPlayNetworking.send(player, Constant.Packet.OPEN_SCREEN, buf); + + return Command.SINGLE_SUCCESS; + } + + + /** + * Finds the highest solid block in the level to teleport to. + * @param level The level. + * @param entity The entity to teleport. + * @return The highest valid position to teleport to. + */ + static Vec3 getValidTeleportPos(ServerLevel level, Entity entity) { + if (entity.level() == level) return entity.position(); + BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(); + pos.set(entity.blockPosition()); + + for (int y = level.getMaxBuildHeight(); y > level.getMinBuildHeight(); y--) { + pos.setY(y); + if (!level.getBlockState(pos).isAir()) { + return new Vec3(entity.getX(), y + 1.0, entity.getZ()); + } + } + return entity.position(); + } +} diff --git a/src/main/java/dev/galacticraft/mod/command/GCCommands.java b/src/main/java/dev/galacticraft/mod/command/GCCommands.java index e4f730a5f..03415eb19 100644 --- a/src/main/java/dev/galacticraft/mod/command/GCCommands.java +++ b/src/main/java/dev/galacticraft/mod/command/GCCommands.java @@ -22,241 +22,17 @@ package dev.galacticraft.mod.command; -import com.mojang.brigadier.Command; -import com.mojang.brigadier.arguments.BoolArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.tree.LiteralCommandNode; -import dev.galacticraft.api.universe.celestialbody.CelestialBody; -import dev.galacticraft.mod.Constant; -import dev.galacticraft.mod.network.GCScreenType; -import dev.galacticraft.mod.util.Translations; -import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; -import it.unimi.dsi.fastutil.objects.Object2IntMap; +import dev.galacticraft.mod.Galacticraft; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.Commands; -import net.minecraft.commands.arguments.DimensionArgument; -import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.coordinates.BlockPosArgument; -import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.Mth; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.block.Block; - -import java.util.Collection; -import java.util.UUID; public class GCCommands { - private static final Object2IntMap GC_HOUSTON_TIMERS = new Object2IntArrayMap<>(); - private static final int GC_HOUSTON_TIMER_LENGTH = 12 * 20; // seconds * tps - public static void register() { - CommandRegistrationCallback.EVENT.register((commandDispatcher, registryAccess, environment) -> { - - commandDispatcher.register( - Commands.literal(Constant.Command.HOUSTON) - .executes(GCCommands::teleportToEarth)); - - LiteralCommandNode node = commandDispatcher.register( - Commands.literal(Constant.Command.DIMENSION_TP) - .requires(stack -> stack.hasPermission(2)) - .then(Commands.argument("dimension", DimensionArgument.dimension()) - .executes(GCCommands::teleport) - .then(Commands.argument("entities", EntityArgument.entities()) - .executes(((GCCommands::teleportMultiple)))) - .then(Commands.argument("pos", BlockPosArgument.blockPos()) - .executes(GCCommands::teleportToCoords)))); - commandDispatcher.register(Commands.literal(Constant.Command.DIMENSION_TP_ALIAS).redirect(node)); - - commandDispatcher.register( - Commands.literal(Constant.Command.OPEN_CELESTIAL_SCREEN) - .requires(stack -> stack.hasPermission(2)) - .then(Commands.argument("players", EntityArgument.players()) - .executes(context -> openCelestialScreenWithPlayer(context, false)) - .then(Commands.argument("mapMode", BoolArgumentType.bool()) - .executes(context -> openCelestialScreenWithPlayer(context, BoolArgumentType.getBool(context, "mapMode"))) - ) - ) - .executes(context -> openCelestialScreen(context, true))); - }); - } - - private static int openCelestialScreen(CommandContext context, boolean mapMode) { - var player = context.getSource().getPlayer(); - if (player != null) { - var buf = PacketByteBufs.create(); - buf.writeEnum(GCScreenType.CELESTIAL); - buf.writeBoolean(mapMode); - player.galacticraft$openCelestialScreen(null); - ServerPlayNetworking.send(player, Constant.Packet.OPEN_SCREEN, buf); - } else { - context.getSource().sendFailure(Component.translatable(Translations.OpenCelestialScreen.REQUIRES_PLAYER)); - return 0; - } - return Command.SINGLE_SUCCESS; - } + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { + DimensionTpCommand.register(dispatcher); - private static int openCelestialScreenWithPlayer(CommandContext context, boolean mapMode) throws CommandSyntaxException { - var buf = PacketByteBufs.create(); - buf.writeEnum(GCScreenType.CELESTIAL); - buf.writeBoolean(mapMode); - for (ServerPlayer player : EntityArgument.getPlayers(context, "players")) { - player.galacticraft$openCelestialScreen(null); - ServerPlayNetworking.send(player, Constant.Packet.OPEN_SCREEN, buf); - } - return Command.SINGLE_SUCCESS; - } - - private static int teleportToEarth(CommandContext context) { - final int[] retval = new int[]{Command.SINGLE_SUCCESS}; - // Clear the expired timers - for (UUID id : GC_HOUSTON_TIMERS.keySet()) { - if (GC_HOUSTON_TIMERS.getInt(id) + GC_HOUSTON_TIMER_LENGTH < context.getSource().getServer().getTickCount()) { - GC_HOUSTON_TIMERS.removeInt(id); - } - } - context.getSource().getServer().execute(() -> { - if (CelestialBody.getByDimension(context.getSource().registryAccess(), context.getSource().getLevel().dimension()).isEmpty()) { - context.getSource().sendFailure(Component.translatable(Translations.GcHouston.IN_OTHER_DIMENSION).setStyle(Constant.Text.Color.RED_STYLE)); - retval[0] = -1; - return; - } - ServerPlayer player = context.getSource().getPlayer(); - if (player == null) { - context.getSource().sendFailure(Component.translatable(Translations.GcHouston.MISSING_PLAYER).setStyle(Constant.Text.Color.RED_STYLE)); - retval[0] = -1; - return; - } - ServerLevel serverWorld = context.getSource().getServer().overworld(); - if (context.getSource().getLevel().equals(serverWorld)) { - context.getSource().sendFailure(Component.translatable(Translations.GcHouston.IN_OVERWORLD).setStyle(Constant.Text.Color.RED_STYLE)); - retval[0] = -1; - return; - } - UUID playerID = context.getSource().getPlayer().getGameProfile().getId(); - if (!GC_HOUSTON_TIMERS.containsKey(playerID)) { - GC_HOUSTON_TIMERS.put(playerID, context.getSource().getServer().getTickCount()); - context.getSource().sendSuccess(() -> Component.translatable(Translations.GcHouston.CONFIRMATION, serverWorld.dimension().location()).setStyle(Constant.Text.Color.RED_STYLE), false); - } else if (GC_HOUSTON_TIMERS.getInt(playerID) + GC_HOUSTON_TIMER_LENGTH > context.getSource().getServer().getTickCount()) { - GC_HOUSTON_TIMERS.removeInt(playerID); - BlockPos pos = getValidTeleportPos(serverWorld, player); - player.teleportTo(serverWorld, - pos.getX(), - pos.getY(), - pos.getZ(), - player.getYRot(), - player.getXRot()); - context.getSource().sendSuccess(() -> Component.translatable(Translations.GcHouston.SUCCESS, serverWorld.dimension().location()).setStyle(Constant.Text.Color.GREEN_STYLE), true); + if (Galacticraft.CONFIG.enableGcHouston()) { + GCHoustonCommand.register(dispatcher); } }); - return retval[0]; - } - - private static int teleport(CommandContext context) throws CommandSyntaxException { - final int[] retval = new int[]{Command.SINGLE_SUCCESS}; - ServerLevel serverWorld = DimensionArgument.getDimension(context, "dimension"); - context.getSource().getServer().execute(() -> { - ServerPlayer player; - player = context.getSource().getPlayer(); - if (context.getSource().getLevel().equals(serverWorld)) { - context.getSource().sendFailure(Component.translatable(Translations.DimensionTp.ALREADY_IN_DIMENSION, serverWorld.dimension().location()).setStyle(Constant.Text.Color.RED_STYLE)); - retval[0] = -1; - return; - } - BlockPos pos = getValidTeleportPos(serverWorld, player); - player.teleportTo(serverWorld, - pos.getX(), - pos.getY(), - pos.getZ(), - player.getYRot(), - player.getXRot()); - context.getSource().sendSuccess(() -> Component.translatable(Translations.DimensionTp.SUCCESS_SINGLE, serverWorld.dimension().location()), true); - }); - return retval[0]; - } - - private static int teleportMultiple(CommandContext context) throws CommandSyntaxException { - final int[] retval = new int[]{Command.SINGLE_SUCCESS}; - ServerLevel serverWorld = DimensionArgument.getDimension(context, "dimension"); - Collection entities = EntityArgument.getEntities(context, "entities"); - - context.getSource().getServer().execute(() -> { - if (context.getSource().getLevel().equals(serverWorld)) { - context.getSource().sendFailure(Component.translatable(Translations.DimensionTp.ALREADY_IN_DIMENSION, serverWorld.dimension().location()).setStyle(Constant.Text.Color.RED_STYLE)); - retval[0] = -1; - return; - } - for (Entity entity : entities) { - BlockPos pos = getValidTeleportPos(serverWorld, entity); - if (entity instanceof ServerPlayer player) { - player.teleportTo(serverWorld, - pos.getX(), - pos.getY(), - pos.getZ(), - player.getYRot(), - player.getXRot()); - } else { - entity = entity.changeDimension(serverWorld); //Entities are recreated upon dim change, not moved. - if (entity != null) { - entity.teleportToWithTicket(pos.getX(), pos.getY(), pos.getZ()); - } else { - context.getSource().sendFailure(Component.translatable(Translations.DimensionTp.UNKNOWN_ENTITY).setStyle(Constant.Text.Color.RED_STYLE)); - } - } - } - context.getSource().sendSuccess(() -> Component.translatable(Translations.DimensionTp.SUCCESS_MULTIPLE, entities.size(), serverWorld.dimension().location()), true); - }); - return retval[0]; - } - - private static int teleportToCoords(CommandContext context) throws CommandSyntaxException{ - final int[] retval = new int[]{Command.SINGLE_SUCCESS}; - ServerLevel serverWorld = DimensionArgument.getDimension(context, "dimension"); - BlockPos pos = BlockPosArgument.getSpawnablePos(context, "pos"); - - context.getSource().getServer().execute(() -> { - if (context.getSource().getLevel().equals(serverWorld)) { - context.getSource().sendFailure(Component.translatable(Translations.DimensionTp.ALREADY_IN_DIMENSION, serverWorld.dimension().location()).setStyle(Constant.Text.Color.RED_STYLE)); - retval[0] = -1; - return; - } - ServerPlayer player = context.getSource().getPlayer(); - player.teleportTo(serverWorld, - Mth.clamp(pos.getX(), -30000000, 30000000), - Mth.clamp(pos.getY(), 0, serverWorld.getHeight() - 1), - Mth.clamp(pos.getZ(), -30000000, 30000000), - player.getYRot(), - player.getXRot()); - context.getSource().sendSuccess(() -> Component.translatable(Translations.DimensionTp.SUCCESS_POSITION, serverWorld.dimension().location(), pos.getX(), pos.getY(), pos.getZ()), true); - }); - return retval[0]; - } - - /** - * Finds the highest solid block in the world to teleport to. - * @param world The ServerWorld. - * @param entity The entity to teleport. - * @return A valid position (BlockPos) to teleport to. - */ - private static BlockPos getValidTeleportPos(ServerLevel world, Entity entity) { - int posX = (int) entity.getX(); - int posZ = (int) entity.getZ(); - - for (int i = world.getHeight(); i > 0; i--) { - BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(posX, i, posZ); - Block currentBlock = world.getBlockState(pos).getBlock(); - if (!currentBlock.defaultBlockState().isAir()) { - pos.setY(pos.getY() + 1); - return pos; - } - } - // SHOULD NOT happen! Entity gets teleported to where they were before. - return entity.blockPosition(); } } diff --git a/src/main/java/dev/galacticraft/mod/command/GCHoustonCommand.java b/src/main/java/dev/galacticraft/mod/command/GCHoustonCommand.java new file mode 100644 index 000000000..9971eb956 --- /dev/null +++ b/src/main/java/dev/galacticraft/mod/command/GCHoustonCommand.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.galacticraft.mod.command; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import dev.galacticraft.api.universe.celestialbody.CelestialBody; +import dev.galacticraft.mod.Constant; +import dev.galacticraft.mod.util.Translations; +import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; + +import java.util.UUID; + +public class GCHoustonCommand { + private static final Object2IntMap PROMPT_EXPIRY = new Object2IntArrayMap<>(); + private static final int GC_HOUSTON_TIMER_LENGTH = 10000/*ms*/; + + private static final SimpleCommandExceptionType IN_OTHER_DIMENSION = new SimpleCommandExceptionType(Component.translatable(Translations.GcHouston.IN_OTHER_DIMENSION)); + private static final SimpleCommandExceptionType IN_OVERWORLD = new SimpleCommandExceptionType(Component.translatable(Translations.GcHouston.IN_OVERWORLD)); + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(Commands.literal(Constant.Command.HOUSTON) + .executes(GCHoustonCommand::teleportToEarth)); + } + + private static int teleportToEarth(CommandContext context) throws CommandSyntaxException { + ServerPlayer player = context.getSource().getPlayerOrException(); + + if (player.level() == context.getSource().getServer().overworld()) { + throw IN_OVERWORLD.create(); + } + + if (CelestialBody.getByDimension(context.getSource().registryAccess(), context.getSource().getLevel().dimension()).isEmpty()) { + throw IN_OTHER_DIMENSION.create(); + } + + UUID uuid = player.getUUID(); + int tickId = context.getSource().getServer().getTickCount(); + if (tickId < PROMPT_EXPIRY.getOrDefault(uuid, -1)) { + PROMPT_EXPIRY.removeInt(uuid); + + ServerLevel overworld = context.getSource().getServer().overworld(); + BlockPos pos = player.getRespawnPosition(); + if (pos == null) pos = overworld.getSharedSpawnPos(); + + player.teleportTo(overworld, + pos.getX() + 0.5, + pos.getY(), + pos.getZ() + 0.5, + player.getYRot(), + player.getXRot()); + + context.getSource().sendSuccess(() -> Component.translatable(Translations.GcHouston.SUCCESS).setStyle(Constant.Text.Color.GREEN_STYLE), true); + } else { + PROMPT_EXPIRY.put(uuid, tickId + (int)(GC_HOUSTON_TIMER_LENGTH * context.getSource().getServer().tickRateManager().millisecondsPerTick())); + context.getSource().sendSuccess(() -> Component.translatable(Translations.GcHouston.CONFIRMATION), false); + } + return Command.SINGLE_SUCCESS; + } +} diff --git a/src/main/java/dev/galacticraft/mod/config/ConfigImpl.java b/src/main/java/dev/galacticraft/mod/config/ConfigImpl.java index 390591139..63c1d24ff 100644 --- a/src/main/java/dev/galacticraft/mod/config/ConfigImpl.java +++ b/src/main/java/dev/galacticraft/mod/config/ConfigImpl.java @@ -65,6 +65,7 @@ public class ConfigImpl implements Config { private long playerOxygenConsumptionRate = FluidConstants.DROPLET; private double bossHealthMultiplier = 1.0; private boolean hideAlphaWarning = false; + private boolean enableGcHouston = true; public ConfigImpl(File file) { this.gson = new GsonBuilder() @@ -239,6 +240,15 @@ public void setBossHealthMultiplier(double bossHealthMultiplier) { this.bossHealthMultiplier = bossHealthMultiplier; } + @Override + public boolean enableGcHouston() { + return this.enableGcHouston; + } + + public void setEnableGcHouston(boolean enableGcHouston) { + this.enableGcHouston = enableGcHouston; + } + public void load() { if (!this.file.exists()) { this.file.getParentFile().mkdirs(); @@ -450,9 +460,19 @@ public Screen create(Screen parent) { b.getOrCreateCategory(Component.translatable(Translations.Config.DEBUG)).addEntry(dB.build()); b.getOrCreateCategory(Component.translatable(Translations.Config.ENERGY)).addEntry(wires.build()).addEntry(machines.build()); - b.getOrCreateCategory(Component.translatable(Translations.Config.CLIENT)).addEntry(skybox.build()); b.getOrCreateCategory(Component.translatable(Translations.Config.PLAYER)).addEntry(lifeSupport.build()); + SubCategoryBuilder commands = ConfigEntryBuilder.create().startSubCategory(Component.translatable(Translations.Config.COMMANDS)); + + commands.add(new BooleanToggleBuilder( + Component.translatable(Translations.Config.RESET), + Component.translatable(Translations.Config.ENABLE_GC_HOUSTON), + config.enableGcHouston()) + .setSaveConsumer(config::setEnableGcHouston) + .setDefaultValue(true) + .build() + ); + return b.build(); } } diff --git a/src/main/java/dev/galacticraft/mod/data/GCTranslationProvider.java b/src/main/java/dev/galacticraft/mod/data/GCTranslationProvider.java index ad1896f72..5f46eb063 100644 --- a/src/main/java/dev/galacticraft/mod/data/GCTranslationProvider.java +++ b/src/main/java/dev/galacticraft/mod/data/GCTranslationProvider.java @@ -137,27 +137,26 @@ protected void generateTranslations(HolderLookup.@NotNull Provider registries) { this.add(SetOxygen.FULL_OXYGEN, "Area is filled with oxygen"); this.add(SetOxygen.PARTIAL_OXYGEN, "Area partially contains oxygen"); this.add(SetOxygen.EMPTY_OXYGEN, "Area contains no oxygen"); - this.add(OpenCelestialScreen.REQUIRES_PLAYER, "Requires Player"); - this.add(DimensionTp.ALREADY_IN_DIMENSION, "Already inside dimension %s"); - this.add(DimensionTp.UNKNOWN_ENTITY, "Invalid entity"); this.add(DimensionTp.SUCCESS_MULTIPLE, "Teleported %s entities to %s"); - this.add(DimensionTp.SUCCESS_POSITION, "Teleported to %s at (%d, %d, %d)"); this.add(DimensionTp.SUCCESS_SINGLE, "Teleported to %s"); + this.add(GcHouston.IN_OTHER_DIMENSION, "We cannot locate your signal! Are you sure you're in space?"); this.add(GcHouston.CONFIRMATION, "Er, Houston, we have a problem... (Run this command again to confirm teleport)"); this.add(GcHouston.IN_OVERWORLD, "I don't need to be rescued!"); this.add(GcHouston.SUCCESS, "You have been rescued. Better luck next time..."); - this.add(GcHouston.MISSING_PLAYER, "Command requires player"); this.add(Config.CLIENT, "Client"); this.add(Config.SKYBOX, "Skybox"); + this.add(Config.COMMANDS, "Commands"); + this.add(Config.ENABLE_GC_HOUSTON, "Enable /gchouston"); this.add(Config.DEBUG, "Debug"); this.add(Config.HIDE_ALPHA_WARNING, "Hide Alpha Warning"); this.add(Config.DEBUG_LOGGING, "Debug Logging"); this.add(Config.ENERGY, "Energy"); this.add(Config.MACHINES, "Machines"); this.add(Config.CIRCUIT_FABRICATOR_ENERGY_CONSUMPTION_RATE, "Circuit Fabricator Energy Consumption Rate/t"); + this.add(Config.ELECTRIC_COMPRESSOR_ENERGY_CONSUMPTION_RATE, "Electric Compressor Energy Consumption Rate/t"); this.add(Config.COAL_GENERATOR_ENERGY_PRODUCTION_RATE, "Coal Generator Energy Production Rate/t"); this.add(Config.ELECTRIC_FURNACE_ENERGY_CONSUMPTION_RATE, "Electric Compressor Energy Consumption Rate/t"); this.add(Config.ELECTRIC_FURNACE_ENERGY_CONSUMPTION_RATE, "Electric Furnace Energy Consumption Rate/t"); @@ -186,6 +185,7 @@ protected void generateTranslations(HolderLookup.@NotNull Provider registries) { this.add(Galaxy.MILKY_WAY, "Milky Way"); this.add(Keybindings.ROCKET_INVENTORY, "Open Rocket Inventory"); + this.add(Keybindings.OPEN_CELESTIAL_SCREEN, "Open Celestial Map"); this.add(CelestialBody.SOL_DESC, ""); this.add(CelestialBody.SOL, "Sol"); diff --git a/src/main/java/dev/galacticraft/mod/events/ClientEventHandler.java b/src/main/java/dev/galacticraft/mod/events/ClientEventHandler.java index a6b6fc5b7..7d902e6a0 100644 --- a/src/main/java/dev/galacticraft/mod/events/ClientEventHandler.java +++ b/src/main/java/dev/galacticraft/mod/events/ClientEventHandler.java @@ -24,24 +24,20 @@ import dev.galacticraft.api.rocket.LaunchStage; import dev.galacticraft.api.rocket.entity.Rocket; +import dev.galacticraft.mod.client.GCKeyBinds; import dev.galacticraft.mod.client.gui.overlay.CountdownOverlay; import dev.galacticraft.mod.client.gui.overlay.LanderOverlay; import dev.galacticraft.mod.client.gui.overlay.OxygenOverlay; import dev.galacticraft.mod.client.gui.overlay.RocketOverlay; import dev.galacticraft.mod.client.render.FootprintRenderer; import dev.galacticraft.mod.client.sounds.RocketSound; -import dev.galacticraft.mod.content.entity.ControllableEntity; import dev.galacticraft.mod.content.entity.orbital.RocketEntity; import dev.galacticraft.mod.misc.footprint.FootprintManager; -import dev.galacticraft.mod.network.packets.ControlEntityPacket; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.player.Input; -import net.minecraft.client.player.LocalPlayer; public class ClientEventHandler { public static void init() { @@ -62,6 +58,7 @@ public static void rocketLaunchSound(Rocket rocket, LaunchStage oldStage) { public static void clientTick(Minecraft client) { LanderOverlay.clientTick(); + GCKeyBinds.handleKeybinds(client); } public static void tickFootprints(ClientLevel level) { diff --git a/src/main/java/dev/galacticraft/mod/structure/dungeon/Corridor.java b/src/main/java/dev/galacticraft/mod/structure/dungeon/Corridor.java index 87d8ce457..515d076bf 100644 --- a/src/main/java/dev/galacticraft/mod/structure/dungeon/Corridor.java +++ b/src/main/java/dev/galacticraft/mod/structure/dungeon/Corridor.java @@ -37,8 +37,6 @@ import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType; -import java.lang.reflect.Constructor; - public class Corridor extends SizedPiece { public Corridor(CompoundTag tag) { @@ -52,28 +50,28 @@ public Corridor(DungeonConfiguration configuration, RandomSource rand, int block @Override public void postProcess(WorldGenLevel worldIn, StructureManager structureManager, ChunkGenerator chunkGenerator, RandomSource randomIn, BoundingBox structureBoundingBoxIn, ChunkPos pos, BlockPos pivot) { - for (int i = 0; i < this.boundingBox.getXSpan(); i++) { - for (int j = 0; j < this.boundingBox.getYSpan(); j++) { - for (int k = 0; k < this.boundingBox.getZSpan(); k++) { - if ((this.getDirection().getAxis() == Direction.Axis.Z && (i == 0 || i == this.boundingBox.getXSpan() - 1)) || j == 0 || j == this.boundingBox.getYSpan() - 1 - || (this.getDirection().getAxis() == Direction.Axis.X && (k == 0 || k == this.boundingBox.getZSpan() - 1))) { - this.placeBlock(worldIn, this.configuration.getBrickBlock(), i, j, k, this.boundingBox); + for (int x = 0; x < this.boundingBox.getXSpan(); x++) { + for (int y = 0; y < this.boundingBox.getYSpan(); y++) { + for (int z = 0; z < this.boundingBox.getZSpan(); z++) { + if ((this.getDirection().getAxis() == Direction.Axis.Z && (x == 0 || x == this.boundingBox.getXSpan() - 1)) || y == 0 || y == this.boundingBox.getYSpan() - 1 + || (this.getDirection().getAxis() == Direction.Axis.X && (z == 0 || z == this.boundingBox.getZSpan() - 1))) { + this.placeBlock(worldIn, this.configuration.getBrickBlock(), x, y, z, this.boundingBox); } else { - if (j == this.boundingBox.getYSpan() - 2) { - if (this.getDirection().getAxis() == Direction.Axis.Z && (k + 1) % 4 == 0 && (i == 1 || i == this.boundingBox.getXSpan() - 2)) { + if (y == this.boundingBox.getYSpan() - 2) { + if (this.getDirection().getAxis() == Direction.Axis.Z && (z + 1) % 4 == 0 && (x == 1 || x == this.boundingBox.getXSpan() - 2)) { this.placeBlock(worldIn, - GCBlocks.UNLIT_WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, i == 1 ? Direction.WEST.getOpposite() : Direction.EAST.getOpposite()), i, j, k, + GCBlocks.UNLIT_WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, x == 1 ? Direction.WEST.getOpposite() : Direction.EAST.getOpposite()), x, y, z, this.boundingBox); continue; - } else if (this.getDirection().getAxis() == Direction.Axis.X && (i + 1) % 4 == 0 && (k == 1 || k == this.boundingBox.getZSpan() - 2)) { + } else if (this.getDirection().getAxis() == Direction.Axis.X && (x + 1) % 4 == 0 && (z == 1 || z == this.boundingBox.getZSpan() - 2)) { this.placeBlock(worldIn, - GCBlocks.UNLIT_WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, k == 1 ? Direction.NORTH.getOpposite() : Direction.SOUTH.getOpposite()), i, j, k, + GCBlocks.UNLIT_WALL_TORCH.defaultBlockState().setValue(WallTorchBlock.FACING, z == 1 ? Direction.NORTH.getOpposite() : Direction.SOUTH.getOpposite()), x, y, z, this.boundingBox); continue; } } - this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), i, j, k, this.boundingBox); + this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), x, y, z, this.boundingBox); } } } diff --git a/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomBoss.java b/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomBoss.java index 77e366588..5e8fc34cb 100644 --- a/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomBoss.java +++ b/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomBoss.java @@ -61,50 +61,50 @@ public RoomBoss(DungeonConfiguration configuration, RandomSource rand, int block @Override public void postProcess(WorldGenLevel worldIn, StructureManager structureManager, ChunkGenerator generator, RandomSource random, BoundingBox chunkBox, ChunkPos pos, BlockPos pivot) { - for (int i = 0; i <= this.sizeX; i++) { - for (int j = 0; j <= this.sizeY; j++) { - for (int k = 0; k <= this.sizeZ; k++) { - if (i == 0 || i == this.sizeX || j == 0 || j == this.sizeY || k == 0 || k == this.sizeZ) { + for (int x = 0; x <= this.sizeX; x++) { + for (int y = 0; y <= this.sizeY; y++) { + for (int z = 0; z <= this.sizeZ; z++) { + if (x == 0 || x == this.sizeX || y == 0 || y == this.sizeY || z == 0 || z == this.sizeZ) { boolean placeBlock = true; if (getDirection().getAxis() == Direction.Axis.Z) { int start = (this.boundingBox.maxX() - this.boundingBox.minX()) / 2 - 1; int end = (this.boundingBox.maxX() - this.boundingBox.minX()) / 2 + 1; - if (i > start && i <= end && j < 3 && j > 0) { - if (getDirection() == Direction.SOUTH && k == 0) { + if (x > start && x <= end && y < 3 && y > 0) { + if (getDirection() == Direction.SOUTH && z == 0) { placeBlock = false; - } else if (getDirection() == Direction.NORTH && k == this.sizeZ) { + } else if (getDirection() == Direction.NORTH && z == this.sizeZ) { placeBlock = false; } } } else { int start = (this.boundingBox.maxZ() - this.boundingBox.minZ()) / 2 - 1; int end = (this.boundingBox.maxZ() - this.boundingBox.minZ()) / 2 + 1; - if (k > start && k <= end && j < 3 && j > 0) { - if (getDirection() == Direction.EAST && i == 0) { + if (z > start && z <= end && y < 3 && y > 0) { + if (getDirection() == Direction.EAST && x == 0) { placeBlock = false; - } else if (getDirection() == Direction.WEST && i == this.sizeX) { + } else if (getDirection() == Direction.WEST && x == this.sizeX) { placeBlock = false; } } } if (placeBlock) { - this.placeBlock(worldIn, this.configuration.getBrickBlock(), i, j, k, chunkBox); + this.placeBlock(worldIn, this.configuration.getBrickBlock(), x, y, z, chunkBox); } else { - this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), i, j, k, chunkBox); + this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), x, y, z, chunkBox); } - } else if ((i == 1 && k == 1) || (i == 1 && k == this.sizeZ - 1) || (i == this.sizeX - 1 && k == 1) || (i == this.sizeX - 1 && k == this.sizeZ - 1)) { - this.placeBlock(worldIn, Blocks.LAVA.defaultBlockState(), i, j, k, chunkBox); - } else if (j % 3 == 0 && j >= 2 && ((i == 1 || i == this.sizeX - 1 || k == 1 || k == this.sizeZ - 1) || (i == 2 && k == 2) || (i == 2 && k == this.sizeZ - 2) || (i == this.sizeX - 2 && k == 2) || (i == this.sizeX - 2 && k == this.sizeZ - 2))) { + } else if ((x == 1 && z == 1) || (x == 1 && z == this.sizeZ - 1) || (x == this.sizeX - 1 && z == 1) || (x == this.sizeX - 1 && z == this.sizeZ - 1)) { + this.placeBlock(worldIn, Blocks.LAVA.defaultBlockState(), x, y, z, chunkBox); + } else if (y % 3 == 0 && y >= 2 && ((x == 1 || x == this.sizeX - 1 || z == 1 || z == this.sizeZ - 1) || (x == 2 && z == 2) || (x == 2 && z == this.sizeZ - 2) || (x == this.sizeX - 2 && z == 2) || (x == this.sizeX - 2 && z == this.sizeZ - 2))) { // Horizontal bars - this.placeBlock(worldIn, Blocks.IRON_BARS.defaultBlockState(), i, j, k, chunkBox); - } else if ((i == 1 && k == 2) || (i == 2 && k == 1) || - (i == 1 && k == this.sizeZ - 2) || (i == 2 && k == this.sizeZ - 1) || - (i == this.sizeX - 1 && k == 2) || (i == this.sizeX - 2 && k == 1) || - (i == this.sizeX - 1 && k == this.sizeZ - 2) || (i == this.sizeX - 2 && k == this.sizeZ - 1)) { + this.placeBlock(worldIn, Blocks.IRON_BARS.defaultBlockState(), x, y, z, chunkBox); + } else if ((x == 1 && z == 2) || (x == 2 && z == 1) || + (x == 1 && z == this.sizeZ - 2) || (x == 2 && z == this.sizeZ - 1) || + (x == this.sizeX - 1 && z == 2) || (x == this.sizeX - 2 && z == 1) || + (x == this.sizeX - 1 && z == this.sizeZ - 2) || (x == this.sizeX - 2 && z == this.sizeZ - 1)) { // Vertical bars - this.placeBlock(worldIn, Blocks.IRON_BARS.defaultBlockState(), i, j, k, chunkBox); + this.placeBlock(worldIn, Blocks.IRON_BARS.defaultBlockState(), x, y, z, chunkBox); } else { - this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), i, j, k, chunkBox); + this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), x, y, z, chunkBox); } } } diff --git a/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomEmpty.java b/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomEmpty.java index 1fc666d9d..964452306 100644 --- a/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomEmpty.java +++ b/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomEmpty.java @@ -58,39 +58,39 @@ public RoomEmpty(DungeonConfiguration configuration, RandomSource rand, int bloc @Override public void postProcess(WorldGenLevel worldIn, StructureManager structureManager, ChunkGenerator generator, RandomSource random, BoundingBox boundingBox, ChunkPos pos, BlockPos pivot) { - for (int i = 0; i <= this.sizeX; i++) { - for (int j = 0; j <= this.sizeY; j++) { - for (int k = 0; k <= this.sizeZ; k++) { - if (i == 0 || i == this.sizeX || j == 0 || j == this.sizeY || k == 0 || k == this.sizeZ) { + for (int x = 0; x <= this.sizeX; x++) { + for (int y = 0; y <= this.sizeY; y++) { + for (int z = 0; z <= this.sizeZ; z++) { + if (x == 0 || x == this.sizeX || y == 0 || y == this.sizeY || z == 0 || z == this.sizeZ) { boolean placeBlock = true; if (getDirection().getAxis() == Direction.Axis.Z) { int start = (this.boundingBox.maxX() - this.boundingBox.minX()) / 2 - 1; int end = (this.boundingBox.maxX() - this.boundingBox.minX()) / 2 + 1; - if (i > start && i <= end && j < this.configuration.getHallwayHeight() && j > 0) { - if (getDirection() == Direction.SOUTH && k == 0) { + if (x > start && x <= end && y < this.configuration.getHallwayHeight() && y > 0) { + if (getDirection() == Direction.SOUTH && z == 0) { placeBlock = false; - } else if (getDirection() == Direction.NORTH && k == this.sizeZ) { + } else if (getDirection() == Direction.NORTH && z == this.sizeZ) { placeBlock = false; } } } else { int start = (this.boundingBox.maxZ() - this.boundingBox.minZ()) / 2 - 1; int end = (this.boundingBox.maxZ() - this.boundingBox.minZ()) / 2 + 1; - if (k > start && k <= end && j < this.configuration.getHallwayHeight() && j > 0) { - if (getDirection() == Direction.EAST && i == 0) { + if (z > start && z <= end && y < this.configuration.getHallwayHeight() && y > 0) { + if (getDirection() == Direction.EAST && x == 0) { placeBlock = false; - } else if (getDirection() == Direction.WEST && i == this.sizeX) { + } else if (getDirection() == Direction.WEST && x == this.sizeX) { placeBlock = false; } } } if (placeBlock) { - this.placeBlock(worldIn, this.configuration.getBrickBlock(), i, j, k, boundingBox); + this.placeBlock(worldIn, this.configuration.getBrickBlock(), x, y, z, boundingBox); } else { - this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), i, j, k, boundingBox); + this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), x, y, z, boundingBox); } } else { - this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), i, j, k, boundingBox); + this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), x, y, z, boundingBox); } } } diff --git a/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomEntrance.java b/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomEntrance.java index 230e3f66f..e47bb5cb1 100644 --- a/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomEntrance.java +++ b/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomEntrance.java @@ -50,13 +50,13 @@ public RoomEntrance(DungeonConfiguration configuration, RandomSource rand, int b @Override public void postProcess(WorldGenLevel worldIn, StructureManager structureManager, ChunkGenerator chunkGenerator, RandomSource randomIn, BoundingBox structureBoundingBoxIn, ChunkPos pos, BlockPos pivot) { - for (int i = 0; i <= this.sizeX; i++) { - for (int j = 0; j <= this.sizeY; j++) { - for (int k = 0; k <= this.sizeZ; k++) { - if (i == 0 || i == this.sizeX || j == 0 /*|| j == this.sizeY*/ || k == 0 || k == this.sizeZ) { - this.placeBlock(worldIn, this.configuration.getBrickBlock(), i, j, k, boundingBox); + for (int x = 0; x <= this.sizeX; x++) { + for (int y = 0; y <= this.sizeY; y++) { + for (int z = 0; z <= this.sizeZ; z++) { + if (x == 0 || x == this.sizeX || y == 0 /*|| j == this.sizeY*/ || z == 0 || z == this.sizeZ) { + this.placeBlock(worldIn, this.configuration.getBrickBlock(), x, y, z, boundingBox); } else { - this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), i, j, k, boundingBox); + this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), x, y, z, boundingBox); } } } diff --git a/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomTreasure.java b/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomTreasure.java index 0194df248..94dbbf832 100644 --- a/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomTreasure.java +++ b/src/main/java/dev/galacticraft/mod/structure/dungeon/RoomTreasure.java @@ -32,16 +32,12 @@ import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.StructureManager; import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.StructurePiece; -import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType; import net.minecraft.world.level.storage.loot.BuiltInLootTables; -import java.util.Random; - public class RoomTreasure extends SizedPiece { public static ResourceLocation MOONCHEST = Constant.id("dungeon_tier_1"); @@ -62,41 +58,41 @@ public RoomTreasure(DungeonConfiguration configuration, RandomSource rand, int b @Override public void postProcess(WorldGenLevel worldIn, StructureManager structureManager, ChunkGenerator generator, RandomSource random, BoundingBox chunkBox, ChunkPos pos, BlockPos pivot) { - for (int i = 0; i <= this.sizeX; i++) { - for (int j = 0; j <= this.sizeY; j++) { - for (int k = 0; k <= this.sizeZ; k++) { - if (i == 0 || i == this.sizeX || j == 0 || j == this.sizeY || k == 0 || k == this.sizeZ) { + for (int x = 0; x <= this.sizeX; x++) { + for (int y = 0; y <= this.sizeY; y++) { + for (int z = 0; z <= this.sizeZ; z++) { + if (x == 0 || x == this.sizeX || y == 0 || y == this.sizeY || z == 0 || z == this.sizeZ) { boolean placeBlock = true; if (getDirection().getAxis() == Direction.Axis.Z) { int start = (this.boundingBox.maxX() - this.boundingBox.minX()) / 2 - 1; int end = (this.boundingBox.maxX() - this.boundingBox.minX()) / 2 + 1; - if (i > start && i <= end && j < 3 && j > 0) { - if (getDirection() == Direction.SOUTH && k == 0) { + if (x > start && x <= end && y < 3 && y > 0) { + if (getDirection() == Direction.SOUTH && z == 0) { placeBlock = false; - } else if (getDirection() == Direction.NORTH && k == this.sizeZ) { + } else if (getDirection() == Direction.NORTH && z == this.sizeZ) { placeBlock = false; } } } else { int start = (this.boundingBox.maxZ() - this.boundingBox.minZ()) / 2 - 1; int end = (this.boundingBox.maxZ() - this.boundingBox.minZ()) / 2 + 1; - if (k > start && k <= end && j < 3 && j > 0) { - if (getDirection() == Direction.EAST && i == 0) { + if (z > start && z <= end && y < 3 && y > 0) { + if (getDirection() == Direction.EAST && x == 0) { placeBlock = false; - } else if (getDirection() == Direction.WEST && i == this.sizeX) { + } else if (getDirection() == Direction.WEST && x == this.sizeX) { placeBlock = false; } } } if (placeBlock) { - this.placeBlock(worldIn, this.configuration.getBrickBlock(), i, j, k, chunkBox); + this.placeBlock(worldIn, this.configuration.getBrickBlock(), x, y, z, chunkBox); } else { - this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), i, j, k, chunkBox); + this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), x, y, z, chunkBox); } - } else if ((i == 1 && k == 1) || (i == 1 && k == this.sizeZ - 1) || (i == this.sizeX - 1 && k == 1) || (i == this.sizeX - 1 && k == this.sizeZ - 1)) { - this.placeBlock(worldIn, Blocks.GLOWSTONE.defaultBlockState(), i, j, k, chunkBox); - } else if (i == this.sizeX / 2 && j == 1 && k == this.sizeZ / 2) { - BlockPos blockpos = new BlockPos(this.getWorldX(i, k), this.getWorldY(j), this.getWorldZ(i, k)); + } else if ((x == 1 && z == 1) || (x == 1 && z == this.sizeZ - 1) || (x == this.sizeX - 1 && z == 1) || (x == this.sizeX - 1 && z == this.sizeZ - 1)) { + this.placeBlock(worldIn, Blocks.GLOWSTONE.defaultBlockState(), x, y, z, chunkBox); + } else if (x == this.sizeX / 2 && y == 1 && z == this.sizeZ / 2) { + BlockPos blockpos = new BlockPos(this.getWorldX(x, z), this.getWorldY(y), this.getWorldZ(x, z)); if (chunkBox.isInside(blockpos)) { // worldIn.setBlock(blockpos, GCBlocks.treasureChestTier1.getDefaultState().withProperty(BlockTier1TreasureChest.FACING, this.getDirection().getOpposite()), Block.UPDATE_CLIENTS); // TileEntityTreasureChest treasureChest = (TileEntityTreasureChest) worldIn.getTileEntity(blockpos); @@ -109,7 +105,7 @@ public void postProcess(WorldGenLevel worldIn, StructureManager structureManager // } } } else { - this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), i, j, k, chunkBox); + this.placeBlock(worldIn, Blocks.AIR.defaultBlockState(), x, y, z, chunkBox); } } } diff --git a/src/main/java/dev/galacticraft/mod/util/Translations.java b/src/main/java/dev/galacticraft/mod/util/Translations.java index e4caf729e..16997a550 100644 --- a/src/main/java/dev/galacticraft/mod/util/Translations.java +++ b/src/main/java/dev/galacticraft/mod/util/Translations.java @@ -54,15 +54,8 @@ interface SetOxygen { String EMPTY_OXYGEN = "commands.galacticraft.oxygen.get.area.none"; } - interface OpenCelestialScreen { - String REQUIRES_PLAYER = "commands.galacticraft.opencelestialscreen.requires_player"; - } - interface DimensionTp { - String ALREADY_IN_DIMENSION = "commands.galacticraft.dimensiontp.failure.already_in_dimension"; - String UNKNOWN_ENTITY = "commands.galacticraft.dimensiontp.failure.entity"; String SUCCESS_MULTIPLE = "commands.galacticraft.dimensiontp.success.multiple"; - String SUCCESS_POSITION = "commands.galacticraft.dimensiontp.success.pos"; String SUCCESS_SINGLE = "commands.galacticraft.dimensiontp.success.single"; } @@ -71,7 +64,6 @@ interface GcHouston { String CONFIRMATION = "commands.galacticraft.gchouston.confirm"; String IN_OVERWORLD = "commands.galacticraft.gchouston.on_earth_already"; String SUCCESS = "commands.galacticraft.gchouston.success"; - String MISSING_PLAYER = "commands.galacticraft.require_player"; } interface Config { @@ -109,6 +101,9 @@ interface Config { String BOSS_HEALTH_MODIFIER = "config.galacticraft.difficulty.dungeon_boss_health_multiplier"; String BOSS_HEALTH_MODIFIER_DESC = "config.galacticraft.difficulty.dungeon_boss_health_multiplier.desc"; String SKYBOX = "config.galacticraft.client.skybox"; + + String COMMANDS = "config.galacticraft.commands"; + String ENABLE_GC_HOUSTON = "config.galacticraft.commands.enable_gc_houston"; } interface Galaxy { @@ -118,6 +113,7 @@ interface Galaxy { interface Keybindings { String ROCKET_INVENTORY = "key.galacticraft.rocket.inventory"; + String OPEN_CELESTIAL_SCREEN = "key.galacticraft.open_celestial_screen"; } interface CelestialBody {