Skip to content

Commit

Permalink
Removed LastKnownLocation for CurrentLocation (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
CommandrMoose authored May 6, 2024
1 parent 32de1dc commit 1f57d99
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public boolean onRightClick(BlockState blockState, ItemStack stack, Level level,
ResourceKey<Level> dimension = this.getTardisId();

if (stack.is(Items.SHEARS) && cap.getAestheticHandler().getShellTheme() == ShellTheme.HALF_BAKED.getId() && !cap.getPilotingManager().isInFlight()) {
cap.getAestheticHandler().setShellTheme(ShellTheme.FACTORY.getId(), cap.getExteriorManager().getLastKnownLocation());
cap.getAestheticHandler().setShellTheme(ShellTheme.FACTORY.getId(), cap.getPilotingManager().getCurrentLocation());
level.playSound(null, blockPos, SoundEvents.SHEEP_SHEAR, SoundSource.BLOCKS, 1, 1);

spawnCoralItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import whocraft.tardis_refined.common.dimension.DimensionHandler;
import whocraft.tardis_refined.common.tardis.ExteriorShell;
import whocraft.tardis_refined.common.tardis.TardisDesktops;
import whocraft.tardis_refined.common.tardis.TardisNavLocation;
import whocraft.tardis_refined.common.tardis.manager.TardisPilotingManager;
import whocraft.tardis_refined.common.tardis.themes.DesktopTheme;
import whocraft.tardis_refined.common.util.Platform;
import whocraft.tardis_refined.common.util.PlayerUtil;
Expand Down Expand Up @@ -114,7 +116,7 @@ public void onAttemptEnter(BlockState blockState, Level level, BlockPos external
}
}
}
cap.enterTardis(entity, externalShellPos, serverLevel, blockState.getValue(ShellBaseBlock.FACING));
cap.enterTardis(entity, getBlockPos(), serverLevel, blockState.getValue(ShellBaseBlock.FACING));
} else {
if (!cap.isTardisReady()) {
if (entity instanceof Player player)
Expand All @@ -141,20 +143,31 @@ public DesktopTheme getAssociatedTheme() {

@Override
public void tick(Level level, BlockPos blockPos, BlockState blockState, ShellBaseBlockEntity blockEntity) {
// if(level.getGameTime() % DUPLICATION_CHECK_TIME == 0 && !level.isClientSide){
// ResourceKey<Level> tardisId = getTardisId();
// if(tardisId == null) return;
// ServerLevel tardisLevel = Platform.getServer().getLevel(tardisId);
// BlockPos myCurrentPosition = getBlockPos();
//
// TardisLevelOperator.get(tardisLevel).ifPresent(tardisLevelOperator -> {
// BlockPos blockPosLastKnown = tardisLevelOperator.getExteriorManager().getLastKnownLocation().getPosition();
// BlockPos wantedDestination = tardisLevelOperator.getPilotingManager().getTargetLocation().getPosition();
//
// if(myCurrentPosition != blockPosLastKnown && myCurrentPosition != wantedDestination && myCurrentPosition != BlockPos.ZERO){
// level.removeBlock(worldPosition, false);
// }
// });
// }
if(level.getGameTime() % DUPLICATION_CHECK_TIME == 0 && !level.isClientSide){
ResourceKey<Level> tardisId = getTardisId();
if(tardisId == null) return;
ServerLevel tardisLevel = Platform.getServer().getLevel(tardisId);
BlockPos myCurrentPosition = getBlockPos();

TardisLevelOperator.get(tardisLevel).ifPresent(tardisLevelOperator -> {

TardisPilotingManager pilotingManager = tardisLevelOperator.getPilotingManager();

BlockPos currentLocation = pilotingManager.getCurrentLocation().getPosition();
BlockPos wantedDestination = pilotingManager.getTargetLocation().getPosition();


if (currentLocation == null) {
Direction direction = blockState.getValue(ShellBaseBlock.FACING);
ServerLevel serverLevel = Platform.getServer().getLevel(level.dimension());
pilotingManager.setCurrentLocation(new TardisNavLocation(getBlockPos(), direction != null ? direction : Direction.NORTH, serverLevel));
}

if (!myCurrentPosition.equals(currentLocation) && !myCurrentPosition.equals(wantedDestination) ) {
level.removeBlock(myCurrentPosition, false);
}

});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
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.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import whocraft.tardis_refined.api.event.TardisEvents;
import whocraft.tardis_refined.client.TardisClientData;
import whocraft.tardis_refined.common.block.shell.ShellBaseBlock;
import whocraft.tardis_refined.common.blockentity.door.AbstractDoorBlockEntity;
import whocraft.tardis_refined.common.blockentity.door.RootShellDoorBlockEntity;
import whocraft.tardis_refined.common.blockentity.door.TardisInternalDoor;
import whocraft.tardis_refined.common.blockentity.shell.ShellBaseBlockEntity;
import whocraft.tardis_refined.common.capability.upgrades.UpgradeHandler;
import whocraft.tardis_refined.common.hum.HumEntry;
import whocraft.tardis_refined.common.hum.TardisHums;
Expand Down Expand Up @@ -142,9 +145,11 @@ public Level getLevel() {
}

public void tick(ServerLevel level) {
interiorManager.tick(level);
pilotingManager.tick(level);
flightDanceManager.tick();

if (interiorManager != null) { interiorManager.tick(level);}
if (pilotingManager != null) { pilotingManager.tick(level);}
if (flightDanceManager != null) { flightDanceManager.tick();}


var shouldSync = level.getGameTime() % 40 == 0;
if (shouldSync) {
Expand Down Expand Up @@ -188,6 +193,8 @@ public boolean enterTardis(Entity entity, BlockPos externalShellPos, ServerLevel
TardisNavLocation sourceLocation = new TardisNavLocation(externalShellPos, shellDirection, shellLevel);
TardisNavLocation targetLocation = new TardisNavLocation(targetPosition, doorDirection, targetServerLevel);

this.pilotingManager.setCurrentLocation(new TardisNavLocation(externalShellPos, shellDirection.getOpposite(), shellLevel));

TardisHelper.teleportEntityTardis(this, entity, sourceLocation, targetLocation, true);
return true;
}
Expand All @@ -204,6 +211,10 @@ public boolean exitTardis(Entity entity, ServerLevel doorLevel, BlockPos doorPos
return false;
}

if (aestheticHandler == null || pilotingManager == null) {
return false;
}

if (aestheticHandler.getShellTheme() != null) {
ResourceLocation theme = aestheticHandler.getShellTheme();
if (ModCompatChecker.immersivePortals() && !(this.internalDoor instanceof RootShellDoorBlockEntity)) {
Expand All @@ -213,32 +224,29 @@ public boolean exitTardis(Entity entity, ServerLevel doorLevel, BlockPos doorPos
}
}

if (this.exteriorManager != null) {
if (this.exteriorManager.getLastKnownLocation() != null) {
if (this.pilotingManager.getCurrentLocation() != null) {

TardisNavLocation targetLocation = this.exteriorManager.getLastKnownLocation();
BlockPos exteriorPos = targetLocation.getPosition();
ServerLevel targetLevel = targetLocation.getLevel();
Direction exteriorDirection = targetLocation.getDirection().getOpposite();
TardisNavLocation targetLocation = this.pilotingManager.getCurrentLocation();
BlockPos exteriorPos = targetLocation.getPosition();
ServerLevel targetLevel = targetLocation.getLevel();
Direction exteriorDirection = targetLocation.getDirection().getOpposite();

BlockPos teleportPos = exteriorPos;
BlockPos teleportPos = exteriorPos;

if (targetLevel.getBlockEntity(exteriorPos) instanceof ExteriorShell exteriorShell) {
teleportPos = exteriorShell.getExitPosition();
}
if (targetLevel.getBlockEntity(exteriorPos) instanceof ExteriorShell exteriorShell) {
teleportPos = exteriorShell.getExitPosition();
}

TardisNavLocation sourceLocation = new TardisNavLocation(doorPos, doorDirection, doorLevel);
TardisNavLocation destinationLocation = new TardisNavLocation(teleportPos, exteriorDirection, targetLevel);
TardisNavLocation sourceLocation = new TardisNavLocation(doorPos, doorDirection, doorLevel);
TardisNavLocation destinationLocation = new TardisNavLocation(teleportPos, exteriorDirection, targetLevel);

TardisHelper.teleportEntityTardis(this, entity, sourceLocation, destinationLocation, false);
}
TardisHelper.teleportEntityTardis(this, entity, sourceLocation, destinationLocation, false);
}

return true;
}

public void setDoorClosed(boolean closeDoor) {
TardisExteriorManager extManager = getExteriorManager();
TardisInternalDoor intDoor = getInternalDoor();

if (intDoor != null) {
Expand All @@ -250,15 +258,15 @@ public void setDoorClosed(boolean closeDoor) {
TardisEvents.DOOR_OPENED_EVENT.invoker().onDoorOpen(this);
}

if (extManager != null) {
if (extManager.getLastKnownLocation() != null) {
extManager.setDoorClosed(closeDoor);
if (this.pilotingManager != null) {
if (this.pilotingManager.getCurrentLocation() != null) {
this.exteriorManager.setDoorClosed(closeDoor);
}
}
}

public void setShellTheme(ResourceLocation theme, boolean setupTardis) {
this.getAestheticHandler().setShellTheme(theme, setupTardis, getExteriorManager().getLastKnownLocation());
this.getAestheticHandler().setShellTheme(theme, setupTardis, this.getPilotingManager().getCurrentLocation());
tardisClientData.setShellTheme(theme);
tardisClientData.setShellPattern(aestheticHandler.shellPattern().id());
tardisClientData.sync();
Expand All @@ -283,7 +291,7 @@ public void setupInitialCave(ServerLevel shellServerLevel, BlockState shellBlock

Direction direction = shellBlockState.getValue(ShellBaseBlock.FACING).getOpposite();
TardisNavLocation navLocation = new TardisNavLocation(shellBlockPos, direction, shellServerLevel);
this.exteriorManager.setLastKnownLocation(navLocation);
this.pilotingManager.setCurrentLocation(navLocation);
this.pilotingManager.setTargetLocation(navLocation);

shellServerLevel.setBlock(shellBlockPos, shellBlockState.setValue(OPEN, true), Block.UPDATE_ALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public boolean onRightClick(TardisLevelOperator operator, ConsoleTheme theme, Co
TardisPilotingManager pilotManager = operator.getPilotingManager();

int increment = pilotManager.getCordIncrement();
BlockPos currentExLoc = operator.getExteriorManager().getLastKnownLocation().getPosition();
BlockPos currentExLoc = operator.getPilotingManager().getCurrentLocation().getPosition();
pilotManager.getTargetLocation().setPosition(
new BlockPos((currentExLoc.getX() - (increment / 2)) + operator.getLevel().random.nextInt(increment * 2),
150,
Expand All @@ -35,7 +35,7 @@ public boolean onRightClick(TardisLevelOperator operator, ConsoleTheme theme, Co
);

if (pilotManager.isInFlight()) {
operator.getPilotingManager().recalculateFlightDistance();
pilotManager.recalculateFlightDistance();
}

PlayerUtil.sendMessage(player, Component.translatable(pilotManager.getTargetLocation().getPosition().toShortString()), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import whocraft.tardis_refined.common.tardis.control.ControlSpecification;
import whocraft.tardis_refined.common.tardis.themes.ConsoleTheme;
import whocraft.tardis_refined.common.util.PlayerUtil;
import whocraft.tardis_refined.constants.ModMessages;

public class ReadoutControl extends Control {
public ReadoutControl(ResourceLocation id) {
Expand All @@ -23,8 +24,8 @@ public ReadoutControl(ResourceLocation id, String langId){
@Override
public boolean onLeftClick(TardisLevelOperator operator, ConsoleTheme theme, ControlEntity controlEntity, Player player) {

TardisNavLocation currentPosition = operator.getExteriorManager().getLastKnownLocation();
PlayerUtil.sendMessage(player, Component.translatable("Current - X: " + currentPosition.getPosition().getX() + " Y: " + currentPosition.getPosition().getY()+ " Z: " + currentPosition.getPosition().getZ() + "F: " + currentPosition.getDirection().getName() + " D: " + currentPosition.getDimensionKey().location().getPath()), true);
TardisNavLocation currentPosition = operator.getPilotingManager().getCurrentLocation();
PlayerUtil.sendMessage(player, Component.translatable(ModMessages.CURRENT).append( " - X: " + currentPosition.getPosition().getX() + " Y: " + currentPosition.getPosition().getY()+ " Z: " + currentPosition.getPosition().getZ() + " F: " + currentPosition.getDirection().getName() + " D: " + currentPosition.getDimensionKey().location().getPath()), true);


return true;
Expand All @@ -34,7 +35,7 @@ public boolean onLeftClick(TardisLevelOperator operator, ConsoleTheme theme, Con
public boolean onRightClick(TardisLevelOperator operator, ConsoleTheme theme, ControlEntity controlEntity, Player player) {

TardisNavLocation targetLocation = operator.getPilotingManager().getTargetLocation();
PlayerUtil.sendMessage(player, Component.translatable("Destination - X: " + targetLocation.getPosition().getX() + " Y: " + targetLocation.getPosition().getY()+ " Z: " + targetLocation.getPosition().getZ() + " F: " + targetLocation.getDirection().getName() + " D: " + targetLocation.getDimensionKey().location().getPath()), true);
PlayerUtil.sendMessage(player, Component.translatable(ModMessages.DESTINATION).append(" - X: " + targetLocation.getPosition().getX() + " Y: " + targetLocation.getPosition().getY()+ " Z: " + targetLocation.getPosition().getZ() + " F: " + targetLocation.getDirection().getName() + " D: " + targetLocation.getDimensionKey().location().getPath()), true);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public boolean onRightClick(TardisLevelOperator operator, ConsoleTheme theme, Co
isSyncingKey = true;
}
if (!isSyncingKey)
new OpenMonitorMessage(operator.getInteriorManager().isWaitingToGenerate(), operator.getExteriorManager().getLastKnownLocation(), operator.getPilotingManager().getTargetLocation(), operator.getUpgradeHandler()).send((ServerPlayer) player);
new OpenMonitorMessage(operator.getInteriorManager().isWaitingToGenerate(), operator.getPilotingManager().getCurrentLocation(), operator.getPilotingManager().getTargetLocation(), operator.getUpgradeHandler()).send((ServerPlayer) player);
return true;
}
return false;
Expand Down
Loading

0 comments on commit 1f57d99

Please sign in to comment.