From ee81ad9783749b4d33e75a598b682b8cd9d85c85 Mon Sep 17 00:00:00 2001 From: Craig Date: Tue, 26 Nov 2024 13:41:06 +0000 Subject: [PATCH] - Fixed villagers being strange about being Tardis Pilots (I would be too, I don't blame them) - Fixed Villager path finding - Sped up gravity well --- changelog.md | 7 +-- .../tardis_refined/common/GravityClient.java | 3 +- .../block/console/GlobalConsoleBlock.java | 7 ++- .../capability/player/TardisPlayerInfo.java | 12 +++-- .../common/mixin/VillagerMixin.java | 11 ++-- .../tardis/TardisArchitectureHandler.java | 1 - .../tardis/manager/TardisInteriorManager.java | 8 +++ .../villager/FlyTardisAtPOI.java | 53 ++++++++++++++++--- 8 files changed, 76 insertions(+), 26 deletions(-) diff --git a/changelog.md b/changelog.md index 72f3f355f..5bac09eb1 100644 --- a/changelog.md +++ b/changelog.md @@ -9,8 +9,8 @@ - land pad dont work and crash on server [#377](https://github.com/WhoCraft/TardisRefined/issues/377) - tardis is damaged [#351](https://github.com/WhoCraft/TardisRefined/issues/351) - Diagonal Windows makes it impossible to craft the terraformer [#383](https://github.com/WhoCraft/TardisRefined/issues/383) -- relogging causes Tardis Dance events to not occur [#387](https://github.com/WhoCraft/TardisRefined/issues/387) -- Console cannot be removed/changed with the console configurator outside of the tardis dimension [#380](https://github.com/WhoCraft/TardisRefined/issues/380) +- relogging causes TARDIS Dance events to not occur [#387](https://github.com/WhoCraft/TardisRefined/issues/387) +- Console cannot be removed/changed with the console configurator outside the TARDIS dimension [#380](https://github.com/WhoCraft/TardisRefined/issues/380) ## Gameplay changes - Standing in a Crashed smoke of a crashed TARDIS will cause 0.5 damage to the player for the duration their standing in it @@ -18,4 +18,5 @@ - Recovery Progress of crashed TARDIS is now displayed on Key tooltip - You can now view your TARDIS exterior via the Monitor - Holographic exteriors on consoles now spin according to throttle -- Improved UI for Gravity Shaft \ No newline at end of file +- Improved UI for Gravity Shaft +- Speed up downwards descent for Gravity Shaft \ No newline at end of file diff --git a/common/src/main/java/whocraft/tardis_refined/common/GravityClient.java b/common/src/main/java/whocraft/tardis_refined/common/GravityClient.java index df35fbd18..8c9e497c5 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/GravityClient.java +++ b/common/src/main/java/whocraft/tardis_refined/common/GravityClient.java @@ -27,7 +27,8 @@ public static void moveGravity(Player player, CallbackInfo info) { player.setDeltaMovement(deltaMovement.add(0, easeMovement(), 0)); info.cancel(); } else if (options.keyShift.isDown()) { - player.setDeltaMovement(deltaMovement.add(0, -easeMovement(), 0)); + player.setPose(Pose.STANDING); + player.setDeltaMovement(deltaMovement.add(0, -(easeMovement() * 5), 0)); info.cancel(); } else { player.setDeltaMovement(deltaMovement.x, 0, deltaMovement.z); diff --git a/common/src/main/java/whocraft/tardis_refined/common/block/console/GlobalConsoleBlock.java b/common/src/main/java/whocraft/tardis_refined/common/block/console/GlobalConsoleBlock.java index 4cb6977cc..e1865f877 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/block/console/GlobalConsoleBlock.java +++ b/common/src/main/java/whocraft/tardis_refined/common/block/console/GlobalConsoleBlock.java @@ -13,6 +13,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Items; import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.BaseEntityBlock; @@ -23,6 +24,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; @@ -207,5 +209,8 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP return InteractionResult.sidedSuccess(true); //Use InteractionResult.sidedSuccess(true) for client side. Stops hand swinging twice. We don't want to use InteractionResult.SUCCESS because the client calls SUCCESS, so the server side calling it too sends the hand swinging packet twice. } - + @Override + public boolean isPathfindable(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, PathComputationType pathComputationType) { + return false; + } } diff --git a/common/src/main/java/whocraft/tardis_refined/common/capability/player/TardisPlayerInfo.java b/common/src/main/java/whocraft/tardis_refined/common/capability/player/TardisPlayerInfo.java index d16c3a925..423e310da 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/capability/player/TardisPlayerInfo.java +++ b/common/src/main/java/whocraft/tardis_refined/common/capability/player/TardisPlayerInfo.java @@ -1,6 +1,7 @@ package whocraft.tardis_refined.common.capability.player; import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.commands.arguments.EntityAnchorArgument; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -11,6 +12,8 @@ import net.minecraft.world.entity.player.Abilities; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.GameType; +import net.minecraft.world.phys.Vec3; +import whocraft.tardis_refined.common.blockentity.console.GlobalConsoleBlockEntity; import whocraft.tardis_refined.common.blockentity.door.TardisInternalDoor; import whocraft.tardis_refined.common.capability.tardis.TardisLevelOperator; import whocraft.tardis_refined.common.network.messages.player.SyncTardisPlayerInfoMessage; @@ -62,7 +65,6 @@ public void updatePlayerAbilities(ServerPlayer player, Abilities abilities, bool abilities.instabuild = false; abilities.invulnerable = true; abilities.flying = true; - player.setNoGravity(true); } else { player.gameMode.getGameModeForPlayer().updatePlayerAbilities(abilities); @@ -119,13 +121,13 @@ public void setPlayerPreviousPos(BlockPos playerPreviousPos) { @Override public void endPlayerForInspection(ServerPlayer serverPlayer, TardisLevelOperator tardisLevelOperator) { - TardisInternalDoor internalDoor = tardisLevelOperator.getInternalDoor(); BlockPos targetPosition = getPlayerPreviousPos(); - Direction doorDirection = internalDoor != null ? internalDoor.getTeleportRotation() : serverPlayer.getDirection(); ServerLevel tardisDimensionLevel = serverPlayer.server.getLevel(tardisLevelOperator.getLevelKey()); - TardisNavLocation targetLocation = new TardisNavLocation(targetPosition, doorDirection, tardisDimensionLevel); + TardisNavLocation console = tardisLevelOperator.getPilotingManager().getCurrentLocation(); + + TardisNavLocation targetLocation = new TardisNavLocation(targetPosition, Direction.NORTH, tardisDimensionLevel); TardisNavLocation sourceLocation = tardisLevelOperator.getPilotingManager().getCurrentLocation(); TardisHelper.teleportEntityTardis(tardisLevelOperator, serverPlayer, sourceLocation, targetLocation, true); @@ -133,6 +135,8 @@ public void endPlayerForInspection(ServerPlayer serverPlayer, TardisLevelOperato updatePlayerAbilities(serverPlayer, serverPlayer.getAbilities(), false); serverPlayer.onUpdateAbilities(); + serverPlayer.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3(console.getPosition().getX(), console.getPosition().getY(), console.getPosition().getZ())); + // Clear the viewed TARDIS UUID setViewedTardis(null); diff --git a/common/src/main/java/whocraft/tardis_refined/common/mixin/VillagerMixin.java b/common/src/main/java/whocraft/tardis_refined/common/mixin/VillagerMixin.java index 62f2a9812..bc7b289eb 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/mixin/VillagerMixin.java +++ b/common/src/main/java/whocraft/tardis_refined/common/mixin/VillagerMixin.java @@ -19,14 +19,9 @@ public void tick(CallbackInfo ci) { if (villager.level() instanceof ServerLevel serverLevel) { TardisLevelOperator.get(serverLevel).ifPresent(tardisLevelOperator -> { - - if (tardisLevelOperator.getPilotingManager().isInFlight()) { - if (villager.getVillagerData().getProfession() == TRVillagerProfession.PILOT.get() && !villager.getBrain().isActive(Activity.WORK)) { - villager.getBrain().setDefaultActivity(Activity.WORK); - villager.getBrain().setActiveActivityIfPossible(Activity.WORK); - } else { - villager.getVillagerData().setProfession(TRVillagerProfession.PILOT.get()); - } + if (!villager.getBrain().isActive(Activity.WORK)) { + villager.getBrain().setDefaultActivity(Activity.WORK); + villager.getBrain().setActiveActivityIfPossible(Activity.WORK); } }); } diff --git a/common/src/main/java/whocraft/tardis_refined/common/tardis/TardisArchitectureHandler.java b/common/src/main/java/whocraft/tardis_refined/common/tardis/TardisArchitectureHandler.java index bfcc1ab20..3ab2001ed 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/tardis/TardisArchitectureHandler.java +++ b/common/src/main/java/whocraft/tardis_refined/common/tardis/TardisArchitectureHandler.java @@ -23,7 +23,6 @@ public class TardisArchitectureHandler { public static final BlockPos DESKTOP_CENTER_POS = new BlockPos(0, 100, 0); public static final BlockPos EYE_OF_HARMONY_PLACEMENT = new BlockPos(991,41,31); - public static final int INTERIOR_SIZE = 150; public static String currentArsStage = "one"; 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 0878c764e..14c70c5fa 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 @@ -412,6 +412,14 @@ public void generateDesktop(DesktopTheme theme) { } } + public boolean isHasGeneratedCorridors() { + return hasGeneratedCorridors; + } + + public void setHasGeneratedCorridors(boolean hasGeneratedCorridors) { + this.hasGeneratedCorridors = hasGeneratedCorridors; + } + /** Prepares the Tardis for desktop generation but doesn't actually start it. Handles cooldowns etc.*/ public void prepareDesktop(DesktopTheme theme) { this.preparedTheme = theme; diff --git a/common/src/main/java/whocraft/tardis_refined/villager/FlyTardisAtPOI.java b/common/src/main/java/whocraft/tardis_refined/villager/FlyTardisAtPOI.java index 5b96d3171..9bf72b2cd 100644 --- a/common/src/main/java/whocraft/tardis_refined/villager/FlyTardisAtPOI.java +++ b/common/src/main/java/whocraft/tardis_refined/villager/FlyTardisAtPOI.java @@ -1,12 +1,17 @@ package whocraft.tardis_refined.villager; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.core.GlobalPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.ai.Brain; +import net.minecraft.world.entity.ai.behavior.BlockPosTracker; import net.minecraft.world.entity.ai.behavior.WorkAtPoi; import net.minecraft.world.entity.ai.memory.MemoryModuleType; import net.minecraft.world.entity.npc.Villager; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; +import whocraft.tardis_refined.common.block.device.ConsoleConfigurationBlock; import whocraft.tardis_refined.common.blockentity.console.GlobalConsoleBlockEntity; import whocraft.tardis_refined.common.capability.tardis.TardisLevelOperator; import whocraft.tardis_refined.common.entity.ControlEntity; @@ -36,6 +41,13 @@ protected void useWorkstation(ServerLevel serverLevel, Villager villager) { if (pilotManager.isInFlight()) { BlockPos consolePos = console.getBlockPos(); + BlockState consoleState = serverLevel.getBlockState(consolePos); + + if (!consoleState.hasProperty(ConsoleConfigurationBlock.FACING)) { + return; // Exit if FACING property is not available + } + + Direction facing = consoleState.getValue(ConsoleConfigurationBlock.FACING); double distanceToConsoleSqr = consolePos.distToCenterSqr(villager.position().x, villager.position().y, villager.position().z); if (pilotManager.canEndFlight()) { @@ -44,20 +56,32 @@ protected void useWorkstation(ServerLevel serverLevel, Villager villager) { pilotManager.endFlight(true); } - // Ensure the villager is within 2 blocks and not closer than 1 block to the console - if (distanceToConsoleSqr > 4) { // More than 2 blocks away - // Move villager closer to the console - villager.moveTo(consolePos.getX() + 1.5, villager.position().y, consolePos.getZ() + 1.5); - } else if (distanceToConsoleSqr < 1) { // Less than 1 block away - // Move villager slightly away from the console - villager.moveTo(consolePos.getX() + 2, villager.position().y, consolePos.getZ() + 2); + // Ensure the villager is within a reasonable radius + if (distanceToConsoleSqr > 9) { // Too far from the console (3 blocks radius) + villager.getNavigation().moveTo(consolePos.getX() + 0.5, villager.position().y, consolePos.getZ() + 0.5, 1); + return; } + double observePointOffset = 4; + + // Calculate villager position relative to the FACING direction + Vec3 offset = switch (facing) { + case NORTH -> new Vec3(0, 0, -observePointOffset); // Stand 1.5 blocks away to the north + case SOUTH -> new Vec3(0, 0, observePointOffset); // Stand 1.5 blocks away to the south + case WEST -> new Vec3(-observePointOffset, 0, 0); // Stand 1.5 blocks away to the west + case EAST -> new Vec3(observePointOffset, 0, 0); // Stand 1.5 blocks away to the east + default -> Vec3.ZERO; // Default fallback + }; + + Vec3 targetPosition = new Vec3(consolePos.getX(), villager.position().y, consolePos.getZ()).add(offset); + + villager.getNavigation().moveTo(targetPosition.x, targetPosition.y, targetPosition.z, 1); + + // Find the nearest control and perform actions for (ControlEntity controlEntity : console.getControlEntityList()) { if (controlEntity.isTickingDown() && villager.getRandom().nextBoolean()) { controlEntity.realignControl(); villager.setUnhappyCounter(40); - System.out.println("Re-aligned: " + controlEntity.getCustomName().getString()); return; } } @@ -68,6 +92,19 @@ protected void useWorkstation(ServerLevel serverLevel, Villager villager) { } + @Override + protected void start(ServerLevel serverLevel, Villager villager, long l) { + Brain brain = villager.getBrain(); + brain.setMemory(MemoryModuleType.LAST_WORKED_AT_POI, l); + brain.getMemory(MemoryModuleType.JOB_SITE).ifPresent((globalPos) -> { + brain.setMemory(MemoryModuleType.LOOK_TARGET, new BlockPosTracker(globalPos.pos())); + villager.moveTo(new Vec3(globalPos.pos().getX(), globalPos.pos().getY(), globalPos.pos().getZ())); + }); + + this.useWorkstation(serverLevel, villager); + } + + @Override protected boolean canStillUse(ServerLevel serverLevel, Villager villager, long l) { Optional optional = villager.getBrain().getMemory(MemoryModuleType.JOB_SITE);