Skip to content

Commit

Permalink
- Fixed villagers being strange about being Tardis Pilots (I would be…
Browse files Browse the repository at this point in the history
… too, I don't blame them)

- Fixed Villager path finding
- Sped up gravity well
  • Loading branch information
Jeryn99 committed Nov 26, 2024
1 parent 0d53360 commit ee81ad9
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 26 deletions.
7 changes: 4 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
- 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
- Recovery Progress of crashed TARDIS now displayed on controls until repair is complete
- 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
- Improved UI for Gravity Shaft
- Speed up downwards descent for Gravity Shaft
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -119,20 +121,22 @@ 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);

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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
}
}
Expand All @@ -68,6 +92,19 @@ protected void useWorkstation(ServerLevel serverLevel, Villager villager) {
}


@Override
protected void start(ServerLevel serverLevel, Villager villager, long l) {
Brain<Villager> 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<GlobalPos> optional = villager.getBrain().getMemory(MemoryModuleType.JOB_SITE);
Expand Down

0 comments on commit ee81ad9

Please sign in to comment.