diff --git a/core-api/src/main/java/dev/compactmods/machines/api/Constants.java b/core-api/src/main/java/dev/compactmods/machines/api/Constants.java index f0125d9..7c507e4 100644 --- a/core-api/src/main/java/dev/compactmods/machines/api/Constants.java +++ b/core-api/src/main/java/dev/compactmods/machines/api/Constants.java @@ -1,6 +1,11 @@ package dev.compactmods.machines.api; +import net.minecraft.resources.ResourceLocation; + public interface Constants { String MOD_ID = "compactmachines"; + static ResourceLocation modRL(String path) { + return new ResourceLocation(MOD_ID, path); + } } diff --git a/core-api/src/main/java/dev/compactmods/machines/api/Messages.java b/core-api/src/main/java/dev/compactmods/machines/api/Messages.java deleted file mode 100644 index 1c8973c..0000000 --- a/core-api/src/main/java/dev/compactmods/machines/api/Messages.java +++ /dev/null @@ -1,42 +0,0 @@ -package dev.compactmods.machines.api; - -import net.minecraft.resources.ResourceLocation; - -public interface Messages { - ResourceLocation CANNOT_ENTER_MACHINE = new ResourceLocation(Constants.MOD_ID, "cannot_enter"); - ResourceLocation NO_MACHINE_DATA = new ResourceLocation(Constants.MOD_ID, "no_machine_data"); - ResourceLocation ROOM_SPAWNPOINT_SET = new ResourceLocation(Constants.MOD_ID, "spawnpoint_set"); - ResourceLocation TELEPORT_OUT_OF_BOUNDS = new ResourceLocation(Constants.MOD_ID, "teleport_oob"); - ResourceLocation HOW_DID_YOU_GET_HERE = new ResourceLocation(Constants.MOD_ID, "how_did_you_get_here"); - ResourceLocation UNKNOWN_TUNNEL = new ResourceLocation(Constants.MOD_ID, "unknown_tunnel_type"); - ResourceLocation NO_TUNNEL_SIDE = new ResourceLocation(Constants.MOD_ID, "no_available_sides"); - ResourceLocation UNKNOWN_ROOM_CHUNK = new ResourceLocation(Constants.MOD_ID, "unknown_room_chunk"); - ResourceLocation UNREGISTERED_CM_DIM = new ResourceLocation(Constants.MOD_ID, "dimension_not_registered"); - ResourceLocation NEW_MACHINE = new ResourceLocation(Constants.MOD_ID, "new_machine"); - - /** - * Used to show information about a player inside a Compact room. - */ - ResourceLocation PLAYER_ROOM_INFO = new ResourceLocation(Constants.MOD_ID, "player_room_info"); - - /** - * Used to show information about a room, accessed via a bound machine. - */ - ResourceLocation MACHINE_ROOM_INFO = new ResourceLocation(Constants.MOD_ID, "machine_room_info"); - - /** - * Shown when a non-owner tries to rename a room. Takes the owner's display name. - */ - ResourceLocation CANNOT_RENAME_NOT_OWNER = new ResourceLocation(Constants.MOD_ID, "cannot_rename_not_owner"); - - /** - * Shown to players when they try to interact with a room they do not own. Provides the owner's display name. - */ - ResourceLocation NOT_ROOM_OWNER = new ResourceLocation(Constants.MOD_ID, "not_the_room_owner"); - ResourceLocation UPGRADE_APPLIED = new ResourceLocation(Constants.MOD_ID, "upgrade_applied"); - ResourceLocation UPGRADE_ADD_FAILED = new ResourceLocation(Constants.MOD_ID, "upgrade_add_failed"); - ResourceLocation UPGRADE_REMOVED = new ResourceLocation(Constants.MOD_ID, "upgrade_removed"); - ResourceLocation UPGRADE_REM_FAILED = new ResourceLocation(Constants.MOD_ID, "upgrade_remove_failed"); - ResourceLocation ALREADY_HAS_UPGRADE = new ResourceLocation(Constants.MOD_ID, "upgrade_already_present"); - ResourceLocation UPGRADE_NOT_PRESENT = new ResourceLocation(Constants.MOD_ID, "upgrade_not_present"); -} diff --git a/core-api/src/main/java/dev/compactmods/machines/api/Tooltips.java b/core-api/src/main/java/dev/compactmods/machines/api/Tooltips.java deleted file mode 100644 index 899fa3f..0000000 --- a/core-api/src/main/java/dev/compactmods/machines/api/Tooltips.java +++ /dev/null @@ -1,31 +0,0 @@ -package dev.compactmods.machines.api; - -import net.minecraft.resources.ResourceLocation; - -public interface Tooltips { - - ResourceLocation UNKNOWN_PLAYER_NAME = new ResourceLocation(Constants.MOD_ID, "unknown_player"); - ResourceLocation TUNNEL_TYPE = new ResourceLocation(Constants.MOD_ID, "tunnel_type"); - ResourceLocation UNKNOWN_TUNNEL_TYPE = new ResourceLocation(Constants.MOD_ID, "unknown_tunnel_type"); - ResourceLocation ROOM_NAME = new ResourceLocation(Constants.MOD_ID, "room_name"); - ResourceLocation ROOM_UPGRADE_TYPE = new ResourceLocation(Constants.MOD_ID, "room_upgrade_type"); - ResourceLocation TUTORIAL_APPLY_ROOM_UPGRADE = new ResourceLocation(Constants.MOD_ID, "tutorial_apply_room_upgrade"); - ResourceLocation CRAFT_TO_UPGRADE = new ResourceLocation(Constants.MOD_ID, "craft_machine_to_upgrade"); - ResourceLocation NOT_YET_IMPLEMENTED = new ResourceLocation(Constants.MOD_ID, "not_yet_implemented"); - - interface Machines { - ResourceLocation ID = new ResourceLocation(Constants.MOD_ID, "machine.id"); - ResourceLocation OWNER = new ResourceLocation(Constants.MOD_ID, "machine.owner"); - ResourceLocation SIZE = new ResourceLocation(Constants.MOD_ID, "machine.size"); - ResourceLocation BOUND_TO = new ResourceLocation(Constants.MOD_ID, "machine.bound_to"); - } - - //#region Hints and Details - ResourceLocation HINT_HOLD_SHIFT = new ResourceLocation(Constants.MOD_ID, "hint.hold_shift"); - - interface Details { - ResourceLocation PERSONAL_SHRINKING_DEVICE = new ResourceLocation(Constants.MOD_ID, "details.psd"); - ResourceLocation SOLID_WALL = new ResourceLocation(Constants.MOD_ID, "details.solid_wall"); - } - //#endregion -} diff --git a/core-api/src/main/java/dev/compactmods/machines/api/Translations.java b/core-api/src/main/java/dev/compactmods/machines/api/Translations.java new file mode 100644 index 0000000..fabc852 --- /dev/null +++ b/core-api/src/main/java/dev/compactmods/machines/api/Translations.java @@ -0,0 +1,35 @@ +package dev.compactmods.machines.api; + +import net.minecraft.ChatFormatting; +import net.minecraft.Util; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.AABB; + +import java.util.function.Function; +import java.util.function.Supplier; + +import static dev.compactmods.machines.api.Constants.MOD_ID; + +public interface Translations { + + Supplier HINT_HOLD_SHIFT = () -> Component.translatableWithFallback(IDs.HINT_HOLD_SHIFT, "Hold shift for details.") + .withStyle(ChatFormatting.DARK_GRAY) + .withStyle(ChatFormatting.ITALIC); + + Supplier UNBREAKABLE_BLOCK = () -> Component.translatableWithFallback(IDs.UNBREAKABLE_BLOCK, "Warning! Unbreakable for non-creative players!") + .withStyle(ChatFormatting.DARK_RED); + + Supplier TELEPORT_OUT_OF_BOUNDS = () -> Component + .translatableWithFallback(IDs.TELEPORT_OUT_OF_BOUNDS, "An otherworldly force prevents your teleportation.") + .withStyle(ChatFormatting.DARK_RED) + .withStyle(ChatFormatting.ITALIC); + + interface IDs { + String TELEPORT_OUT_OF_BOUNDS = Util.makeDescriptionId("messages", Constants.modRL("teleport_oob")); + String HOW_DID_YOU_GET_HERE = Util.makeDescriptionId("messages", Constants.modRL("how_did_you_get_here")); + String HINT_HOLD_SHIFT = Util.makeDescriptionId("messages", Constants.modRL("hint.hold_shift")); + String UNBREAKABLE_BLOCK = Util.makeDescriptionId("messages", Constants.modRL("solid_wall")); + } +} diff --git a/core-api/src/main/java/dev/compactmods/machines/api/command/CMCommands.java b/core-api/src/main/java/dev/compactmods/machines/api/command/CMCommands.java deleted file mode 100644 index 5cd52bb..0000000 --- a/core-api/src/main/java/dev/compactmods/machines/api/command/CMCommands.java +++ /dev/null @@ -1,38 +0,0 @@ -package dev.compactmods.machines.api.command; - -import net.minecraft.resources.ResourceLocation; - -import static dev.compactmods.machines.api.Constants.MOD_ID; - -public interface CMCommands { - ResourceLocation LEVEL_REGISTERED = new ResourceLocation(MOD_ID, "level_registered"); - ResourceLocation LEVEL_NOT_FOUND = new ResourceLocation(MOD_ID, "level_not_found"); - - ResourceLocation ROOM_NOT_FOUND = new ResourceLocation(MOD_ID, "room_not_found"); - - /** - * Used for displaying the number of registered machines via summary commands. - */ - ResourceLocation MACHINE_REG_DIM = new ResourceLocation(MOD_ID, "summary.machines.dimension"); - ResourceLocation MACHINE_REG_TOTAL = new ResourceLocation(MOD_ID, "summary.machines.total"); - - /** - * Used for displaying the number of registered rooms via summary commands. - */ - ResourceLocation ROOM_REG_COUNT = new ResourceLocation(MOD_ID, "room_reg_count"); - ResourceLocation NOT_A_MACHINE_BLOCK = new ResourceLocation(MOD_ID, "not_a_machine_block"); - - /** - * Shows a machine is not bound. Takes in a single param, the machine position in world. - */ - ResourceLocation MACHINE_NOT_BOUND = new ResourceLocation(MOD_ID, "machine_not_bound"); - - ResourceLocation WRONG_DIMENSION = new ResourceLocation(MOD_ID, "not_in_compact_dimension"); - ResourceLocation NOT_IN_COMPACT_DIMENSION = new ResourceLocation(MOD_ID, "not_in_compact_dim"); - ResourceLocation FAILED_CMD_FILE_ERROR = new ResourceLocation(MOD_ID, "failed_command_file_error"); - - ResourceLocation CANNOT_GIVE_MACHINE = new ResourceLocation(MOD_ID, "cannot_give_machine_item"); - ResourceLocation MACHINE_GIVEN = new ResourceLocation(MOD_ID, "machine_given_successfully"); - ResourceLocation NO_REBIND_TUNNEL_PRESENT = new ResourceLocation(MOD_ID, "cannot_rebind_tunnel_present"); - ResourceLocation SPAWN_CHANGED_SUCCESSFULLY = new ResourceLocation(MOD_ID, "spawn_changed_successfully"); -} diff --git a/core-api/src/main/java/dev/compactmods/machines/api/command/CommandTranslations.java b/core-api/src/main/java/dev/compactmods/machines/api/command/CommandTranslations.java new file mode 100644 index 0000000..eca2ab8 --- /dev/null +++ b/core-api/src/main/java/dev/compactmods/machines/api/command/CommandTranslations.java @@ -0,0 +1,33 @@ +package dev.compactmods.machines.api.command; + +import dev.compactmods.machines.api.Constants; +import net.minecraft.Util; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; + +import java.util.function.Function; +import java.util.function.Supplier; + +import static dev.compactmods.machines.api.Constants.MOD_ID; + +public interface CommandTranslations { + + Supplier CANNOT_GIVE_MACHINE = () -> Component.translatableWithFallback(IDs.CANNOT_GIVE_MACHINE, "Cannot give machine."); + + Function MACHINE_GIVEN = (player) -> Component + .translatableWithFallback(IDs.MACHINE_GIVEN, "Created a new machine item and gave it to %s.", player.getDisplayName()); + + interface IDs { + String CANNOT_GIVE_MACHINE = Util.makeDescriptionId("commands.machines", Constants.modRL("cannot_give_machine_item")); + + String MACHINE_GIVEN = Util.makeDescriptionId("commands.machines", Constants.modRL("machine_given_successfully")); + + /** + * Used for displaying the number of registered rooms via summary commands. + */ + String ROOM_COUNT = Util.makeDescriptionId("commands.rooms", new ResourceLocation(MOD_ID, "room_reg_count")); + + String SPAWN_CHANGED_SUCCESSFULLY = Util.makeDescriptionId("commands.rooms", new ResourceLocation(MOD_ID, "spawn_changed_successfully")); + } +} diff --git a/core-api/src/main/java/dev/compactmods/machines/api/machine/MachineTranslations.java b/core-api/src/main/java/dev/compactmods/machines/api/machine/MachineTranslations.java new file mode 100644 index 0000000..9e6e9d7 --- /dev/null +++ b/core-api/src/main/java/dev/compactmods/machines/api/machine/MachineTranslations.java @@ -0,0 +1,24 @@ +package dev.compactmods.machines.api.machine; + +import dev.compactmods.machines.api.Constants; +import net.minecraft.Util; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.BlockParticleOption; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import org.apache.commons.lang3.function.TriFunction; + +import java.util.function.Function; +import java.util.function.Supplier; + +public interface MachineTranslations { + + Function NOT_A_MACHINE_BLOCK = (pos) -> Component.empty(); + + interface IDs { + String OWNER = Util.makeDescriptionId("machine", Constants.modRL("machine.owner")); + String SIZE = Util.makeDescriptionId("machine", Constants.modRL("machine.size")); + String BOUND_TO = Util.makeDescriptionId("machine", Constants.modRL("machine.bound_to")); + String NEW_MACHINE = Util.makeDescriptionId("machine", Constants.modRL("new_machine")); + } +} diff --git a/core/src/main/java/dev/compactmods/machines/i18n/TranslationUtil.java b/core/src/main/java/dev/compactmods/machines/i18n/TranslationUtil.java deleted file mode 100644 index fd41b1e..0000000 --- a/core/src/main/java/dev/compactmods/machines/i18n/TranslationUtil.java +++ /dev/null @@ -1,69 +0,0 @@ -package dev.compactmods.machines.i18n; - -import net.minecraft.Util; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; - -public abstract class TranslationUtil { - - public static String messageId(ResourceLocation message) { - return Util.makeDescriptionId("message", message); - } - - public static MutableComponent message(ResourceLocation message) { - return Component.translatable(messageId(message)); - } - - public static MutableComponent message(ResourceLocation message, Object... params) { - return Component.translatable(messageId(message), params); - } - - public static String tooltipId(ResourceLocation tooltip) { - return Util.makeDescriptionId("tooltip", tooltip); - } - - public static MutableComponent tooltip(ResourceLocation tooltip) { - return Component.translatable(tooltipId(tooltip)); - } - - public static MutableComponent tooltip(ResourceLocation tooltip, Object... params) { - return Component.translatable(tooltipId(tooltip), params); - } - - public static String advId(ResourceLocation tooltip) { - return Util.makeDescriptionId("advancement", tooltip); - } - - public static MutableComponent advancement(ResourceLocation advancement) { - return Component.translatable(advId(advancement)); - } - - public static MutableComponent advancementTitle(ResourceLocation advancement) { - return advancement(advancement); - } - - public static MutableComponent advancementDesc(ResourceLocation advancement) { - return Component.translatable(Util.makeDescriptionId("advancement", advancement) + ".desc"); - } - - public static MutableComponent jeiInfo(ResourceLocation jei) { - return Component.translatable(Util.makeDescriptionId("jei", jei)); - } - - public static String commandId(ResourceLocation s) { - return Util.makeDescriptionId("command", s); - } - - public static MutableComponent command(ResourceLocation s) { - return Component.translatable(commandId(s)); - } - - public static MutableComponent command(ResourceLocation s, Object... params) { - return Component.translatable(commandId(s), params); - } - - public static String tunnelId(ResourceLocation id) { - return "item." + id.getNamespace() + ".tunnels." + id.getPath().replace('/', '.'); - } -} diff --git a/core/src/main/java/dev/compactmods/machines/room/spawn/SpawnManager.java b/core/src/main/java/dev/compactmods/machines/room/spawn/SpawnManager.java index 19a7067..b79a489 100644 --- a/core/src/main/java/dev/compactmods/machines/room/spawn/SpawnManager.java +++ b/core/src/main/java/dev/compactmods/machines/room/spawn/SpawnManager.java @@ -96,11 +96,7 @@ public void setPlayerSpawn(UUID player, Vec3 location, Vec2 rotation) { if(!roomBounds.contains(location)) return; - if (playerSpawns.containsKey(player)) - playerSpawns.replace(player, new RoomSpawn(location, rotation)); - else - playerSpawns.put(player, new RoomSpawn(location, rotation)); - + playerSpawns.put(player, new RoomSpawn(location, rotation)); this.setDirty(); } diff --git a/core/src/main/java/dev/compactmods/machines/wall/ItemBlockWall.java b/core/src/main/java/dev/compactmods/machines/wall/ItemBlockWall.java index 34fd2b1..4bc25b7 100644 --- a/core/src/main/java/dev/compactmods/machines/wall/ItemBlockWall.java +++ b/core/src/main/java/dev/compactmods/machines/wall/ItemBlockWall.java @@ -1,8 +1,7 @@ package dev.compactmods.machines.wall; -import dev.compactmods.machines.api.Tooltips; +import dev.compactmods.machines.api.Translations; import dev.compactmods.machines.api.WallConstants; -import dev.compactmods.machines.i18n.TranslationUtil; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; @@ -27,18 +26,8 @@ public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List PLAYER_ROOM_INFO = (player, roomCode) -> + Component.translatableWithFallback(IDs.PLAYER_ROOM_INFO, "%1$s is inside room '%2$s'.", + player.getDisplayName(), roomCode); + + Function PLAYER_NOT_IN_COMPACT_DIM = (player) -> Component.translatableWithFallback(IDs.Errors.PLAYER_NOT_IN_COMPACT_DIM, "", player.getDisplayName()); + + Function UNKNOWN_ROOM_BY_PLAYER_CHUNK = (player) -> Component.translatableWithFallback(IDs.Errors.UNKNOWN_ROOM_BY_PLAYER_CHUNK, "Room not found at chunk: %s", player.chunkPosition()) + .withStyle(ChatFormatting.DARK_RED); + + Function UNKNOWN_ROOM_BY_CODE = (roomCode) -> Component.translatableWithFallback(IDs.Errors.UNKNOWN_ROOM_BY_CODE, "Room not found: %s", roomCode); + + BiFunction MACHINE_ROOM_INFO = (machinePos, info) -> Component.translatableWithFallback(IDs.MACHINE_ROOM_INFO, + "Machine at %1$s is bound to a %2$s size room at %3$s", + machinePos.toShortString(), AABBHelper.toString(info.boundaries().innerBounds()), info.boundaries().innerBounds().getCenter()); + + Function CANNOT_RENAME_NOT_OWNER = (owner) -> Component + .translatableWithFallback(IDs.Errors.CANNOT_RENAME_NOT_OWNER, "You are not the room owner; only %s may make changes.", owner.getName()); + + PlayerAndRoomCodeFunction ROOM_SPAWNPOINT_SET = (player, roomCode) -> Component + .translatableWithFallback(IDs.ROOM_SPAWNPOINT_SET, "Room spawn for %s updated.", player.getDisplayName()) + .withStyle(ChatFormatting.GREEN); + + interface IDs { + String ROOM_SPAWNPOINT_SET = Util.makeDescriptionId("rooms", Constants.modRL("spawnpoint_set")); + + String PLAYER_ROOM_INFO = Util.makeDescriptionId("rooms", Constants.modRL("player_room_info")); + + String MACHINE_ROOM_INFO = Util.makeDescriptionId("machine", Constants.modRL("machine_room_info")); + + interface Errors { + String UNKNOWN_ROOM_BY_CODE = Util.makeDescriptionId("rooms.errors", Constants.modRL("room_not_found")); + + String CANNOT_ENTER_ROOM = Util.makeDescriptionId("rooms.errors", Constants.modRL("cannot_enter")); + + String UNKNOWN_ROOM_BY_PLAYER_CHUNK = Util.makeDescriptionId("rooms.errors", Constants.modRL("unknown_room_chunk")); + + String PLAYER_NOT_IN_COMPACT_DIM = Util.makeDescriptionId("rooms.errors", Constants.modRL("player_not_in_compact_dimension")); + } + } +} diff --git a/room-api/src/main/java/dev/compactmods/machines/api/room/function/PlayerAndRoomCodeFunction.java b/room-api/src/main/java/dev/compactmods/machines/api/room/function/PlayerAndRoomCodeFunction.java new file mode 100644 index 0000000..d7d92c7 --- /dev/null +++ b/room-api/src/main/java/dev/compactmods/machines/api/room/function/PlayerAndRoomCodeFunction.java @@ -0,0 +1,9 @@ +package dev.compactmods.machines.api.room.function; + +import net.minecraft.world.entity.player.Player; + +@FunctionalInterface +public interface PlayerAndRoomCodeFunction { + + T apply(Player player, String roomCode); +} diff --git a/room-api/src/main/java/dev/compactmods/machines/api/room/spawn/IRoomSpawnManager.java b/room-api/src/main/java/dev/compactmods/machines/api/room/spawn/IRoomSpawnManager.java index fbaba25..ce9a908 100644 --- a/room-api/src/main/java/dev/compactmods/machines/api/room/spawn/IRoomSpawnManager.java +++ b/room-api/src/main/java/dev/compactmods/machines/api/room/spawn/IRoomSpawnManager.java @@ -1,5 +1,6 @@ package dev.compactmods.machines.api.room.spawn; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; @@ -7,6 +8,10 @@ public interface IRoomSpawnManager { + default void setPlayerSpawn(ServerPlayer player) { + setPlayerSpawn(player.getUUID(), player.position(), player.getRotationVector()); + } + void setPlayerSpawn(UUID player, Vec3 location, Vec2 rotation); void resetPlayerSpawn(UUID player);