From f65da2e5ce2e9c20465d49fcea934d2ba603fc08 Mon Sep 17 00:00:00 2001 From: 50ap5ud5 <50ap5ud5125@gmail.com> Date: Sun, 24 Dec 2023 02:53:13 +1100 Subject: [PATCH] Started Teleport enchancements and many fixes -Waypoint translation entries -Internal Door blocks not using proper inheritance and having dummy entries actually registered as a result --- .../api/event/TardisEvents.java | 39 ++- .../door/RootShellDoorRenderer.java | 2 +- .../waypoints/WaypointManageScreen.java | 28 +-- .../command/sub/CreateCommand.java | 6 +- .../command/sub/InteriorCommand.java | 2 +- .../command/sub/LevelCommand.java | 33 +-- .../command/sub/UpgradesCommand.java | 12 +- .../common/block/door/GlobalDoorBlock.java | 15 +- .../common/block/door/InternalDoorBlock.java | 42 ++-- .../common/block/door/RootShellDoorBlock.java | 21 +- .../common/block/shell/ShellBaseBlock.java | 4 +- .../desktop/InternalDoorBlockEntity.java | 37 --- .../door/RootShellDoorBlockEntity.java | 34 --- ...Door.java => AbstractDoorBlockEntity.java} | 30 ++- .../door/GlobalDoorBlockEntity.java | 17 +- .../door/InternalDoorBlockEntity.java | 13 + .../door/RootShellDoorBlockEntity.java | 19 ++ .../blockentity/door/TardisInternalDoor.java | 3 + .../shell/GlobalShellBlockEntity.java | 1 + .../shell/ShellBaseBlockEntity.java | 36 ++- .../capability/TardisLevelOperator.java | 100 ++++---- .../common/dimension/DelayedTeleportData.java | 83 ------- .../common/dimension/TardisTeleportData.java | 162 +++++++++++++ .../common/tardis/ExteriorShell.java | 6 + .../tardis/manager/TardisExteriorManager.java | 4 +- .../manager/TardisFlightEventManager.java | 69 +++++- .../tardis/manager/TardisInteriorManager.java | 7 +- .../tardis/manager/TardisPilotingManager.java | 14 +- .../tardis/manager/TardisWaypointManager.java | 8 + .../common/util/LevelHelper.java | 19 ++ .../common/util/MiscHelper.java | 2 +- .../common/util/TRTeleporter.java | 222 ++++++++++++++---- .../common/util/TardisHelper.java | 66 +++++- .../tardis_refined/constants/ModMessages.java | 15 +- .../registry/BlockEntityRegistry.java | 6 +- .../registry/BlockRegistry.java | 3 +- .../tardis_refined/registry/TagKeys.java | 7 + .../fabric/TardisLevelOperatorDummy.java | 17 ++ .../fabric/TardisLevelOperatorImpl.java | 3 + .../fabric/events/ModEvents.java | 4 +- .../assets/tardis_refined/lang/en_us.json | 11 +- .../common/data/LangProviderEnglish.java | 10 +- .../common/data/ProviderEntityTags.java | 8 + .../common/data/RecipeProvider.java | 2 +- .../common/data/TRBlockModelProvider.java | 1 - .../tardis_refined/neoforge/CommonBus.java | 10 +- 46 files changed, 788 insertions(+), 465 deletions(-) delete mode 100644 common/src/main/java/whocraft/tardis_refined/common/blockentity/desktop/InternalDoorBlockEntity.java delete mode 100644 common/src/main/java/whocraft/tardis_refined/common/blockentity/desktop/door/RootShellDoorBlockEntity.java rename common/src/main/java/whocraft/tardis_refined/common/blockentity/door/{AbstractEntityBlockDoor.java => AbstractDoorBlockEntity.java} (79%) create mode 100644 common/src/main/java/whocraft/tardis_refined/common/blockentity/door/InternalDoorBlockEntity.java create mode 100644 common/src/main/java/whocraft/tardis_refined/common/blockentity/door/RootShellDoorBlockEntity.java delete mode 100644 common/src/main/java/whocraft/tardis_refined/common/dimension/DelayedTeleportData.java create mode 100644 common/src/main/java/whocraft/tardis_refined/common/dimension/TardisTeleportData.java diff --git a/common/src/main/java/whocraft/tardis_refined/api/event/TardisEvents.java b/common/src/main/java/whocraft/tardis_refined/api/event/TardisEvents.java index a9ebd1262..7e8f60dd1 100644 --- a/common/src/main/java/whocraft/tardis_refined/api/event/TardisEvents.java +++ b/common/src/main/java/whocraft/tardis_refined/api/event/TardisEvents.java @@ -4,9 +4,11 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; +import whocraft.tardis_refined.common.blockentity.door.TardisInternalDoor; import whocraft.tardis_refined.common.capability.TardisLevelOperator; import whocraft.tardis_refined.common.capability.upgrades.Upgrade; import whocraft.tardis_refined.common.entity.ControlEntity; @@ -24,9 +26,15 @@ public class TardisEvents { } })); - public static final Event TARDIS_ENTRY_EVENT = new Event<>(TardisEntry.class, listeners -> (tardisLevelOperator, shell, player, externalPos, level, direction) -> { + public static final Event TARDIS_ENTRY_EVENT = new Event<>(TardisEntry.class, listeners -> (tardisLevelOperator, livingEntity, source, destination) -> { for (TardisEntry listener : listeners) { - listener.onEnterTardis(tardisLevelOperator, shell, player, externalPos, level, direction); + listener.onEnterTardis(tardisLevelOperator, livingEntity, source, destination); + } + }); + + public static final Event TARDIS_EXIT_EVENT = new Event<>(TardisExit.class, listeners -> (tardisLevelOperator, livingEntity, source, destination) -> { + for (TardisExit listener : listeners) { + listener.onExitTardis(tardisLevelOperator, livingEntity, source, destination); } }); @@ -175,15 +183,28 @@ public interface ShellChange { @FunctionalInterface public interface TardisEntry { /** - * Called when a player enters a TARDIS. + * Called when a living entity enters a TARDIS. + * + * @param tardisLevelOperator The Tardis capability + * @param livingEntity The living entity who is entering the TARDIS. + * @param sourceLocation The position, level and direction of the exterior of the TARDIS. + * @param destinationLocation The position, level and direction of the internal door of the TARDIS. + */ + void onEnterTardis(TardisLevelOperator tardisLevelOperator, LivingEntity livingEntity, TardisNavLocation sourceLocation, TardisNavLocation destinationLocation); + + } + + @FunctionalInterface + public interface TardisExit { + /** + * Called when a living entity exits a TARDIS. * - * @param shell The exterior shell of the TARDIS. - * @param player The player who is entering the TARDIS. - * @param externalPos The position of the exterior of the TARDIS. - * @param level The level where the TARDIS is located. - * @param direction The direction the player is facing when entering the TARDIS. + * @param tardisLevelOperator The Tardis capability + * @param livingEntity The living entity who is exiting the TARDIS. + * @param sourceLocation The position, level and direction of the internal door of the TARDIS. + * @param destinationLocation The position, level and direction of the exterior of the TARDIS. */ - void onEnterTardis(TardisLevelOperator tardisLevelOperator, ExteriorShell shell, Player player, BlockPos externalPos, Level level, Direction direction); + void onExitTardis(TardisLevelOperator tardisLevelOperator, LivingEntity livingEntity, TardisNavLocation sourceLocation, TardisNavLocation destinationLocation); } /** diff --git a/common/src/main/java/whocraft/tardis_refined/client/renderer/blockentity/door/RootShellDoorRenderer.java b/common/src/main/java/whocraft/tardis_refined/client/renderer/blockentity/door/RootShellDoorRenderer.java index cfecbdeb8..6dbcf0bb8 100644 --- a/common/src/main/java/whocraft/tardis_refined/client/renderer/blockentity/door/RootShellDoorRenderer.java +++ b/common/src/main/java/whocraft/tardis_refined/client/renderer/blockentity/door/RootShellDoorRenderer.java @@ -13,7 +13,7 @@ import whocraft.tardis_refined.client.ModelRegistry; import whocraft.tardis_refined.client.model.blockentity.shell.internal.door.RootShellDoorModel; import whocraft.tardis_refined.common.block.shell.RootedShellBlock; -import whocraft.tardis_refined.common.blockentity.desktop.door.RootShellDoorBlockEntity; +import whocraft.tardis_refined.common.blockentity.door.RootShellDoorBlockEntity; public class RootShellDoorRenderer implements BlockEntityRenderer, BlockEntityRendererProvider { diff --git a/common/src/main/java/whocraft/tardis_refined/client/screen/waypoints/WaypointManageScreen.java b/common/src/main/java/whocraft/tardis_refined/client/screen/waypoints/WaypointManageScreen.java index 36a7aaeb3..8f04f0eef 100644 --- a/common/src/main/java/whocraft/tardis_refined/client/screen/waypoints/WaypointManageScreen.java +++ b/common/src/main/java/whocraft/tardis_refined/client/screen/waypoints/WaypointManageScreen.java @@ -47,7 +47,7 @@ public class WaypointManageScreen extends Screen { private SpriteIconButton onSaveWaypoint; public WaypointManageScreen(List> worlds, CoordInputType coordInputType, TardisNavLocation tardisNavLocation) { - super(Component.translatable(coordInputType == CoordInputType.WAYPOINT ? ModMessages.UI_MONITOR_UPLOAD_WAYPOINTS : ModMessages.UI_MONITOR_UPLOAD_COORDS)); //todo translatable + super(Component.translatable(coordInputType == CoordInputType.WAYPOINT ? ModMessages.UI_MONITOR_UPLOAD_WAYPOINTS : ModMessages.UI_MONITOR_UPLOAD_COORDS)); this.worlds = worlds; this.coordInputType = coordInputType; this.tardisNavLocation = tardisNavLocation; @@ -72,10 +72,10 @@ protected void init() { xPosition = this.width / 2 - 95; // Upload Data Button - Component uploadLiteral = Component.translatable(ModMessages.UI_MONITOR_UPLOAD); + Component uploadLiteral = Component.translatable(ModMessages.UI_MONITOR_WAYPOINT_UPLOAD); - onSaveWaypoint = this.addRenderableWidget(CommonTRWidgets.imageButton(this.width / 2 - 40, Component.translatable("Submit"), (arg) -> { + onSaveWaypoint = this.addRenderableWidget(CommonTRWidgets.imageButton(this.width / 2 - 40, Component.translatable(ModMessages.UI_MONITOR_WAYPOINT_SUBMIT), (arg) -> { if (issues.isEmpty()) { prepareForUpload(); new UploadWaypointMessage(tardisNavLocation, coordInputType).send(); @@ -87,10 +87,10 @@ protected void init() { if (coordInputType == CoordInputType.WAYPOINT) { - this.waypointName = new EditBox(this.font, xPosition, yPosition, this.width / 2 - 40, widgetHeight, this.waypointName, Component.translatable("selectWorld.search")); + this.waypointName = new EditBox(this.font, xPosition, yPosition, this.width / 2 - 40, widgetHeight, this.waypointName, Component.translatable(ModMessages.VANILLA_SELECT_WORLD)); this.waypointName.setResponder((string) -> { if (string.isEmpty()) { - issues.put("waypoint_error", "Invalid Waypoint name"); + issues.put("waypoint_error", Component.translatable(ModMessages.UI_MONITOR_WAYPOINT_ISSUE_NAME).getString()); return; } else { tardisNavLocation.setName(string); @@ -103,45 +103,45 @@ protected void init() { } - this.xCoord = new EditBox(this.font, xPosition, yPosition, widgetLengths - 30, widgetHeight, this.xCoord, Component.translatable("selectWorld.search")); + this.xCoord = new EditBox(this.font, xPosition, yPosition, widgetLengths - 30, widgetHeight, this.xCoord, Component.translatable(ModMessages.VANILLA_SELECT_WORLD)); this.xCoord.setResponder((string) -> { try { int newValue = Integer.parseInt(string); tardisNavLocation.setX(newValue); issues.remove("x_error"); } catch (NumberFormatException e) { - issues.put("x_error", "Invalid X Value!"); + issues.put("x_error", Component.translatable(ModMessages.UI_MONITOR_WAYPOINT_ISSUE_X).getString()); } }); xPosition += widgetLengths - 35 + 15; - this.yCoord = new EditBox(this.font, xPosition, yPosition, widgetLengths - 30, widgetHeight, this.yCoord, Component.translatable("selectWorld.search")); + this.yCoord = new EditBox(this.font, xPosition, yPosition, widgetLengths - 30, widgetHeight, this.yCoord, Component.translatable(ModMessages.VANILLA_SELECT_WORLD)); this.yCoord.setResponder((string) -> { try { int newValue = Integer.parseInt(string); tardisNavLocation.setY(newValue); issues.remove("y_error"); } catch (NumberFormatException e) { - issues.put("y_error", "Invalid Y Value!"); + issues.put("y_error", Component.translatable(ModMessages.UI_MONITOR_WAYPOINT_ISSUE_Y).getString()); } }); xPosition += widgetLengths - 35 + 15; - this.zCoord = new EditBox(this.font, xPosition, yPosition, widgetLengths - 30, widgetHeight, this.zCoord, Component.translatable("selectWorld.search")); + this.zCoord = new EditBox(this.font, xPosition, yPosition, widgetLengths - 30, widgetHeight, this.zCoord, Component.translatable(ModMessages.VANILLA_SELECT_WORLD)); this.zCoord.setResponder((string) -> { try { int newValue = Integer.parseInt(string); tardisNavLocation.setZ(newValue); issues.remove("z_error"); } catch (NumberFormatException e) { - issues.put("z_error", "Invalid Z Value!"); + issues.put("z_error", Component.translatable(ModMessages.UI_MONITOR_WAYPOINT_ISSUE_Z).getString()); } }); -//Buttons + //Buttons xPosition = this.width / 2 - 95; // Set Dimension Button @@ -150,7 +150,7 @@ protected void init() { return Component.literal(MiscHelper.getCleanDimensionName(dimension)); }); dimBuilder.withValues(this.worlds); - levelButton = dimBuilder.create(xPosition, yPosition + 100 - 45, this.width / 2 - 40, widgetHeight, Component.literal("Dimension")); + levelButton = dimBuilder.create(xPosition, yPosition + 100 - 45, this.width / 2 - 40, widgetHeight, Component.translatable(ModMessages.UI_MONITOR_WAYPOINT_DIMENSION)); this.addWidget(levelButton); // Direction Button @@ -162,7 +162,7 @@ protected void init() { return Component.literal(direction.getName().substring(0, 1).toUpperCase() + direction.getName().substring(1)); }); builder.withValues(directionCollection); - directionButton = builder.create(xPosition, yPosition + 100 - 65, this.width / 2 - 40, widgetHeight, Component.literal("Direction")); + directionButton = builder.create(xPosition, yPosition + 100 - 65, this.width / 2 - 40, widgetHeight, Component.translatable(ModMessages.UI_MONITOR_WAYPOINT_DIRECTION)); addWidget(directionButton); diff --git a/common/src/main/java/whocraft/tardis_refined/command/sub/CreateCommand.java b/common/src/main/java/whocraft/tardis_refined/command/sub/CreateCommand.java index 3d360713b..895d5e372 100644 --- a/common/src/main/java/whocraft/tardis_refined/command/sub/CreateCommand.java +++ b/common/src/main/java/whocraft/tardis_refined/command/sub/CreateCommand.java @@ -19,7 +19,6 @@ import whocraft.tardis_refined.command.arguments.DesktopArgumentType; import whocraft.tardis_refined.command.arguments.ShellArgumentType; import whocraft.tardis_refined.common.tardis.themes.DesktopTheme; -import whocraft.tardis_refined.common.util.CommandHelper; import whocraft.tardis_refined.common.util.TardisHelper; import whocraft.tardis_refined.constants.ModMessages; @@ -48,10 +47,7 @@ private static int createTardis(CommandContext context) thro //Create a Level Key with a randomised UUID ResourceKey generatedLevelKey = ResourceKey.create(Registries.DIMENSION, new ResourceLocation(TardisRefined.MODID, UUID.randomUUID().toString())); - ResourceLocation levelId = generatedLevelKey.location(); - String id = levelId.toString(); - String displayId = levelId.getPath().substring(0, 5); - MutableComponent tardisId = CommandHelper.createComponentWithTooltip(displayId, id); + MutableComponent tardisId = TardisHelper.createTardisIdComponent(generatedLevelKey.location()); context.getSource().sendSystemMessage(Component.translatable(ModMessages.CMD_CREATE_TARDIS_IN_PROGRESS, tardisId)); diff --git a/common/src/main/java/whocraft/tardis_refined/command/sub/InteriorCommand.java b/common/src/main/java/whocraft/tardis_refined/command/sub/InteriorCommand.java index 9fea11841..aeb6aa34a 100644 --- a/common/src/main/java/whocraft/tardis_refined/command/sub/InteriorCommand.java +++ b/common/src/main/java/whocraft/tardis_refined/command/sub/InteriorCommand.java @@ -59,7 +59,7 @@ private static boolean teleportToInterior(TardisLevelOperator tardisLevelOperato if (tardisLevelOperator.getInternalDoor() != null) { BlockPos pos = tardisLevelOperator.getInternalDoor().getDoorPosition(); pos = pos.relative(tardisLevelOperator.getInternalDoor().getEntryRotation(), 1); - TRTeleporter.performTeleport(entity, finalTpLevel, pos.getX(), pos.getY(), pos.getZ(), entity.getYRot(), entity.getXRot()); + TRTeleporter.performTeleport(entity, finalTpLevel, pos.getX(), pos.getY(), pos.getZ(), entity.getYHeadRot(), entity.getXRot()); return true; } } diff --git a/common/src/main/java/whocraft/tardis_refined/command/sub/LevelCommand.java b/common/src/main/java/whocraft/tardis_refined/command/sub/LevelCommand.java index b9b4535c9..e202a34b0 100644 --- a/common/src/main/java/whocraft/tardis_refined/command/sub/LevelCommand.java +++ b/common/src/main/java/whocraft/tardis_refined/command/sub/LevelCommand.java @@ -11,12 +11,11 @@ import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; -import org.spongepowered.asm.mixin.Mutable; import whocraft.tardis_refined.common.capability.TardisLevelOperator; import whocraft.tardis_refined.common.capability.upgrades.UpgradeHandler; import whocraft.tardis_refined.common.util.CommandHelper; +import whocraft.tardis_refined.common.util.TardisHelper; import whocraft.tardis_refined.constants.ModMessages; public class LevelCommand { @@ -54,10 +53,7 @@ public class LevelCommand { private static int getDimensionPoints(CommandContext context) throws CommandSyntaxException { ServerLevel dimension = DimensionArgument.getDimension(context, "tardis"); - ResourceLocation levelId = dimension.dimension().location(); - String id = levelId.toString(); - String displayId = levelId.getPath().substring(0, 5); - MutableComponent tardisId = CommandHelper.createComponentWithTooltip(displayId, id); + MutableComponent tardisId = TardisHelper.createTardisIdComponent(dimension.dimension().location()); TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { int points = tardisLevelOperator.getUpgradeHandler().getUpgradePoints(); @@ -72,10 +68,7 @@ private static int setDimensionPoints(CommandContext context int amount = IntegerArgumentType.getInteger(context, "amount"); ServerLevel dimension = DimensionArgument.getDimension(context, "tardis"); - ResourceLocation levelId = dimension.dimension().location(); - String id = levelId.toString(); - String displayId = levelId.getPath().substring(0, 5); - MutableComponent tardisId = CommandHelper.createComponentWithTooltip(displayId, id); + MutableComponent tardisId = TardisHelper.createTardisIdComponent(dimension.dimension().location()); TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { UpgradeHandler upgradeHandler = tardisLevelOperator.getUpgradeHandler(); @@ -92,10 +85,7 @@ private static int addDimensionPoints(CommandContext context int amount = IntegerArgumentType.getInteger(context, "amount"); ServerLevel dimension = DimensionArgument.getDimension(context, "tardis"); - ResourceLocation levelId = dimension.dimension().location(); - String id = levelId.toString(); - String displayId = levelId.getPath().substring(0, 5); - MutableComponent tardisId = CommandHelper.createComponentWithTooltip(displayId, id); + MutableComponent tardisId = TardisHelper.createTardisIdComponent(dimension.dimension().location()); TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { UpgradeHandler upgradeHandler = tardisLevelOperator.getUpgradeHandler(); @@ -112,10 +102,7 @@ private static int addDimensionXp(CommandContext context) th int amount = IntegerArgumentType.getInteger(context, "amount"); ServerLevel dimension = DimensionArgument.getDimension(context, "tardis"); - ResourceLocation levelId = dimension.dimension().location(); - String id = levelId.toString(); - String displayId = levelId.getPath().substring(0, 5); - MutableComponent tardisId = CommandHelper.createComponentWithTooltip(displayId, id); + MutableComponent tardisId = TardisHelper.createTardisIdComponent(dimension.dimension().location()); TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { UpgradeHandler upgradeHandler = tardisLevelOperator.getUpgradeHandler(); @@ -130,10 +117,7 @@ private static int addDimensionXp(CommandContext context) th private static int getDimensionXp(CommandContext context) throws CommandSyntaxException { ServerLevel dimension = DimensionArgument.getDimension(context, "tardis"); - ResourceLocation levelId = dimension.dimension().location(); - String id = levelId.toString(); - String displayId = levelId.getPath().substring(0, 5); - MutableComponent tardisId = CommandHelper.createComponentWithTooltip(displayId, id); + MutableComponent tardisId = TardisHelper.createTardisIdComponent(dimension.dimension().location()); TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { int xp = tardisLevelOperator.getUpgradeHandler().getUpgradeXP(); @@ -148,10 +132,7 @@ private static int setDimensionXp(CommandContext context) th int amount = IntegerArgumentType.getInteger(context, "amount"); ServerLevel dimension = DimensionArgument.getDimension(context, "tardis"); - ResourceLocation levelId = dimension.dimension().location(); - String id = levelId.toString(); - String displayId = levelId.getPath().substring(0, 5); - MutableComponent tardisId = CommandHelper.createComponentWithTooltip(displayId, id); + MutableComponent tardisId = TardisHelper.createTardisIdComponent(dimension.dimension().location()); TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { tardisLevelOperator.getUpgradeHandler().setUpgradeXP(amount); diff --git a/common/src/main/java/whocraft/tardis_refined/command/sub/UpgradesCommand.java b/common/src/main/java/whocraft/tardis_refined/command/sub/UpgradesCommand.java index 42262f877..11d03b413 100644 --- a/common/src/main/java/whocraft/tardis_refined/command/sub/UpgradesCommand.java +++ b/common/src/main/java/whocraft/tardis_refined/command/sub/UpgradesCommand.java @@ -10,12 +10,12 @@ import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import whocraft.tardis_refined.command.arguments.UpgradeArgumentType; import whocraft.tardis_refined.common.capability.TardisLevelOperator; import whocraft.tardis_refined.common.capability.upgrades.Upgrade; import whocraft.tardis_refined.common.util.CommandHelper; +import whocraft.tardis_refined.common.util.TardisHelper; import whocraft.tardis_refined.constants.ModMessages; public class UpgradesCommand { @@ -43,10 +43,7 @@ private static int setUpgradeLocked(CommandContext context) Upgrade upgrade = UpgradeArgumentType.getUpgrade(context, "upgrade"); ServerLevel dimension = DimensionArgument.getDimension(context, "tardis"); - ResourceLocation levelId = dimension.dimension().location(); - String id = levelId.toString(); - String displayId = levelId.getPath().substring(0, 5); - MutableComponent tardisId = CommandHelper.createComponentWithTooltip(displayId, id); + MutableComponent tardisId = TardisHelper.createTardisIdComponent(dimension.dimension().location()); TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { tardisLevelOperator.getUpgradeHandler().lockUpgrade(upgrade); @@ -61,10 +58,7 @@ private static int setUpgradeUnlocked(CommandContext context Upgrade upgrade = UpgradeArgumentType.getUpgrade(context, "upgrade"); ServerLevel dimension = DimensionArgument.getDimension(context, "tardis"); - ResourceLocation levelId = dimension.dimension().location(); - String id = levelId.toString(); - String displayId = levelId.getPath().substring(0, 5); - MutableComponent tardisId = CommandHelper.createComponentWithTooltip(displayId, id); + MutableComponent tardisId = TardisHelper.createTardisIdComponent(dimension.dimension().location()); TardisLevelOperator.get(dimension).ifPresent(tardisLevelOperator -> { tardisLevelOperator.getUpgradeHandler().unlockUpgrade(upgrade); diff --git a/common/src/main/java/whocraft/tardis_refined/common/block/door/GlobalDoorBlock.java b/common/src/main/java/whocraft/tardis_refined/common/block/door/GlobalDoorBlock.java index 6d59227ef..31de07a03 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/block/door/GlobalDoorBlock.java +++ b/common/src/main/java/whocraft/tardis_refined/common/block/door/GlobalDoorBlock.java @@ -35,7 +35,8 @@ public GlobalDoorBlock(Properties properties) { @Nullable @Override public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { - return new GlobalDoorBlockEntity(blockPos, blockState); + this.setBlockEntity(new GlobalDoorBlockEntity(blockPos, blockState)); + return super.newBlockEntity(blockPos, blockState); } @Override @@ -96,18 +97,6 @@ public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, Block } } - @Override - public void entityInside(BlockState blockState, Level level, BlockPos blockPos, Entity entity) { - - if (!level.isClientSide()) { - if (level.getBlockEntity(blockPos) instanceof GlobalDoorBlockEntity door) { - if (entity instanceof Player player) { - door.onAttemptEnter(level,player); - } - } - } - } - static { NORTH_AABB = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 0.25D); SOUTH_AABB = Block.box(0.0D, 0.0D, 15.75D, 16.0D, 16.0D, 16.0D); diff --git a/common/src/main/java/whocraft/tardis_refined/common/block/door/InternalDoorBlock.java b/common/src/main/java/whocraft/tardis_refined/common/block/door/InternalDoorBlock.java index fa452cf08..e69bd57f3 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/block/door/InternalDoorBlock.java +++ b/common/src/main/java/whocraft/tardis_refined/common/block/door/InternalDoorBlock.java @@ -2,10 +2,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.Entity; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; @@ -18,20 +15,19 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.DirectionProperty; -import net.minecraft.world.level.gameevent.GameEventListener; -import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import whocraft.tardis_refined.common.blockentity.desktop.InternalDoorBlockEntity; -import whocraft.tardis_refined.common.blockentity.door.AbstractEntityBlockDoor; +import whocraft.tardis_refined.common.blockentity.door.InternalDoorBlockEntity; public class InternalDoorBlock extends BaseEntityBlock { public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public static final BooleanProperty OPEN = BooleanProperty.create("open"); protected static final VoxelShape COLLISION = Block.box(0, 0, 0, 16, 3, 16); + protected static BlockEntity blockEntity; + public InternalDoorBlock(Properties properties) { super(properties); @@ -40,7 +36,7 @@ public InternalDoorBlock(Properties properties) { @Override public void onPlace(BlockState blockState, Level level, BlockPos blockPos, BlockState blockState2, boolean bl) { - if (level.getBlockEntity(blockPos) instanceof AbstractEntityBlockDoor door) { + if (level.getBlockEntity(blockPos) instanceof InternalDoorBlockEntity door) { door.onBlockPlaced(); } super.onPlace(blockState, level, blockPos, blockState2, bl); @@ -57,20 +53,18 @@ public VoxelShape getCollisionShape(BlockState blockState, BlockGetter blockGett return COLLISION; } + @Nullable @Override - public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) { - - if (level.getBlockEntity(blockPos) instanceof InternalDoorBlockEntity door) { - door.onRightClick(blockState, level, blockPos, player, interactionHand, blockHitResult); - } + public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { + return this.getDoorBlockEntity(); + } - return super.use(blockState, level, blockPos, player, interactionHand, blockHitResult); + public void setBlockEntity(BlockEntity blockEntity){ + this.blockEntity = blockEntity; } - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { - return new InternalDoorBlockEntity(blockPos, blockState); + public BlockEntity getDoorBlockEntity(){ + return this.blockEntity; } @Override @@ -90,10 +84,14 @@ public BlockState getStateForPlacement(@NotNull BlockPlaceContext blockPlaceCont return state.setValue(FACING, rot.rotate(state.getValue(FACING))); } - @Nullable @Override - public GameEventListener getListener(ServerLevel pLevel, T pBlockEntity) { - return super.getListener(pLevel, pBlockEntity); + public void entityInside(BlockState blockState, Level level, BlockPos blockPos, Entity entity) { + + if (!level.isClientSide()) { + if (level.getBlockEntity(blockPos) instanceof InternalDoorBlockEntity door) { + door.onAttemptEnter(blockState, level, blockPos, entity); + } + } } diff --git a/common/src/main/java/whocraft/tardis_refined/common/block/door/RootShellDoorBlock.java b/common/src/main/java/whocraft/tardis_refined/common/block/door/RootShellDoorBlock.java index c7d8573cd..f35ef1580 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/block/door/RootShellDoorBlock.java +++ b/common/src/main/java/whocraft/tardis_refined/common/block/door/RootShellDoorBlock.java @@ -3,7 +3,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -12,15 +11,15 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.Nullable; -import whocraft.tardis_refined.common.blockentity.desktop.door.RootShellDoorBlockEntity; +import whocraft.tardis_refined.common.blockentity.door.GlobalDoorBlockEntity; +import whocraft.tardis_refined.common.blockentity.door.RootShellDoorBlockEntity; -public class RootShellDoorBlock extends InternalDoorBlock { +public class RootShellDoorBlock extends GlobalDoorBlock { protected static final VoxelShape SOUTH_AABB, NORTH_AABB, WEST_AABB, EAST_AABB; public RootShellDoorBlock(Properties properties) { - super(properties); this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(OPEN, true)); } @@ -28,7 +27,8 @@ public RootShellDoorBlock(Properties properties) { @Nullable @Override public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { - return new RootShellDoorBlockEntity(blockPos, blockState); + this.setBlockEntity(new RootShellDoorBlockEntity(blockPos, blockState)); + return super.newBlockEntity(blockPos, blockState); } @Override @@ -60,17 +60,6 @@ public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, Block } } - @Override - public void entityInside(BlockState blockState, Level level, BlockPos blockPos, Entity entity) { - if (!level.isClientSide()) { - if (level.getBlockEntity(blockPos) instanceof RootShellDoorBlockEntity door) { - if (entity instanceof Player player) { - door.onAttemptEnter(level,player); - } - } - } - } - static { NORTH_AABB = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 3.0D); SOUTH_AABB = Block.box(0.0D, 0.0D, 13.0D, 16.0D, 16.0D, 16.0D); diff --git a/common/src/main/java/whocraft/tardis_refined/common/block/shell/ShellBaseBlock.java b/common/src/main/java/whocraft/tardis_refined/common/block/shell/ShellBaseBlock.java index 60af3bcb5..a4649a608 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/block/shell/ShellBaseBlock.java +++ b/common/src/main/java/whocraft/tardis_refined/common/block/shell/ShellBaseBlock.java @@ -131,9 +131,7 @@ public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, Block public void entityInside(BlockState blockState, Level level, BlockPos blockPos, Entity entity) { if (!level.isClientSide()){ if (level.getBlockEntity(blockPos) instanceof ShellBaseBlockEntity shellEntity) { - if (entity instanceof Player player) { - shellEntity.onAttemptEnter(blockState, level, shellEntity.getBlockPos(), player); - } + shellEntity.onAttemptEnter(blockState, level, shellEntity.getBlockPos(), entity); } } } diff --git a/common/src/main/java/whocraft/tardis_refined/common/blockentity/desktop/InternalDoorBlockEntity.java b/common/src/main/java/whocraft/tardis_refined/common/blockentity/desktop/InternalDoorBlockEntity.java deleted file mode 100644 index e71ec56d3..000000000 --- a/common/src/main/java/whocraft/tardis_refined/common/blockentity/desktop/InternalDoorBlockEntity.java +++ /dev/null @@ -1,37 +0,0 @@ -package whocraft.tardis_refined.common.blockentity.desktop; - -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.BlockHitResult; -import whocraft.tardis_refined.common.blockentity.door.AbstractEntityBlockDoor; -import whocraft.tardis_refined.common.capability.TardisLevelOperator; -import whocraft.tardis_refined.registry.BlockEntityRegistry; - -import java.util.Optional; - -public class InternalDoorBlockEntity extends AbstractEntityBlockDoor { - - public InternalDoorBlockEntity(BlockPos blockPos, BlockState blockState) { - super(BlockEntityRegistry.TARDIS_INTERNAL_DOOR.get(), blockPos, blockState); - } - - - - public void onRightClick(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) { - if (!level.isClientSide()) { - Optional operator = TardisLevelOperator.get((ServerLevel) level); - operator.ifPresent(x -> { - x.setInternalDoor(this); - x.exitTardis(player); - }); - - } - - - } - -} diff --git a/common/src/main/java/whocraft/tardis_refined/common/blockentity/desktop/door/RootShellDoorBlockEntity.java b/common/src/main/java/whocraft/tardis_refined/common/blockentity/desktop/door/RootShellDoorBlockEntity.java deleted file mode 100644 index de542433b..000000000 --- a/common/src/main/java/whocraft/tardis_refined/common/blockentity/desktop/door/RootShellDoorBlockEntity.java +++ /dev/null @@ -1,34 +0,0 @@ -package whocraft.tardis_refined.common.blockentity.desktop.door; - -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockState; -import whocraft.tardis_refined.common.capability.TardisLevelOperator; -import whocraft.tardis_refined.common.blockentity.door.AbstractEntityBlockDoor; -import whocraft.tardis_refined.registry.BlockEntityRegistry; - -import java.util.Optional; - -public class RootShellDoorBlockEntity extends AbstractEntityBlockDoor { - - public RootShellDoorBlockEntity(BlockPos blockPos, BlockState blockState) { - super(BlockEntityRegistry.ROOT_SHELL_DOOR.get(), blockPos, blockState); - } - - public void onAttemptEnter(Level level, Player player) { - if(level instanceof ServerLevel serverLevel){ - Optional data = TardisLevelOperator.get(serverLevel); - data.ifPresent(tardisLevelOperator -> { - tardisLevelOperator.setInternalDoor(this); - tardisLevelOperator.exitTardis(player); - }); - } - } - - @Override - public boolean isOpen() { - return true; - } -} diff --git a/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/AbstractEntityBlockDoor.java b/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/AbstractDoorBlockEntity.java similarity index 79% rename from common/src/main/java/whocraft/tardis_refined/common/blockentity/door/AbstractEntityBlockDoor.java rename to common/src/main/java/whocraft/tardis_refined/common/blockentity/door/AbstractDoorBlockEntity.java index a831621f2..449f2315f 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/AbstractEntityBlockDoor.java +++ b/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/AbstractDoorBlockEntity.java @@ -7,6 +7,8 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -20,14 +22,15 @@ import java.util.Optional; import java.util.UUID; -public class AbstractEntityBlockDoor extends BlockEntity implements TardisInternalDoor { +public class AbstractDoorBlockEntity extends BlockEntity implements TardisInternalDoor { + private boolean isLocked = false; private String uuid_id; private boolean isMainDoor = false; private TardisLevelOperator operator; - public AbstractEntityBlockDoor(BlockEntityType blockEntityType, BlockPos blockPos, BlockState blockState) { + public AbstractDoorBlockEntity(BlockEntityType blockEntityType, BlockPos blockPos, BlockState blockState) { super(blockEntityType, blockPos, blockState); this.uuid_id = UUID.randomUUID().toString(); } @@ -55,7 +58,7 @@ public void setID(String id) { @Override public boolean isOpen() { - return getBlockState().getValue(GlobalDoorBlock.OPEN); + return this.getBlockState().getValue(InternalDoorBlock.OPEN); } @Override @@ -75,15 +78,8 @@ public BlockPos getDoorPosition() { @Override public BlockPos getEntryPosition() { - - int direction = getBlockState().getValue(ShellBaseBlock.FACING).get2DDataValue(); - return switch (direction) { - case 3 -> new BlockPos(getBlockPos().getX() - 1, getBlockPos().getY(), getBlockPos().getZ()); - case 2 -> new BlockPos(getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ() + 1); - case 1 -> new BlockPos(getBlockPos().getX() + 1, getBlockPos().getY(), getBlockPos().getZ()); - case 0 -> new BlockPos(getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ() - 1); - default -> getBlockPos().above(); - }; + Direction direction = this.getBlockState().getValue(ShellBaseBlock.FACING); + return this.getBlockPos().offset(direction.getOpposite().getNormal()); } @@ -138,4 +134,14 @@ public void load(CompoundTag compoundTag) { this.isLocked = compoundTag.getBoolean(NbtConstants.DOOR_IS_LOCKED); } + public void onAttemptEnter(BlockState blockState, Level level, BlockPos doorPos, Entity entity) { + if(!entity.level().isClientSide() && level instanceof ServerLevel serverLevel){ + Optional data = TardisLevelOperator.get(serverLevel); + data.ifPresent(tardisLevelOperator -> { + tardisLevelOperator.setInternalDoor(this); + tardisLevelOperator.exitTardis(entity, serverLevel, doorPos, blockState.getValue(InternalDoorBlock.FACING)); + }); + } + } + } diff --git a/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/GlobalDoorBlockEntity.java b/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/GlobalDoorBlockEntity.java index 304e68c98..e337cb879 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/GlobalDoorBlockEntity.java +++ b/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/GlobalDoorBlockEntity.java @@ -7,12 +7,15 @@ import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; import whocraft.tardis_refined.common.block.door.GlobalDoorBlock; +import whocraft.tardis_refined.common.block.door.InternalDoorBlock; +import whocraft.tardis_refined.common.block.shell.ShellBaseBlock; import whocraft.tardis_refined.common.capability.TardisLevelOperator; import whocraft.tardis_refined.common.tardis.themes.ShellTheme; import whocraft.tardis_refined.constants.NbtConstants; @@ -22,7 +25,7 @@ import java.util.Optional; -public class GlobalDoorBlockEntity extends AbstractEntityBlockDoor { +public class GlobalDoorBlockEntity extends InternalDoorBlockEntity { private ResourceLocation shellTheme = ShellTheme.FACTORY.getId(); private ShellPattern basePattern; @@ -133,16 +136,4 @@ public void onRightClick(BlockState blockState, TardisInternalDoor door, Player }); } } - - - - public void onAttemptEnter(Level level, Player player) { - if (!level.isClientSide()) { - Optional operator = TardisLevelOperator.get((ServerLevel) level); - operator.ifPresent(x -> { - x.setInternalDoor(this); - x.exitTardis(player); - }); - } - } } diff --git a/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/InternalDoorBlockEntity.java b/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/InternalDoorBlockEntity.java new file mode 100644 index 000000000..37d7d67d5 --- /dev/null +++ b/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/InternalDoorBlockEntity.java @@ -0,0 +1,13 @@ +package whocraft.tardis_refined.common.blockentity.door; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; + +public class InternalDoorBlockEntity extends AbstractDoorBlockEntity { + + public InternalDoorBlockEntity(BlockEntityType type, BlockPos blockPos,BlockState blockState) { + super(type, blockPos, blockState); + } + +} \ No newline at end of file diff --git a/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/RootShellDoorBlockEntity.java b/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/RootShellDoorBlockEntity.java new file mode 100644 index 000000000..3d554f53a --- /dev/null +++ b/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/RootShellDoorBlockEntity.java @@ -0,0 +1,19 @@ +package whocraft.tardis_refined.common.blockentity.door; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import whocraft.tardis_refined.registry.BlockEntityRegistry; + +import java.util.Optional; + +public class RootShellDoorBlockEntity extends InternalDoorBlockEntity { + + public RootShellDoorBlockEntity(BlockPos blockPos, BlockState blockState) { + super(BlockEntityRegistry.ROOT_SHELL_DOOR.get(), blockPos, blockState); + } + + @Override + public boolean isOpen() { + return true; + } +} diff --git a/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/TardisInternalDoor.java b/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/TardisInternalDoor.java index 30927ee63..37ee48566 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/TardisInternalDoor.java +++ b/common/src/main/java/whocraft/tardis_refined/common/blockentity/door/TardisInternalDoor.java @@ -4,6 +4,8 @@ import net.minecraft.core.Direction; import net.minecraft.server.level.ServerEntity; +import java.util.UUID; + public interface TardisInternalDoor { boolean isMainDoor(); @@ -25,4 +27,5 @@ public interface TardisInternalDoor { void setLocked(boolean locked); boolean locked(); + } diff --git a/common/src/main/java/whocraft/tardis_refined/common/blockentity/shell/GlobalShellBlockEntity.java b/common/src/main/java/whocraft/tardis_refined/common/blockentity/shell/GlobalShellBlockEntity.java index 9d3b3b153..f263dd43b 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/blockentity/shell/GlobalShellBlockEntity.java +++ b/common/src/main/java/whocraft/tardis_refined/common/blockentity/shell/GlobalShellBlockEntity.java @@ -9,6 +9,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import whocraft.tardis_refined.TardisRefined; import whocraft.tardis_refined.common.block.shell.GlobalShellBlock; diff --git a/common/src/main/java/whocraft/tardis_refined/common/blockentity/shell/ShellBaseBlockEntity.java b/common/src/main/java/whocraft/tardis_refined/common/blockentity/shell/ShellBaseBlockEntity.java index 9ddf37b81..08afb6a30 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/blockentity/shell/ShellBaseBlockEntity.java +++ b/common/src/main/java/whocraft/tardis_refined/common/blockentity/shell/ShellBaseBlockEntity.java @@ -1,6 +1,7 @@ package whocraft.tardis_refined.common.blockentity.shell; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -9,6 +10,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.AnimationState; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -38,11 +40,11 @@ public abstract class ShellBaseBlockEntity extends BlockEntity implements Exteri public ShellBaseBlockEntity(BlockEntityType blockEntityType, BlockPos blockPos, BlockState blockState) { super(blockEntityType, blockPos, blockState); } - + @Override public ResourceKey getTardisId() { return this.TARDIS_ID; } - + @Override public void setTardisId(ResourceKey levelKey) { this.TARDIS_ID = levelKey; this.setChanged(); @@ -89,18 +91,18 @@ public boolean shouldSetup() { return false; } - public void onAttemptEnter(BlockState blockState, Level level, BlockPos blockPos, Player player) { - if (level instanceof ServerLevel serverLevel) { + public void onAttemptEnter(BlockState blockState, Level level, BlockPos externalShellPos, Entity entity) { + if (!entity.level().isClientSide() && level instanceof ServerLevel serverLevel) { if (this.TARDIS_ID == null) { - TardisRefined.LOGGER.error("Error in onAttemptEnter: null Tardis ID (could this be an invalid block?) [" + blockPos.toShortString() + "]"); + TardisRefined.LOGGER.error("Error in onAttemptEnter: null Tardis ID (could this be an invalid block?) [" + externalShellPos.toShortString() + "]"); return; } - ServerLevel interior = DimensionHandler.getOrCreateInterior(level, this.TARDIS_ID.location()); + ServerLevel interior = DimensionHandler.getOrCreateInterior(serverLevel, this.TARDIS_ID.location()); TardisLevelOperator.get(interior).ifPresent(cap -> { UpgradeHandler upgradeHandler = cap.getUpgradeHandler(); - if (cap.isTardisReady() && (blockState.getValue(ShellBaseBlock.OPEN) || cap.getPilotingManager().endFlight() && Upgrades.MATERIALIZE_AROUND.get().isUnlocked(upgradeHandler))) { + if (cap.isTardisReady() && (blockState.getValue(ShellBaseBlock.OPEN) || (cap.getPilotingManager().endFlight() && Upgrades.MATERIALIZE_AROUND.get().isUnlocked(upgradeHandler)))) { if (cap.getAestheticHandler().getShellTheme() != null) { ResourceLocation theme = cap.getAestheticHandler().getShellTheme(); @@ -110,10 +112,11 @@ public void onAttemptEnter(BlockState blockState, Level level, BlockPos blockPos } } } - cap.enterTardis(this, player, blockPos, serverLevel, blockState.getValue(ShellBaseBlock.FACING)); + cap.enterTardis(entity, externalShellPos, serverLevel, blockState.getValue(ShellBaseBlock.FACING)); } else { if (!cap.isTardisReady()) { - PlayerUtil.sendMessage(player, Component.translatable(ModMessages.MSG_EXTERIOR_COOLDOWN, cap.getInteriorManager().getInteriorGenerationCooldown()), true); + if (entity instanceof Player player) + PlayerUtil.sendMessage(player, Component.translatable(ModMessages.MSG_EXTERIOR_COOLDOWN, cap.getInteriorManager().getInteriorGenerationCooldown()), true); } } }); @@ -123,19 +126,8 @@ public void onAttemptEnter(BlockState blockState, Level level, BlockPos blockPos @Override public BlockPos getExitPosition() { - int direction = getBlockState().getValue(ShellBaseBlock.FACING).get2DDataValue(); - switch (direction) { - case 3: - return new BlockPos(getBlockPos().getX() - 1, getBlockPos().getY(), getBlockPos().getZ()); - case 2: - return new BlockPos(getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ() + 1); - case 1: - return new BlockPos(getBlockPos().getX() + 1, getBlockPos().getY(), getBlockPos().getZ()); - case 0: - return new BlockPos(getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ() - 1); - } - - return getBlockPos().above(); + Direction direction = getBlockState().getValue(ShellBaseBlock.FACING); + return this.getBlockPos().offset(direction.getOpposite().getNormal()); } @Override diff --git a/common/src/main/java/whocraft/tardis_refined/common/capability/TardisLevelOperator.java b/common/src/main/java/whocraft/tardis_refined/common/capability/TardisLevelOperator.java index e67f03510..2952f0262 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/capability/TardisLevelOperator.java +++ b/common/src/main/java/whocraft/tardis_refined/common/capability/TardisLevelOperator.java @@ -7,20 +7,18 @@ import net.minecraft.nbt.NbtUtils; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; -import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.phys.Vec3; import whocraft.tardis_refined.api.event.TardisEvents; import whocraft.tardis_refined.client.TardisClientData; -import whocraft.tardis_refined.common.blockentity.desktop.door.RootShellDoorBlockEntity; +import whocraft.tardis_refined.common.blockentity.door.RootShellDoorBlockEntity; import whocraft.tardis_refined.common.blockentity.door.TardisInternalDoor; import whocraft.tardis_refined.common.capability.upgrades.UpgradeHandler; -import whocraft.tardis_refined.common.dimension.DelayedTeleportData; import whocraft.tardis_refined.common.tardis.ExteriorShell; import whocraft.tardis_refined.common.tardis.TardisArchitectureHandler; +import whocraft.tardis_refined.common.tardis.TardisNavLocation; import whocraft.tardis_refined.common.tardis.manager.*; +import whocraft.tardis_refined.common.util.TardisHelper; import whocraft.tardis_refined.compat.ModCompatChecker; import whocraft.tardis_refined.compat.portals.ImmersivePortals; import whocraft.tardis_refined.constants.NbtConstants; @@ -100,6 +98,7 @@ public void deserializeNBT(CompoundTag tag) { if (doorPos != null) { if (level.getBlockEntity(NbtUtils.readBlockPos(doorPos)) instanceof TardisInternalDoor door) { this.internalDoor = door; + this.internalDoor.setID(tag.getString(NbtConstants.TARDIS_INTERNAL_DOOR_ID)); } } @@ -148,80 +147,77 @@ public void setInitiallyGenerated(boolean hasInitiallyGenerated) { } /** - * Moves the entity into the TARDIS. If the TARDIS has no door established, the player is sent to 0,0,0. + * Moves the entity into the TARDIS. If the TARDIS has no door established, the entity is sent to 0,100,0. * - * @param player Player Entity. **/ - public void enterTardis(ExteriorShell shell, Player player, BlockPos externalPos, ServerLevel level, Direction direction) { + public boolean enterTardis(Entity entity, BlockPos externalShellPos, ServerLevel shellLevel, Direction shellDirection) { - if (player instanceof ServerPlayer serverPlayer) { - if (internalDoor != null) { - BlockPos targetPosition = internalDoor.getEntryPosition(); - Direction dir = internalDoor.getEntryRotation(); + if (!entity.level().isClientSide()) { + if (this.level instanceof ServerLevel targetServerLevel){ - ChunkAccess chunk = getLevel().getChunk(internalDoor.getDoorPosition()); - if (getLevel() instanceof ServerLevel serverLevel) { - serverLevel.setChunkForced(chunk.getPos().x, chunk.getPos().z, true); - } - level.getChunkSource().updateChunkForced(chunk.getPos(), true); - DelayedTeleportData.getOrCreate(serverPlayer.serverLevel()).schedulePlayerTeleport(serverPlayer, getLevel().dimension(), Vec3.atCenterOf(targetPosition), dir.get2DDataValue() * (360 / 4)); - } else { - - // TODO: Scan for console units near the center to warp to. + BlockPos targetPosition = internalDoor != null ? internalDoor.getEntryPosition() : TardisArchitectureHandler.DESKTOP_CENTER_POS.above(); + Direction doorDirection = internalDoor != null ? internalDoor.getEntryRotation() : entity.getDirection(); - ChunkAccess chunk = getLevel().getChunk(TardisArchitectureHandler.DESKTOP_CENTER_POS); + TardisNavLocation sourceLocation = new TardisNavLocation(externalShellPos, shellDirection, shellLevel); + TardisNavLocation targetLocation = new TardisNavLocation(targetPosition, doorDirection, targetServerLevel); - if (getLevel() instanceof ServerLevel serverLevel) { - serverLevel.setChunkForced(chunk.getPos().x, chunk.getPos().z, true); - } - level.getChunkSource().updateChunkForced(chunk.getPos(), true); - DelayedTeleportData.getOrCreate(serverPlayer.serverLevel()).schedulePlayerTeleport(serverPlayer, getLevel().dimension(), Vec3.atCenterOf(TardisArchitectureHandler.DESKTOP_CENTER_POS.above()), 0); + TardisHelper.teleportEntityTardis(this, entity, sourceLocation, targetLocation, true); + return true; } + } + return false; - tardisClientData.sync(); - TardisEvents.TARDIS_ENTRY_EVENT.invoker().onEnterTardis(this, shell, player, externalPos, level, direction); } public boolean isTardisReady() { return !this.getInteriorManager().isGeneratingDesktop(); } - public boolean exitTardis(Player player) { - - if (!this.internalDoor.isOpen()) { - return false; - } - + public boolean exitTardis(Entity entity, ServerLevel doorLevel, BlockPos doorPos, Direction doorDirection) { + if (!entity.level().isClientSide()){ + if (!this.internalDoor.isOpen()) { + return false; + } - if(aestheticHandler.getShellTheme() != null) { - ResourceLocation theme = aestheticHandler.getShellTheme(); - if(ModCompatChecker.immersivePortals() && !(this.internalDoor instanceof RootShellDoorBlockEntity)) { - if(ImmersivePortals.exteriorHasPortalSupport(theme)) { - return false; - } + if(aestheticHandler.getShellTheme() != null) { + ResourceLocation theme = aestheticHandler.getShellTheme(); + if(ModCompatChecker.immersivePortals() && !(this.internalDoor instanceof RootShellDoorBlockEntity)) { + if(ImmersivePortals.exteriorHasPortalSupport(theme)) { + return false; + } + } } - } - if (this.exteriorManager != null) { - if (this.exteriorManager.getLastKnownLocation() != null) { - BlockPos targetPosition = this.exteriorManager.getLastKnownLocation().getPosition(); - ServerLevel targetLevel = this.exteriorManager.getLastKnownLocation().getLevel(); + if (this.exteriorManager != null) { + if (this.exteriorManager.getLastKnownLocation() != null) { + + TardisNavLocation targetLocation = this.exteriorManager.getLastKnownLocation(); + BlockPos exteriorPos = targetLocation.getPosition(); + ServerLevel targetLevel = targetLocation.getLevel(); + Direction exteriorDirection = targetLocation.getDirection(); - ChunkAccess preloadedArea = this.exteriorManager.getLastKnownLocation().getLevel().getChunk(targetPosition); + BlockPos teleportPos = exteriorPos; - if (player instanceof ServerPlayer serverPlayer) { - if (targetLevel.getBlockEntity(targetPosition) instanceof ExteriorShell shellBaseBlockEntity) { - BlockPos landingArea = shellBaseBlockEntity.getExitPosition(); - DelayedTeleportData.getOrCreate(serverPlayer.serverLevel()).schedulePlayerTeleport(serverPlayer, targetLevel.dimension(), Vec3.atCenterOf(landingArea), this.exteriorManager.getLastKnownLocation().getDirection().get2DDataValue() * (360 / 4)); + if (targetLevel.getBlockEntity(exteriorPos) instanceof ExteriorShell exteriorShell) { + teleportPos = exteriorShell.getExitPosition(); } + + TardisNavLocation sourceLocation = new TardisNavLocation(doorPos, doorDirection, doorLevel); + TardisNavLocation destinationLocation = new TardisNavLocation(teleportPos, exteriorDirection, targetLevel); + + TardisHelper.teleportEntityTardis(this, entity, sourceLocation, destinationLocation, false); } } } + return true; } + + + public void setDoorClosed(boolean closeDoor) { TardisExteriorManager extManager = getExteriorManager(); TardisInternalDoor intDoor = getInternalDoor(); diff --git a/common/src/main/java/whocraft/tardis_refined/common/dimension/DelayedTeleportData.java b/common/src/main/java/whocraft/tardis_refined/common/dimension/DelayedTeleportData.java deleted file mode 100644 index f866ba427..000000000 --- a/common/src/main/java/whocraft/tardis_refined/common/dimension/DelayedTeleportData.java +++ /dev/null @@ -1,83 +0,0 @@ -package whocraft.tardis_refined.common.dimension; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.datafix.DataFixTypes; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.saveddata.SavedData; -import net.minecraft.world.phys.Vec3; -import whocraft.tardis_refined.TardisRefined; -import whocraft.tardis_refined.common.util.TRTeleporter; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.function.Function; -import java.util.function.Supplier; - -// we can't teleport players from onBlockActivated as there are assumptions -// in the right click processing that assume a player's world does not change -// so what we'll do is schedule a teleport to occur at the end of the world tick -public class DelayedTeleportData extends SavedData { - public static final String DATA_KEY = TardisRefined.MODID + ":delayed_events"; - - private List delayedTeleports = new ArrayList<>(); - - public static DelayedTeleportData getOrCreate(ServerLevel level) { - return level.getDataStorage().computeIfAbsent(new Factory<>(DelayedTeleportData::new, DelayedTeleportData::load, DataFixTypes.SAVED_DATA_MAP_DATA), DATA_KEY); - } - - public static DelayedTeleportData load(CompoundTag nbt) { - // NOOP, data is transient - return DelayedTeleportData.create(); - } - - public static DelayedTeleportData create() { - return new DelayedTeleportData(); - } - - protected DelayedTeleportData() { - } - - /** - * This is to be called from the world tick event, if the world being ticked - * is a ServerWorld and if the tick phase is the end of the world tick. - *

- * Does *not* create dynamic worlds that don't already exist, - * So dynamic worlds should be created by the thing that schedules the tick, if possible - * - * @param level The world that is being ticked and contains a data instance - */ - public static void tick(ServerLevel level) { - MinecraftServer server = level.getServer(); - DelayedTeleportData eventData = getOrCreate(level); - - // handle teleports - List teleports = eventData.delayedTeleports; - eventData.delayedTeleports = new ArrayList<>(); - for (TeleportEntry entry : teleports) { - @Nullable ServerPlayer player = server.getPlayerList().getPlayer(entry.playerUUID); - @Nullable ServerLevel targetWorld = server.getLevel(entry.targetLevel); - if (player != null && targetWorld != null && player.level() == level) { - TRTeleporter.performTeleport(player, targetWorld, entry.targetVec.x(), entry.targetVec.y(), entry.targetVec.z(), entry.dir(), player.getXRot()); - } - } - } - - public void schedulePlayerTeleport(Player player, ResourceKey destination, Vec3 targetVec, int dir) { - this.delayedTeleports.add(new TeleportEntry(player.getGameProfile().getId(), destination, targetVec, dir)); - } - - @Override - public CompoundTag save(CompoundTag compound) { - return compound; - } - - private record TeleportEntry(UUID playerUUID, ResourceKey targetLevel, Vec3 targetVec, int dir) { - } -} \ No newline at end of file diff --git a/common/src/main/java/whocraft/tardis_refined/common/dimension/TardisTeleportData.java b/common/src/main/java/whocraft/tardis_refined/common/dimension/TardisTeleportData.java new file mode 100644 index 000000000..c5d495462 --- /dev/null +++ b/common/src/main/java/whocraft/tardis_refined/common/dimension/TardisTeleportData.java @@ -0,0 +1,162 @@ +package whocraft.tardis_refined.common.dimension; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.datafix.DataFixTypes; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.saveddata.SavedData; +import whocraft.tardis_refined.TardisRefined; +import whocraft.tardis_refined.common.util.TRTeleporter; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +// we can't teleport players from onBlockActivated as there are assumptions +// in the right click processing that assume a player's world does not change +// so what we'll do is schedule a teleport to occur at the end of the world tick +public class TardisTeleportData extends SavedData { + public static final String DATA_KEY = new ResourceLocation(TardisRefined.MODID, "tardis_teleports").toString(); + + private List queuedTeleports = new ArrayList<>(); + + public static TardisTeleportData getOrCreate(ServerLevel level) { + return level.getDataStorage().computeIfAbsent(new Factory<>(TardisTeleportData::new, TardisTeleportData::load, DataFixTypes.SAVED_DATA_MAP_DATA), DATA_KEY); + } + + public static TardisTeleportData load(CompoundTag nbt) { + // NOOP, data is transient + return TardisTeleportData.create(); + } + + public static TardisTeleportData create() { + return new TardisTeleportData(); + } + + protected TardisTeleportData() { + } + + /** + * This is to be called from the world tick event, if the world being ticked + * is a ServerWorld and if the tick phase is the end of the world tick. + *

+ * Does *not* create dynamic worlds that don't already exist, + * So dynamic worlds should be created by the thing that schedules the tick, if possible + * + * @param level The world that is being ticked and contains a data instance + */ + public static void tick(ServerLevel level) { + MinecraftServer server = level.getServer(); + TardisTeleportData eventData = getOrCreate(level); + + // handle teleports + List teleports = eventData.queuedTeleports; + + Set teleportedEntities = new HashSet<>(); + + if (teleports.size() != 0){ + for (TeleportEntry entry : teleports) { + + if (!entry.getIsCurrentTeleporting()) { + entry.setIsCurrentTeleporting(true); + + Entity entity = entry.getEntity(); + + if (teleportedEntities.contains(entity)) continue; + + @Nullable ServerLevel targetWorld = server.getLevel(entry.getDestination()); + if (entity != null && targetWorld != null && entity.level() == level) { + if (TRTeleporter.performTeleport(entity, targetWorld, entry.getX(), entry.getY(), entry.getZ(), entry.getyRot(), entry.getxRot(), teleportedEntities)) { + teleportedEntities.add(entity); + } + } + } + } + + // remove all entities that were teleported from the queue + teleports.removeIf(teleportEntry -> teleportedEntities.contains(teleportEntry.getEntity())); + + eventData.queuedTeleports = teleports; + } + + + } + + public void scheduleEntityTeleport(Entity entity, ResourceKey destination, double x, double y, double z, float yRot, float xRot) { + if(entity != null && !entity.level().isClientSide() && !isEntityQueuedToTeleportAlready(entity)) { + this.queuedTeleports.add(new TeleportEntry(entity, destination, x, y, z, yRot, xRot)); + } + + } + + public boolean isEntityQueuedToTeleportAlready(Entity entity) { + return this.queuedTeleports.stream().anyMatch(entry -> entry.getEntity().equals(entity)); + } + + @Override + public CompoundTag save(CompoundTag compound) { + return compound; + } + + private static final class TeleportEntry{ + + private final Entity entity; + private final ResourceKey destination; + + private final double x, y, z; + private final float yRot, xRot; + private boolean isCurrentTeleporting = false; + + public TeleportEntry(Entity entity, ResourceKey destination, double x, double y, double z, float yRot, float xRot) { + this.entity = entity; + this.destination = destination; + this.x = x; + this.y = y; + this.z = z; + this.yRot = yRot; + this.xRot = xRot; + } + + public Entity getEntity() { + return this.entity; + } + + public ResourceKey getDestination() { + return this.destination; + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + + public float getxRot() { + return xRot; + } + + public float getyRot() { + return yRot; + } + + public boolean getIsCurrentTeleporting() { + return isCurrentTeleporting; + } + + public void setIsCurrentTeleporting(boolean isCurrentTeleporting) { + this.isCurrentTeleporting = isCurrentTeleporting; + } + } +} \ No newline at end of file diff --git a/common/src/main/java/whocraft/tardis_refined/common/tardis/ExteriorShell.java b/common/src/main/java/whocraft/tardis_refined/common/tardis/ExteriorShell.java index 9ef70a595..7c21a30ac 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/tardis/ExteriorShell.java +++ b/common/src/main/java/whocraft/tardis_refined/common/tardis/ExteriorShell.java @@ -1,6 +1,8 @@ package whocraft.tardis_refined.common.tardis; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; import whocraft.tardis_refined.common.tardis.themes.DesktopTheme; public interface ExteriorShell { @@ -8,4 +10,8 @@ public interface ExteriorShell { BlockPos getExitPosition(); DesktopTheme getAssociatedTheme(); + ResourceKey getTardisId(); + + void setTardisId(ResourceKey levelKey); + } diff --git a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisExteriorManager.java b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisExteriorManager.java index 911944b47..829c480e0 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisExteriorManager.java +++ b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisExteriorManager.java @@ -118,8 +118,8 @@ public void loadData(CompoundTag tag) { } public void playSoundAtShell(SoundEvent event, SoundSource source, float volume, float pitch) { - ServerLevel lastKnownLocationLevel = lastKnownLocation.getLevel(); if (lastKnownLocation != null) { + ServerLevel lastKnownLocationLevel = lastKnownLocation.getLevel(); lastKnownLocationLevel.playSound(null, lastKnownLocation.getPosition(), event, source, volume, pitch); } } @@ -174,7 +174,7 @@ public void placeExteriorBlock(TardisLevelOperator operator, TardisNavLocation l AestheticHandler aestheticHandler = operator.getAestheticHandler(); ResourceLocation theme = (aestheticHandler.getShellTheme() != null) ? aestheticHandler.getShellTheme() : ShellTheme.FACTORY.getId(); BlockState targetBlockState = BlockRegistry.GLOBAL_SHELL_BLOCK.get().defaultBlockState() - .setValue(GlobalShellBlock.FACING, location.getDirection().getOpposite()) + .setValue(GlobalShellBlock.FACING, location.getDirection()) .setValue(GlobalShellBlock.REGEN, false) .setValue(LOCKED, operator.getExteriorManager().locked) .setValue(GlobalShellBlock.WATERLOGGED, location.getLevel().getBlockState(location.getPosition()).getFluidState().getType() == Fluids.WATER); diff --git a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisFlightEventManager.java b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisFlightEventManager.java index ff184e482..a0b10f6db 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisFlightEventManager.java +++ b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisFlightEventManager.java @@ -93,6 +93,20 @@ public boolean areDangerZoneEventsComplete() { return this.requiredDangerZoneRequests <= this.dangerZoneResponses; } + /** + * @return The total required danger zone requests the player will need to complete + */ + public int getRequiredDangerZoneRequests() { + return this.requiredDangerZoneRequests; + } + + /** + * @return The total danger zone responses the player has completed so far + */ + public int getDangerZoneResponses() { + return this.dangerZoneResponses; + } + /* * Is a prompt still within the combo time. * */ @@ -103,10 +117,49 @@ public boolean isEventInComboTime() { /* * Get the current remaining ticks of cooldown between two controls. * */ - public int getControlRequestCooldown() { + private int getControlRequestCooldown() { return (isEventInComboTime() ? 20 : 60); // This will be expanded on when Stats are added. } + /* + * Get the current remaining ticks of cooldown between two controls. + * */ + public int getCurrentControlRequestCooldown() { + return this.controlRequestCooldown; + } + + /** + * All the valid controls that can be used as a flight event and need to be interacted with + * @return a list of flight event capable controls. + */ + public List getPossibleControls() + { + return this.possibleControls; + } + + // The minimum distance that the tardis needs to travel for flight events to happen. + public int getMinDistanceForEvents() + { + return this.MIN_DISTANCE_FOR_EVENTS; + } + + // How many ticks since the last flight event prompt + public int getTicksSincePrompted() + { + return this.ticksSincePrompted; + } + + // how many ticks the tardis has been in the danger zone for + public int getTicksInTheDangerZone() + { + return this.ticksInTheDangerZone; + } + + // the danger zone shake scale + public float getDangerZoneShakeScale() + { + return this.dangerZoneShakeScale; + } /* * Calculates the number of required control requests based on the distance between the current and target location. @@ -135,9 +188,9 @@ public void calculateTravelLogic() { } - private int getBlocksPerRequest(double distance) { + public int getBlocksPerRequest(double distance) { var bpd = (int) (distance / MIN_DISTANCE_FOR_EVENTS); - return Math.min(bpd, 25); // This will be expanded once stats are added. + return Math.min(bpd, 25); // TODO: This will be expanded once stats are added. } // All the logic related to the in-flight events of the TARDIS. @@ -264,21 +317,21 @@ public void respondToWaitingControl(ControlEntity entity, ConsoleControl control } - private void onTargetReached(ControlEntity entity) { + public boolean onTargetReached(ControlEntity entity) { // Is the target acceptable? var targetPosition = operator.getPilotingManager().getTargetLocation(); if (targetPosition.getLevel().dimension() != Level.END) { operator.getLevel().playSound(null, entity.blockPosition(), SoundEvents.PLAYER_LEVELUP, SoundSource.AMBIENT, 10, 1); - return; + return true; } // Check has the dragon been beaten? if (targetPosition.getLevel().dragonFight != null) { if (((EndDragonFightAccessor) targetPosition.getLevel().dragonFight).isDragonKilled()) { operator.getLevel().playSound(null, entity.blockPosition(), SoundEvents.PLAYER_LEVELUP, SoundSource.AMBIENT, 10, 1); - return; + return true; } } @@ -294,9 +347,11 @@ private void onTargetReached(ControlEntity entity) { level.playSound(null, entity.blockPosition(), SoundRegistry.TARDIS_MISC_SPARKLE.get(), SoundSource.AMBIENT, 10, 1); level.explode(null, entity.blockPosition().getX(), entity.blockPosition().getY(), entity.blockPosition().getZ(), 0.1f, Level.ExplosionInteraction.NONE); + return false; + } - private boolean dangerZoneSecondsPast(int seconds) { + public boolean dangerZoneSecondsPast(int seconds) { return (this.ticksInTheDangerZone >= seconds * 20); } diff --git a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisInteriorManager.java b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisInteriorManager.java index a01e3f1b5..6a036089f 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisInteriorManager.java +++ b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisInteriorManager.java @@ -24,6 +24,7 @@ import whocraft.tardis_refined.common.tardis.themes.DesktopTheme; import whocraft.tardis_refined.common.tardis.themes.ShellTheme; import whocraft.tardis_refined.common.util.MiscHelper; +import whocraft.tardis_refined.common.util.TRTeleporter; import whocraft.tardis_refined.constants.NbtConstants; import java.util.ArrayList; @@ -229,12 +230,12 @@ public void tick(ServerLevel level) { desktopEntities.forEach(x -> { Vec3 offsetPos = x.position().subtract(Vec3.atCenterOf(corridorAirlockCenter.north(2))); - MiscHelper.performTeleport(x, level, 1000.5f + offsetPos.x(), 100.5f + offsetPos.y(), -1.5f + offsetPos.z(), x.getYRot(), x.getXRot()); + TRTeleporter.performTeleport(x, level, 1000.5f + offsetPos.x(), 100.5f + offsetPos.y(), -1.5f + offsetPos.z(), x.getYRot(), x.getXRot()); }); corridorEntities.forEach(x -> { Vec3 offsetPos = x.position().subtract(Vec3.atCenterOf(new BlockPos(1000, 100, -2))); - MiscHelper.performTeleport(x, level, corridorAirlockCenter.north(2).getX() + offsetPos.x() + 0.5f, corridorAirlockCenter.north(2).getY() + offsetPos.y() + 0.5f, corridorAirlockCenter.north(2).getZ() + offsetPos.z() + 0.5f, x.getYRot(), x.getXRot()); + TRTeleporter.performTeleport(x, level, corridorAirlockCenter.north(2).getX() + offsetPos.x() + 0.5f, corridorAirlockCenter.north(2).getY() + offsetPos.y() + 0.5f, corridorAirlockCenter.north(2).getZ() + offsetPos.z() + 0.5f, x.getYRot(), x.getXRot()); }); } @@ -264,7 +265,7 @@ public List getCorridorEntities(Level level) { return level.getEntitiesOfClass(LivingEntity.class, new AABB(STATIC_CORRIDOR_POSITION.north(2).west(2), STATIC_CORRIDOR_POSITION.south(2).east(2).above(4))); } - private List getAirlockEntities(Level level) { + public List getAirlockEntities(Level level) { if (corridorAirlockCenter == null) { return new ArrayList<>(); diff --git a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisPilotingManager.java b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisPilotingManager.java index a15987d87..589cf7f29 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisPilotingManager.java +++ b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisPilotingManager.java @@ -89,8 +89,8 @@ public int getCooldownTicks() { * Zero means it has only started, 1 means that cooldown has finished. * @return a percentage value between 0 - 1. */ - public int getCooldownDuration() { - return ticksSinceCrash / TICKS_COOLDOWN_MAX; + public float getCooldownDuration() { + return (float)ticksSinceCrash / (float)TICKS_COOLDOWN_MAX; } public void endCoolDown() { @@ -272,7 +272,7 @@ public TardisNavLocation findClosestValidPosition(TardisNavLocation location) { return location; } - private BlockPos getLegalPosition(Level level, BlockPos pos, int originalY) { + public BlockPos getLegalPosition(Level level, BlockPos pos, int originalY) { if (level.dimension() == Level.NETHER) { if (pos.getY() > level.getMaxBuildHeight() || originalY > level.getMaxBuildHeight()) { @@ -295,7 +295,7 @@ public boolean isSafeToLand(TardisNavLocation location) return false; } - private TardisNavLocation scanUpwardsFromCord(TardisNavLocation location, int maxHeight) { + public TardisNavLocation scanUpwardsFromCord(TardisNavLocation location, int maxHeight) { while (location.getPosition().getY() <= maxHeight) { if (isSafeToLand(location)) { return findSafeDirection(location); @@ -307,7 +307,7 @@ private TardisNavLocation scanUpwardsFromCord(TardisNavLocation location, int ma } - private TardisNavLocation scanDownwardsFromCord(TardisNavLocation location, int minHeight) { + public TardisNavLocation scanDownwardsFromCord(TardisNavLocation location, int minHeight) { while (location.getPosition().getY() >= minHeight) { if (isSafeToLand(location)) { @@ -321,7 +321,7 @@ private TardisNavLocation scanDownwardsFromCord(TardisNavLocation location, int return null; } - private TardisNavLocation findSafeDirection(TardisNavLocation location) { + public TardisNavLocation findSafeDirection(TardisNavLocation location) { Direction[] directions = new Direction[]{location.getDirection(), location.getDirection().getOpposite(), Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST}; for (Direction dir : directions) { @@ -334,7 +334,7 @@ private TardisNavLocation findSafeDirection(TardisNavLocation location) { return null; } - private boolean isSolidBlock(ServerLevel level, BlockPos pos) { + public boolean isSolidBlock(ServerLevel level, BlockPos pos) { return level.getBlockState(pos).isSolid() || level.getBlockState(pos).liquid(); } diff --git a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisWaypointManager.java b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisWaypointManager.java index 452d2a558..290370b1f 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisWaypointManager.java +++ b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisWaypointManager.java @@ -25,6 +25,14 @@ public void deleteWaypoint(String name) { waypointMap.remove(name); } + /** + * @return Map of waypoints, with string names as keys + */ + public Map getWaypointMap() + { + return this.waypointMap; + } + public Collection getWaypoints() { return waypointMap.values(); } diff --git a/common/src/main/java/whocraft/tardis_refined/common/util/LevelHelper.java b/common/src/main/java/whocraft/tardis_refined/common/util/LevelHelper.java index fde057458..d9f039aeb 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/util/LevelHelper.java +++ b/common/src/main/java/whocraft/tardis_refined/common/util/LevelHelper.java @@ -1,6 +1,7 @@ package whocraft.tardis_refined.common.util; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.world.phys.Vec3; /** Helpers related to levels **/ @@ -10,4 +11,22 @@ public static Vec3 centerPos(BlockPos pos, boolean centerY){ return new Vec3(pos.getX() + 0.5, pos.getY() + (centerY ? 0.5 : 0), pos.getZ() + 0.5); } + public static float getAdjustedRotation(float rot) { + float newR = rot % 360.0F; + if(newR < 0) + return 360.0F + newR; + + return newR; + } + + public static float getAngleFromDirection(Direction dir) { + switch(dir){ + case EAST: return 90.0F; + case SOUTH: return 180.0F; + case WEST: return 270.0F; + default: return 0.0F; + } + } + + } diff --git a/common/src/main/java/whocraft/tardis_refined/common/util/MiscHelper.java b/common/src/main/java/whocraft/tardis_refined/common/util/MiscHelper.java index 2c371be0d..89e5c0e77 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/util/MiscHelper.java +++ b/common/src/main/java/whocraft/tardis_refined/common/util/MiscHelper.java @@ -138,7 +138,7 @@ public static boolean shouldStopItem(Level level, Player player, BlockPos blockP return false; } - public static boolean shouldCancelBreaking(Level world, Player player, BlockPos pos, BlockState state) { + public static boolean shouldCancelBreaking(Level world, Entity entity, BlockPos pos, BlockState state) { if (world.dimensionTypeId() == DimensionTypes.TARDIS && world instanceof ServerLevel serverLevel) { TardisLevelOperator data = TardisLevelOperator.get(serverLevel).get(); diff --git a/common/src/main/java/whocraft/tardis_refined/common/util/TRTeleporter.java b/common/src/main/java/whocraft/tardis_refined/common/util/TRTeleporter.java index c55f7fcf4..9b892b65e 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/util/TRTeleporter.java +++ b/common/src/main/java/whocraft/tardis_refined/common/util/TRTeleporter.java @@ -1,10 +1,12 @@ package whocraft.tardis_refined.common.util; import net.minecraft.core.BlockPos; +import net.minecraft.network.protocol.game.*; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.TicketType; import net.minecraft.util.Mth; +import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.PathfinderMob; @@ -12,6 +14,13 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.pathfinder.BlockPathTypes; import net.minecraft.world.level.pathfinder.WalkNodeEvaluator; +import net.minecraft.world.phys.Vec3; +import whocraft.tardis_refined.registry.TagKeys; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; public class TRTeleporter { private static boolean canTeleportTo(BlockPos pPos, Level level, Entity entity) { @@ -25,71 +34,184 @@ private static boolean canTeleportTo(BlockPos pPos, Level level, Entity entity) } public static boolean performTeleport(Entity pEntity, ServerLevel pLevel, double pX, double pY, double pZ, float pYaw, float pPitch) { - return performTeleport(pEntity, pLevel, pX, pY, pZ, pYaw, pPitch, false); + return performTeleport(pEntity, null, pLevel, pX, pY, pZ, pYaw, pPitch, false, new HashSet<>()); } - public static boolean performTeleport(Entity pEntity, ServerLevel pLevel, double pX, double pY, double pZ, float pYaw, float pPitch, boolean safeBlockCheck) { - int xRound = (int)pX; - int yRound = (int)pY; - int zRound = (int)pZ; - BlockPos blockpos = new BlockPos(xRound, yRound, zRound); - - if (safeBlockCheck){ - if (!canTeleportTo(blockpos, pLevel, pEntity)) { - return false; - } + public static boolean performTeleport(Entity pEntity, ServerLevel pLevel, double pX, double pY, double pZ, float pYaw, float pPitch, Set teleportedEntities) { + Entity rootVehicle = pEntity.getRootVehicle(); + Entity controller = pEntity.getControllingPassenger(); + if (pEntity.isVehicle() && controller != null){ + // If there is a valid controlling passenger, this entity must be a vehicle, so we will teleport the vehicle + // The subsequent teleport logic will eject all passengers who will be placed at the vehicle's position before teleport occurs + // Since we assume the vehicle is inside a block or area where teleport is being requested, the dismounted passengers should be teleported too + return performTeleport(rootVehicle, null, pLevel, pX, pY, pZ, pYaw, pPitch, false, teleportedEntities); } + return performTeleport(pEntity, rootVehicle, pLevel, pX, pY, pZ, pYaw, pPitch, false, teleportedEntities); + } - if (!Level.isInSpawnableBounds(blockpos)) { - return false; - } else { - float f = Mth.wrapDegrees(pYaw); - float f1 = Mth.wrapDegrees(pPitch); - if (pEntity instanceof ServerPlayer serverPlayer) { - ChunkPos chunkpos = new ChunkPos(blockpos); - pLevel.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkpos, 1, pEntity.getId()); - pEntity.stopRiding(); - if (serverPlayer.isSleeping()) { - serverPlayer.stopSleepInBed(true, true); + public static boolean performTeleport(Entity pEntity, Entity vehicle, ServerLevel destination, double pX, double pY, double pZ, float pYaw, float pPitch, boolean safeBlockCheck, Set teleportedEntities) { + if (pEntity.level() instanceof ServerLevel) { + + int xRound = (int) pX; + int yRound = (int) pY; + int zRound = (int) pZ; + BlockPos blockpos = new BlockPos(xRound, yRound, zRound); + + if (teleportedEntities.size() != 0){ + if (teleportedEntities.contains(pEntity)){ //If we are calling this method by itself such as teleporting passengers, check if we have already teleported the entity + return false; } + } - if (pLevel == pEntity.level()) { - serverPlayer.connection.teleport(pX, pY, pZ, f, f1); - } else { - serverPlayer.teleportTo(pLevel, pX, pY, pZ, f, f1); + if (pEntity.getType().is(TagKeys.TARDIS_TELEPORT_BLACKLIST)) //Stop teleporting if the entity being teleported is blacklisted + return false; + + if (safeBlockCheck) { + if (!canTeleportTo(blockpos, destination, pEntity)) { + return false; } - pEntity.setYHeadRot(f); + } + + if (!Level.isInSpawnableBounds(blockpos)) { + return false; } else { - float f2 = Mth.clamp(f1, -90.0F, 90.0F); - if (pLevel == pEntity.level()) { - pEntity.moveTo(pX, pY, pZ, f, f2); - pEntity.setYHeadRot(f); - } else { - pEntity.unRide(); - Entity entity = pEntity; - pEntity = pEntity.getType().create(pLevel); - if (pEntity == null) { - return false; + Entity teleportedEntity; + List passengers = pEntity.getPassengers(); + + pEntity.unRide(); + + float updatedYRot = Mth.wrapDegrees(pYaw); + float updatedXRot = Mth.wrapDegrees(pPitch); + + if (pEntity instanceof ServerPlayer serverPlayer) { + //Always update player data, do not create new instances of the player + + if (serverPlayer.isSleeping()) { + serverPlayer.stopSleepInBed(true, true); } - pEntity.restoreFrom(entity); - pEntity.moveTo(pX, pY, pZ, f, f2); - pEntity.setYHeadRot(f); - entity.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION); - pLevel.addDuringTeleport(pEntity); + pEntity.setDeltaMovement(Vec3.ZERO); //set velocity to 0 because otherwise we will trigger the "player moved wrongly" hardcoded vanilla check which will result in the player not changing coordinates in the new dimension + + serverPlayer.connection.send(new ClientboundRespawnPacket(serverPlayer.createCommonSpawnInfo(destination), (byte)3)); + serverPlayer.connection.send(new ClientboundChangeDifficultyPacket(destination.getLevelData().getDifficulty(), destination.getLevelData().isDifficultyLocked())); + + serverPlayer.teleportTo(destination, pX, pY, pZ, updatedYRot, updatedXRot); + + serverPlayer.setPortalCooldown(); //Prevent player from being teleport by nether portal in the destination dimension + pEntity.setYHeadRot(updatedYRot); + + + //Handle player experience not getting received on client after interdimensional teleport + serverPlayer.connection.send(new ClientboundSetExperiencePacket(serverPlayer.experienceProgress, serverPlayer.totalExperience, serverPlayer.experienceLevel)); + serverPlayer.connection.send(new ClientboundPlayerAbilitiesPacket(serverPlayer.getAbilities()));//Keep abilities like creative mode flight height etc. + serverPlayer.connection.send(new ClientboundChangeDifficultyPacket(serverPlayer.level().getDifficulty(), serverPlayer.level().getLevelData().isDifficultyLocked())); + + teleportedEntity = destination.getPlayerByUUID(serverPlayer.getUUID()); + + } else { + //For non player entities, always create new instances if inter dimensional teleporting + float adjustedXRot = Mth.clamp(updatedXRot, -90.0F, 90.0F); + Vec3 oldMotion = pEntity.getDeltaMovement(); + + if (destination == pEntity.level()) { + pEntity.moveTo(pX, pY, pZ, updatedYRot, adjustedXRot); + pEntity.setYHeadRot(updatedYRot); + pEntity.setDeltaMovement(oldMotion); + pEntity.setPortalCooldown(); + teleportedEntity = pEntity; + } else { + //Get most of this logic from Entity#changeDimension which is most suitable as it has most syncing logic. However, we want to exclude the use of PortalInfo as it plays the vanilla portal sounds + Entity newEntity = pEntity; + + newEntity = newEntity.getType().create(destination); + if (newEntity == null) { + return false; + } + + newEntity.restoreFrom(pEntity); + newEntity.moveTo(pX, pY, pZ, updatedYRot, adjustedXRot); + newEntity.setDeltaMovement(oldMotion); + newEntity.setPortalCooldown(); + destination.addDuringTeleport(newEntity); + + teleportedEntity = newEntity; + + pEntity.remove(Entity.RemovalReason.CHANGED_DIMENSION); // equivalent to Entity#removeAfterChangingDimensions + + } } - } - if (!(pEntity instanceof LivingEntity) || !((LivingEntity) pEntity).isFallFlying()) { - pEntity.setDeltaMovement(pEntity.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D)); - pEntity.setOnGround(true); - } + if (teleportedEntity != null){ - if (pEntity instanceof PathfinderMob) { - ((PathfinderMob) pEntity).getNavigation().stop(); + // update set to keep track of entities teleported + teleportedEntities.add(pEntity); + + ChunkPos chunkpos = new ChunkPos(BlockPos.containing(pX, pY, pZ)); + destination.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkpos, 1, pEntity.getId()); + + //Handle Elytra flying + if (!(teleportedEntity instanceof LivingEntity) || !((LivingEntity) teleportedEntity).isFallFlying()) { + teleportedEntity.setDeltaMovement(teleportedEntity.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D)); + teleportedEntity.setOnGround(true); + } + + if (teleportedEntity instanceof PathfinderMob) { + ((PathfinderMob) teleportedEntity).getNavigation().stop(); + } + + if (vehicle != null){ + if (!vehicle.equals(teleportedEntity)) { // DO NOT REMOVE THIS CHECK - used to prevent the entity riding itself because when we teleport a player it will have a root vehicle which is itself + teleportedEntity.startRiding(vehicle); + } + } + + //Handle active potion effects + if(teleportedEntity instanceof LivingEntity livingEntity) { + if (livingEntity instanceof ServerPlayer serverPlayer) { + for(MobEffectInstance effectInstance : new ArrayList<>(livingEntity.getActiveEffects())) { + serverPlayer.connection.send(new ClientboundUpdateMobEffectPacket(serverPlayer.getId(), effectInstance)); + } + } + else { + reAddStatusEffectTempFix(livingEntity); + } + } + + //Handle teleporting any entities that are riding this entity by teleporting them too + if (passengers.size() != 0) { + passengers.forEach(passenger -> performTeleport(passenger, teleportedEntity, destination, pX, pY, pZ, pYaw, pPitch, safeBlockCheck, teleportedEntities)); + } + else { //If all passengers are teleported (empty list), reset the time that the dimension had no players or forced chunks in it + ((ServerLevel)teleportedEntity.level()).resetEmptyTime(); + destination.resetEmptyTime(); + } + return true; + } } + } + return false; + } - return true; + /** + * Temporary fix until Mojang patches the bug that makes potion effect icons disappear when changing dimension. + * To fix it ourselves, we remove the effect and re-add it to the entity. + */ + private static void reAddStatusEffectTempFix(LivingEntity livingEntity) { + //re-adds potion effects so the icon remains instead of disappearing when changing dimensions due to a bug + ArrayList effectInstanceList = new ArrayList<>(livingEntity.getActiveEffects()); + for (int i = effectInstanceList.size() - 1; i >= 0; i--) { + MobEffectInstance effectInstance = effectInstanceList.get(i); + if (effectInstance != null) { + livingEntity.removeEffect(effectInstance.getEffect()); + livingEntity.addEffect( + new MobEffectInstance( + effectInstance.getEffect(), + effectInstance.getDuration(), + effectInstance.getAmplifier(), + effectInstance.isAmbient(), + effectInstance.isVisible(), + effectInstance.showIcon())); + } } } diff --git a/common/src/main/java/whocraft/tardis_refined/common/util/TardisHelper.java b/common/src/main/java/whocraft/tardis_refined/common/util/TardisHelper.java index cbd0f384d..cc4c45341 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/util/TardisHelper.java +++ b/common/src/main/java/whocraft/tardis_refined/common/util/TardisHelper.java @@ -2,25 +2,28 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.material.Fluids; -import whocraft.tardis_refined.TardisRefined; +import net.minecraft.world.phys.Vec3; +import whocraft.tardis_refined.api.event.TardisEvents; import whocraft.tardis_refined.common.block.shell.GlobalShellBlock; import whocraft.tardis_refined.common.block.shell.ShellBaseBlock; import whocraft.tardis_refined.common.blockentity.shell.GlobalShellBlockEntity; -import whocraft.tardis_refined.common.blockentity.shell.ShellBaseBlockEntity; import whocraft.tardis_refined.common.capability.TardisLevelOperator; import whocraft.tardis_refined.common.dimension.DimensionHandler; +import whocraft.tardis_refined.common.dimension.TardisTeleportData; import whocraft.tardis_refined.common.tardis.TardisArchitectureHandler; -import whocraft.tardis_refined.common.tardis.TardisDesktops; import whocraft.tardis_refined.common.tardis.TardisNavLocation; import whocraft.tardis_refined.common.tardis.manager.TardisExteriorManager; import whocraft.tardis_refined.common.tardis.manager.TardisInteriorManager; @@ -28,7 +31,6 @@ import whocraft.tardis_refined.common.tardis.themes.DesktopTheme; import whocraft.tardis_refined.registry.BlockRegistry; -import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import static whocraft.tardis_refined.common.block.shell.ShellBaseBlock.LOCKED; @@ -102,4 +104,58 @@ public static boolean createTardis(BlockPos blockPos, ServerLevel serverLevel, R return false; } + + public static MutableComponent createTardisIdComponent(ResourceLocation levelId){ + String id = levelId.toString(); + String displayId = levelId.getPath().substring(0, 5); + MutableComponent tardisId = CommandHelper.createComponentWithTooltip(displayId, id); + return tardisId; + } + + public static boolean teleportEntityTardis(TardisLevelOperator cap, Entity entity, TardisNavLocation sourceLocation, TardisNavLocation destinationLocation, boolean enterTardis){ + + if (entity.level() instanceof ServerLevel teleportingEntityLevel){ + + BlockPos destinationPos = destinationLocation.getPosition(); + ServerLevel destinationLevel = destinationLocation.getLevel(); + Direction destinationDirection = destinationLocation.getDirection(); + + + BlockPos targetTeleportPos = destinationPos; + + //Calculate entity motion and rotation, taking into account for the internal door's direction and rotation + float entityYRot = entity.getYRot(); + float destinationRotationYaw = destinationDirection.toYRot(); + //Calculate the difference between the entity's rotation and the destination direction's rotation. Get the difference and find the final rotation that preserves the entities' rotation but facing the direction at the destination + float diff = LevelHelper.getAdjustedRotation(entityYRot) - LevelHelper.getAdjustedRotation(destinationRotationYaw); + + float adjustedRotationYaw = LevelHelper.getAngleFromDirection(destinationDirection) + diff; + + if (entity.getType().getDimensions().width > 1F){ + targetTeleportPos = destinationPos.offset(destinationDirection.getNormal()); + } + + BlockPos finalTeleportPos = targetTeleportPos; + + Vec3 centredTarget = LevelHelper.centerPos(finalTeleportPos, false); + + TardisTeleportData.getOrCreate(teleportingEntityLevel).scheduleEntityTeleport(entity, destinationLevel.dimension(), centredTarget.x(), centredTarget.y(), centredTarget.z(), adjustedRotationYaw, entity.getXRot()); + + //Fire exit or enter events + if (entity instanceof LivingEntity livingEntity) { + if (enterTardis){ + TardisEvents.TARDIS_ENTRY_EVENT.invoker().onEnterTardis(cap, livingEntity, sourceLocation, destinationLocation); + } + else { + TardisEvents.TARDIS_EXIT_EVENT.invoker().onExitTardis(cap, livingEntity, sourceLocation, destinationLocation); + } + } + + cap.tardisClientData().sync(); + + return true; + } + return false; + + } } diff --git a/common/src/main/java/whocraft/tardis_refined/constants/ModMessages.java b/common/src/main/java/whocraft/tardis_refined/constants/ModMessages.java index 495967291..6f745b528 100644 --- a/common/src/main/java/whocraft/tardis_refined/constants/ModMessages.java +++ b/common/src/main/java/whocraft/tardis_refined/constants/ModMessages.java @@ -37,8 +37,19 @@ public class ModMessages { public static final String UI_MONITOR_UPLOAD_WAYPOINTS = ui("monitor.upload.waypoints"); public static final String UI_MONITOR_UPLOAD_COORDS = ui("monitor.upload.coords"); public static final String UI_MONITOR_NO_WAYPOINTS = ui("monitor.no.waypoints"); - public static final String UI_MONITOR_UPLOAD = ui("monitor.upload"); - public static final String UI_MONITOR_ISSUES = ui("monitor.issues"); + public static final String UI_MONITOR_WAYPOINT_UPLOAD = ui("monitor.waypoints.upload"); + public static final String UI_MONITOR_WAYPOINT_SUBMIT = ui("monitor.waypoints.submit"); + public static final String UI_MONITOR_WAYPOINT_DIMENSION = ui("monitor.waypoints.dimension"); + public static final String UI_MONITOR_WAYPOINT_DIRECTION = ui("monitor.waypoints.direction"); + + public static final String VANILLA_SELECT_WORLD = "selectWorld.search"; + public static final String UI_MONITOR_ISSUES = ui("monitor.waypoints.issues"); + + public static final String UI_MONITOR_WAYPOINT_ISSUE_NAME = ui("monitor.waypoints.issues.name"); + public static final String UI_MONITOR_WAYPOINT_ISSUE_X = ui("monitor.waypoints.issues.x"); + public static final String UI_MONITOR_WAYPOINT_ISSUE_Y = ui("monitor.waypoints.issues.y"); + public static final String UI_MONITOR_WAYPOINT_ISSUE_Z = ui("monitor.waypoints.issues.z"); + public static final String UI_MONITOR_WAYPOINT_NAME = ui("monitor.waypoint_name"); public static final String UI_UPGRADES = ui("upgrades"); public static final String UI_UPGRADES_BUY = ui("upgrades.buy_ability"); diff --git a/common/src/main/java/whocraft/tardis_refined/registry/BlockEntityRegistry.java b/common/src/main/java/whocraft/tardis_refined/registry/BlockEntityRegistry.java index f55b33677..9e2b4e924 100644 --- a/common/src/main/java/whocraft/tardis_refined/registry/BlockEntityRegistry.java +++ b/common/src/main/java/whocraft/tardis_refined/registry/BlockEntityRegistry.java @@ -4,8 +4,8 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import whocraft.tardis_refined.TardisRefined; import whocraft.tardis_refined.common.blockentity.console.GlobalConsoleBlockEntity; -import whocraft.tardis_refined.common.blockentity.desktop.InternalDoorBlockEntity; -import whocraft.tardis_refined.common.blockentity.desktop.door.RootShellDoorBlockEntity; +import whocraft.tardis_refined.common.blockentity.door.InternalDoorBlockEntity; +import whocraft.tardis_refined.common.blockentity.door.RootShellDoorBlockEntity; import whocraft.tardis_refined.common.blockentity.device.ConsoleConfigurationBlockEntity; import whocraft.tardis_refined.common.blockentity.device.FlightDetectorBlockEntity; import whocraft.tardis_refined.common.blockentity.door.BulkHeadDoorBlockEntity; @@ -25,8 +25,6 @@ public class BlockEntityRegistry { public static final RegistrySupplier> GLOBAL_SHELL_BLOCK = BLOCK_ENTITY_TYPES.register("tardis_shell", () -> BlockEntityType.Builder.of(GlobalShellBlockEntity::new, BlockRegistry.GLOBAL_SHELL_BLOCK.get()).build(null)); public static final RegistrySupplier> GLOBAL_DOOR_BLOCK = BLOCK_ENTITY_TYPES.register("tardis_door", () -> BlockEntityType.Builder.of(GlobalDoorBlockEntity::new, BlockRegistry.GLOBAL_DOOR_BLOCK.get()).build(null)); - public static final RegistrySupplier> TARDIS_INTERNAL_DOOR = BLOCK_ENTITY_TYPES.register("internal_door_block", () -> BlockEntityType.Builder.of(InternalDoorBlockEntity::new, BlockRegistry.INTERNAL_DOOR_BLOCK.get()).build(null)); - public static final RegistrySupplier> ROOT_SHELL_DOOR = BLOCK_ENTITY_TYPES.register("root_shell_door", () -> BlockEntityType.Builder.of(RootShellDoorBlockEntity::new, BlockRegistry.ROOT_SHELL_DOOR.get()).build(null)); public static final RegistrySupplier> ROOT_PLANT = BLOCK_ENTITY_TYPES.register("root_plant", () -> BlockEntityType.Builder.of(RootPlantBlockEntity::new, BlockRegistry.ROOT_PLANT_BLOCK.get()).build(null)); diff --git a/common/src/main/java/whocraft/tardis_refined/registry/BlockRegistry.java b/common/src/main/java/whocraft/tardis_refined/registry/BlockRegistry.java index eb81ffb0b..ee176b2bf 100644 --- a/common/src/main/java/whocraft/tardis_refined/registry/BlockRegistry.java +++ b/common/src/main/java/whocraft/tardis_refined/registry/BlockRegistry.java @@ -44,10 +44,9 @@ private static RegistrySupplier register(String id, Supplie // Shell Blocks public static final RegistrySupplier ROOT_SHELL_BLOCK = register("root_shell", () -> new RootedShellBlock(BlockBehaviour.Properties.of().noOcclusion().strength(1000, 1000).sound(SoundType.CORAL_BLOCK)), true, true); public static final RegistrySupplier GLOBAL_SHELL_BLOCK = register("tardis_shell", () -> new GlobalShellBlock(BlockBehaviour.Properties.of().noOcclusion().strength(1000, 1000).sound(SoundType.STONE)), false, false); - public static final RegistrySupplier GLOBAL_DOOR_BLOCK = register("tardis_door", () -> new GlobalDoorBlock(BlockBehaviour.Properties.of().noOcclusion().strength(10, 10).sound(SoundType.STONE)), true, true); // Interior - public static final RegistrySupplier INTERNAL_DOOR_BLOCK = register("internal_door_block", () -> new InternalDoorBlock(BlockBehaviour.Properties.of().noOcclusion()), true, false); + public static final RegistrySupplier GLOBAL_DOOR_BLOCK = register("tardis_door", () -> new GlobalDoorBlock(BlockBehaviour.Properties.of().noOcclusion().strength(10, 10).sound(SoundType.STONE)), true, true); public static final RegistrySupplier ROOT_SHELL_DOOR = register("root_shell_door", () -> new RootShellDoorBlock(BlockBehaviour.Properties.of().noOcclusion().strength(1000, 1000)), false, true); // Generation Blocks diff --git a/common/src/main/java/whocraft/tardis_refined/registry/TagKeys.java b/common/src/main/java/whocraft/tardis_refined/registry/TagKeys.java index 3c21f5e68..fbe610221 100644 --- a/common/src/main/java/whocraft/tardis_refined/registry/TagKeys.java +++ b/common/src/main/java/whocraft/tardis_refined/registry/TagKeys.java @@ -1,12 +1,19 @@ package whocraft.tardis_refined.registry; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.biome.Biome; +import whocraft.tardis_refined.TardisRefined; import whocraft.tardis_refined.common.util.RegistryHelper; public class TagKeys { public static TagKey IS_MOUNTAIN_OR_OCEAN = RegistryHelper.makeGenericBiomeTagCollection("is_mountain_or_ocean"); public static TagKey TARDIS_ROOT_CLUSTER = RegistryHelper.makeBiomeTagForFeature("tardis_root_cluster"); + /** Entity tag used to blacklist entities from being teleported into the Tardis via the doors or being landed on by the exterior shell*/ + public static final TagKey> TARDIS_TELEPORT_BLACKLIST = TagKey.create(Registries.ENTITY_TYPE, new ResourceLocation(TardisRefined.MODID, "tardis_teleport_blacklist")); + public static void init(){} } \ No newline at end of file diff --git a/fabric/src/main/java/whocraft/tardis_refined/common/capability/fabric/TardisLevelOperatorDummy.java b/fabric/src/main/java/whocraft/tardis_refined/common/capability/fabric/TardisLevelOperatorDummy.java index d4965b552..375b4973f 100644 --- a/fabric/src/main/java/whocraft/tardis_refined/common/capability/fabric/TardisLevelOperatorDummy.java +++ b/fabric/src/main/java/whocraft/tardis_refined/common/capability/fabric/TardisLevelOperatorDummy.java @@ -1,7 +1,12 @@ package whocraft.tardis_refined.common.capability.fabric; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.Level; +import whocraft.tardis_refined.TardisRefined; +import whocraft.tardis_refined.common.capability.TardisLevelOperator; + +import java.util.Optional; public class TardisLevelOperatorDummy extends TardisLevelOperatorImpl { @@ -9,6 +14,18 @@ public TardisLevelOperatorDummy(Level level) { super(level); } + public static Optional get(ServerLevel level) { + if(level == null) { + return Optional.empty(); + } + try { + return Optional.of(TRComponents.TARDIS_DATA.get(level)); + } catch (Exception e) { + TardisRefined.LOGGER.info(e.getMessage()); + return Optional.empty(); + } + } + @Override public void writeToNbt(CompoundTag tag) { diff --git a/fabric/src/main/java/whocraft/tardis_refined/common/capability/fabric/TardisLevelOperatorImpl.java b/fabric/src/main/java/whocraft/tardis_refined/common/capability/fabric/TardisLevelOperatorImpl.java index 5856cde58..53fdd3947 100644 --- a/fabric/src/main/java/whocraft/tardis_refined/common/capability/fabric/TardisLevelOperatorImpl.java +++ b/fabric/src/main/java/whocraft/tardis_refined/common/capability/fabric/TardisLevelOperatorImpl.java @@ -17,6 +17,9 @@ public TardisLevelOperatorImpl(Level level) { } public static Optional get(ServerLevel level) { + if(level == null) { + return Optional.empty(); + } try { return Optional.of(TRComponents.TARDIS_DATA.get(level)); } catch (Exception e) { diff --git a/fabric/src/main/java/whocraft/tardis_refined/fabric/events/ModEvents.java b/fabric/src/main/java/whocraft/tardis_refined/fabric/events/ModEvents.java index 9bdd59978..37198c60d 100644 --- a/fabric/src/main/java/whocraft/tardis_refined/fabric/events/ModEvents.java +++ b/fabric/src/main/java/whocraft/tardis_refined/fabric/events/ModEvents.java @@ -9,7 +9,7 @@ import whocraft.tardis_refined.client.TardisClientData; import whocraft.tardis_refined.command.TardisRefinedCommand; import whocraft.tardis_refined.common.capability.TardisLevelOperator; -import whocraft.tardis_refined.common.dimension.DelayedTeleportData; +import whocraft.tardis_refined.common.dimension.TardisTeleportData; import whocraft.tardis_refined.common.dimension.fabric.DimensionHandlerImpl; import whocraft.tardis_refined.common.util.MiscHelper; import whocraft.tardis_refined.registry.DimensionTypes; @@ -23,7 +23,7 @@ public static void addCommonEvents() { PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, blockEntity) -> !MiscHelper.shouldCancelBreaking(world, player, pos, state)); - END_WORLD_TICK.register(DelayedTeleportData::tick); + END_WORLD_TICK.register(TardisTeleportData::tick); START_WORLD_TICK.register(world -> { if (world.dimensionTypeId().location() == DimensionTypes.TARDIS.location()) { TardisLevelOperator.get(world).get().tick(world); diff --git a/forge/src/generated/resources/assets/tardis_refined/lang/en_us.json b/forge/src/generated/resources/assets/tardis_refined/lang/en_us.json index ad6ae38f9..bfd62e9ec 100644 --- a/forge/src/generated/resources/assets/tardis_refined/lang/en_us.json +++ b/forge/src/generated/resources/assets/tardis_refined/lang/en_us.json @@ -98,17 +98,24 @@ "ui.tardis_refined.monitor.desktop_cancel.title": "OPERATION IN PROGRESS", "ui.tardis_refined.monitor.desktop_cancel_description": "Systems disabled as a Desktop reconfiguration has been scheduled.", "ui.tardis_refined.monitor.external_shell": "EXTERNAL SHELL CONFIGURATION", - "ui.tardis_refined.monitor.issues": "Issues:", "ui.tardis_refined.monitor.list.selection": "Currently selected: &s", "ui.tardis_refined.monitor.main.destination": "Destination", "ui.tardis_refined.monitor.main.gps": "GPS", "ui.tardis_refined.monitor.main_title": "COMPUTER BANK", "ui.tardis_refined.monitor.no.waypoints": "No Waypoints Saved!", - "ui.tardis_refined.monitor.upload": "Upload", "ui.tardis_refined.monitor.upload.coords": "COORD NAVIGATION", "ui.tardis_refined.monitor.upload.waypoints": "WAYPOINT NAVIGATION", "ui.tardis_refined.monitor.waypoint_name": "Waypoint Name:", "ui.tardis_refined.monitor.waypoints": "WAYPOINTS", + "ui.tardis_refined.monitor.waypoints.dimension": "Dimension", + "ui.tardis_refined.monitor.waypoints.direction": "Direction", + "ui.tardis_refined.monitor.waypoints.issues": "Issues:", + "ui.tardis_refined.monitor.waypoints.issues.name": "Invalid waypoint name", + "ui.tardis_refined.monitor.waypoints.issues.x": "Invalid X value", + "ui.tardis_refined.monitor.waypoints.issues.y": "Invalid Y value", + "ui.tardis_refined.monitor.waypoints.issues.z": "Invalid Z value", + "ui.tardis_refined.monitor.waypoints.submit": "Submit", + "ui.tardis_refined.monitor.waypoints.upload": "Upload", "ui.tardis_refined.no_installed_subsystems": "No Available Sub-Systems", "ui.tardis_refined.shell_selection": "EXTERNAL SHELL CONFIGURATION", "ui.tardis_refined.upgrades": "Tardis Upgrades", diff --git a/forge/src/main/java/whocraft/tardis_refined/common/data/LangProviderEnglish.java b/forge/src/main/java/whocraft/tardis_refined/common/data/LangProviderEnglish.java index 9c371e306..1e71a48a6 100644 --- a/forge/src/main/java/whocraft/tardis_refined/common/data/LangProviderEnglish.java +++ b/forge/src/main/java/whocraft/tardis_refined/common/data/LangProviderEnglish.java @@ -48,7 +48,6 @@ protected void addTranslations() { add(BlockRegistry.ROOT_SHELL_BLOCK.get(), "Root Shell"); add(BlockRegistry.TERRAFORMER_BLOCK.get(), "Terraformer"); add(BlockRegistry.GLOBAL_CONSOLE_BLOCK.get(), "Console"); - add(BlockRegistry.INTERNAL_DOOR_BLOCK.get(), "Internal Door"); add(BlockRegistry.GLOBAL_DOOR_BLOCK.get(), "Tardis Door"); add(BlockRegistry.ROOT_SHELL_DOOR.get(), "Root Door"); add(BlockRegistry.AIR_LOCK_GENERATION_BLOCK.get(), "Air Lock Generator"); @@ -134,8 +133,15 @@ protected void addTranslations() { add(ModMessages.UI_DESKTOP_CANCEL_DESKTOP, "Would you like to cancel the upcoming reconfiguration?"); add(ModMessages.UI_DESKTOP_CANCEL, "Cancel Desktop Reconfiguration"); add(ModMessages.UI_MONITOR_NO_WAYPOINTS, "No Waypoints Saved!"); - add(ModMessages.UI_MONITOR_UPLOAD, "Upload"); + add(ModMessages.UI_MONITOR_WAYPOINT_UPLOAD, "Upload"); + add(ModMessages.UI_MONITOR_WAYPOINT_SUBMIT, "Submit"); + add(ModMessages.UI_MONITOR_WAYPOINT_DIMENSION, "Dimension"); + add(ModMessages.UI_MONITOR_WAYPOINT_DIRECTION, "Direction"); add(ModMessages.UI_MONITOR_ISSUES, "Issues:"); + add(ModMessages.UI_MONITOR_WAYPOINT_ISSUE_NAME, "Invalid waypoint name"); + add(ModMessages.UI_MONITOR_WAYPOINT_ISSUE_X, "Invalid X value"); + add(ModMessages.UI_MONITOR_WAYPOINT_ISSUE_Y, "Invalid Y value"); + add(ModMessages.UI_MONITOR_WAYPOINT_ISSUE_Z, "Invalid Z value"); add(ModMessages.UI_MONITOR_WAYPOINT_NAME, "Waypoint Name:"); add(ModMessages.UI_UPGRADES, "Tardis Upgrades"); add(ModMessages.UI_UPGRADES_BUY, "Purchase Upgrade?"); diff --git a/forge/src/main/java/whocraft/tardis_refined/common/data/ProviderEntityTags.java b/forge/src/main/java/whocraft/tardis_refined/common/data/ProviderEntityTags.java index f25b88d47..ccfa16f3e 100644 --- a/forge/src/main/java/whocraft/tardis_refined/common/data/ProviderEntityTags.java +++ b/forge/src/main/java/whocraft/tardis_refined/common/data/ProviderEntityTags.java @@ -11,6 +11,7 @@ import org.jetbrains.annotations.Nullable; import whocraft.tardis_refined.TardisRefined; import whocraft.tardis_refined.registry.EntityRegistry; +import whocraft.tardis_refined.registry.TagKeys; import java.util.concurrent.CompletableFuture; @@ -18,6 +19,8 @@ public class ProviderEntityTags extends EntityTypeTagsProvider { public static final TagKey> ENTITY_BLACKLIST = TagKey.create(Registries.ENTITY_TYPE, new ResourceLocation("carryon", "entity_blacklist")); + + public ProviderEntityTags(PackOutput output, CompletableFuture completableFuture, @Nullable ExistingFileHelper existingFileHelper) { super(output, completableFuture, TardisRefined.MODID, existingFileHelper); } @@ -26,5 +29,10 @@ public ProviderEntityTags(PackOutput output, CompletableFuture