Skip to content

Commit

Permalink
- Bug fix: Fixed duplication happening on logging out mid-flight (and…
Browse files Browse the repository at this point in the history
… other occasions)
  • Loading branch information
Jeryn99 committed Jan 8, 2025
1 parent a7ea1e6 commit 43a4bca
Show file tree
Hide file tree
Showing 22 changed files with 91 additions and 130 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Bug Fix: Fixed TARDIS not storing Adventure Mode Dimensions correctly
- Bug Fix: Fixed Dedicated Servers on Fabric having issues loading data from disk (Caused dupe TARDIS and loss of Upgrades etc)
- Bug Fix: Fixed Diagonal Windows Support
- Bug fix: Fixed duplication happening on logging out mid-flight (and other occasions)

#### Textures and Models
- Altered: Factory Console Emission Texture
Expand All @@ -19,4 +20,4 @@

#### API Changes
- Addon mods can now freely register console models
- Addon Mod consoles can now have per variant models
- Addon mods consoles can now have per variant models
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ private static void renderDoorOpen(GlobalDoorBlockEntity blockEntity, PoseStack
// Unbind RenderTarget
Minecraft.getInstance().getMainRenderTarget().unbindWrite();
RENDER_TARGET_HELPER.start();
if (!getIsStencilEnabled(RENDER_TARGET_HELPER.renderTarget)) {
setIsStencilEnabled(RENDER_TARGET_HELPER.renderTarget, true);
}

copyRenderTarget(Minecraft.getInstance().getMainRenderTarget(), RENDER_TARGET_HELPER.renderTarget);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static void renderShell(GuiGraphics guiGraphics, float control, float alp
ShellModel model = ShellModelCollection.getInstance().getShellEntry(shellTheme).getShellModel(fullPattern);
model.setDoorPosition(false);

if(!tardisClientData.isFlying()) return;

Lighting.setupForEntityInInventory();

PoseStack pose = guiGraphics.pose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
var keyChain = KeyItem.getKeychain(itemStack);
if (!keyChain.isEmpty()) {
ResourceKey<Level> dimension = KeyItem.getKeychain(itemStack).get(0);
var tardisLevel = Platform.getServer().getLevel(dimension);
var tardisLevel = DimensionUtil.getLevel(dimension);
var operatorOptional = TardisLevelOperator.get(tardisLevel);
if (operatorOptional.isEmpty()) {
return InteractionResult.PASS;
Expand All @@ -80,7 +80,7 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
TardisPilotingManager pilotManager = operator.getPilotingManager();
UpgradeHandler upgradeHandler = operator.getUpgradeHandler();

if (TRUpgrades.LANDING_PAD.get().isUnlocked(upgradeHandler) && pilotManager.beginFlight(true, null) && !pilotManager.isInRecovery()) {
if (TRUpgrades.LANDING_PAD.get().isUnlocked(upgradeHandler) && pilotManager.beginFlight(true) && !pilotManager.isInRecovery()) {
pilotManager.setTargetLocation(new TardisNavLocation(blockPos.above(), player.getDirection().getOpposite(), serverLevel));
serverLevel.playSound(null, blockPos, SoundEvents.PLAYER_LEVELUP, SoundSource.BLOCKS, 1f, 1f);
PlayerUtil.sendMessage(player, Component.translatable(ModMessages.TARDIS_IS_ON_THE_WAY), true);
Expand All @@ -98,7 +98,7 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
return InteractionResult.sidedSuccess(false); //Use InteractionResult.sidedSuccess(false) for non-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.
}
}

PlayerUtil.sendMessage(player, Component.translatable(ModMessages.LANDING_PAD_BANNED_DIM), true);
serverLevel.playSound(null, blockPos, SoundEvents.NOTE_BLOCK_BIT.value(), SoundSource.BLOCKS, 100, (float) (0.1 + (serverLevel.getRandom().nextFloat() * 0.25)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import whocraft.tardis_refined.common.blockentity.TardisDoorProperties;
import whocraft.tardis_refined.common.tardis.themes.DesktopTheme;
import whocraft.tardis_refined.common.capability.tardis.TardisLevelOperator;

public interface ExteriorShell extends TardisDoorProperties {

DesktopTheme getAssociatedTheme();

ResourceKey<Level> getTardisId();

void setTardisId(ResourceKey<Level> levelKey);


boolean isInvalidTardis(TardisLevelOperator tardisLevelOperator);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class GlobalShellBlockEntity extends ShellBaseBlockEntity {
private ResourceLocation shellTheme;
private ShellPattern basePattern;


public GlobalShellBlockEntity(BlockPos blockPos, BlockState blockState) {
super(TRBlockEntityRegistry.GLOBAL_SHELL_BLOCK.get(), blockPos, blockState);
this.shellTheme = ShellTheme.HALF_BAKED.getId();
Expand Down Expand Up @@ -99,6 +98,7 @@ public void load(CompoundTag pTag) {
if (this.basePattern == null) {
this.basePattern = pattern();
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import whocraft.tardis_refined.TardisRefined;
import whocraft.tardis_refined.common.capability.tardis.TardisLevelOperator;
import whocraft.tardis_refined.common.dimension.DimensionHandler;
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.DimensionUtil;
import whocraft.tardis_refined.registry.TRBlockEntityRegistry;

import java.util.UUID;
Expand All @@ -30,11 +28,6 @@ public RootedShellBlockEntity(BlockPos blockPos, BlockState blockState) {
super(TRBlockEntityRegistry.ROOT_SHELL.get(), blockPos, blockState);
}

@Override
public DesktopTheme getAssociatedTheme() {
return TardisDesktops.DEFAULT_OVERGROWN_THEME;
}

@Override
public void playDoorCloseSound(boolean closeDoor) {
//Leave blank
Expand Down Expand Up @@ -88,7 +81,7 @@ private void setUpTardis(BlockState blockState, Level level, BlockPos blockPos)
serverLevel.playSound(null, blockPos, SoundEvents.SHEEP_SHEAR, SoundSource.BLOCKS, 1, 1);
});
} else {
ServerLevel tardisLevel = Platform.getServer().getLevel(getTardisId());
ServerLevel tardisLevel = DimensionUtil.getLevel(getTardisId());
TardisLevelOperator.get(tardisLevel).ifPresent(tardisLevelOperator -> {
//Always open the root shell doors when this method is called to ensure that the player isn't softlocked by the early return of InteractionResult that occurs if the player isn't using shears.
tardisLevelOperator.setDoorClosed(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
import whocraft.tardis_refined.common.capability.tardis.TardisLevelOperator;
import whocraft.tardis_refined.common.capability.tardis.upgrades.UpgradeHandler;
import whocraft.tardis_refined.common.dimension.DimensionHandler;
import whocraft.tardis_refined.common.tardis.TardisDesktops;
import whocraft.tardis_refined.common.tardis.TardisNavLocation;
import whocraft.tardis_refined.common.tardis.manager.AestheticHandler;
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.DimensionUtil;
import whocraft.tardis_refined.common.util.PlayerUtil;
import whocraft.tardis_refined.compat.ModCompatChecker;
import whocraft.tardis_refined.compat.portals.ImmersivePortals;
Expand All @@ -44,18 +41,9 @@

public abstract class ShellBaseBlockEntity extends BlockEntity implements ExteriorShell, BlockEntityTicker<ShellBaseBlockEntity> {

private final int DUPLICATION_CHECK_TIME = 1200; // A minute
public AnimationState liveliness = new AnimationState();
protected ResourceKey<Level> TARDIS_ID;
/*
Because we assume it is possible for the tardis to change location without flying there,
the 'if (!myCurrentPosition.equals(currentLocation) && !myCurrentPosition.equals(wantedDestination))' block
in the duplication check that runs once every so often would mistakenly remove this tardis if it just loaded
in the same tick at a different location (if we are unlocky with tick order),
because the operator's currentPosition will be set in the tick after.
We therefore need a way to skip the duplication check for a single tick when loading in this blockentity.
*/
private boolean doNotRemoveNextTick = false;
private boolean hasPotentialToBeRemoved = false;

public ShellBaseBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
super(blockEntityType, blockPos, blockState);
Expand Down Expand Up @@ -92,7 +80,7 @@ private void updateCurrentLocation() {
ServerLevel interior = serverLevel.getServer().getLevel(this.TARDIS_ID);
TardisLevelOperator.get(interior).ifPresent(cap -> {
cap.getPilotingManager().setCurrentLocationOnNextTick(this);
this.doNotRemoveNextTick = true;
hasPotentialToBeRemoved = true;
});
}
}
Expand Down Expand Up @@ -164,37 +152,20 @@ public void onAttemptEnter(BlockState blockState, Level level, BlockPos external

}

@Override
public DesktopTheme getAssociatedTheme() {
return TardisDesktops.FACTORY_THEME;
}

@Override
public void tick(Level level, BlockPos blockPos, BlockState blockState, ShellBaseBlockEntity blockEntity) {
if (level.getGameTime() % DUPLICATION_CHECK_TIME == 0 && !level.isClientSide && !this.doNotRemoveNextTick) {
if (!level.isClientSide) {
ResourceKey<Level> tardisId = getTardisId();
if (tardisId == null) return;
ServerLevel tardisLevel = Platform.getServer().getLevel(tardisId);
BlockPos myCurrentPosition = getBlockPos();

ServerLevel tardisLevel = DimensionUtil.getLevel(tardisId);

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);
if(!tardisLevelOperator.getPilotingManager().isInFlight()) {
if (isInvalidTardis(tardisLevelOperator)) {
BlockPos myCurrentPosition = getBlockPos();
level.removeBlock(myCurrentPosition, false);
}
}

});
}
}
Expand Down Expand Up @@ -266,4 +237,15 @@ public void playDoorLockedSound(boolean lockDoor) {
Level currentLevel = getLevel();
currentLevel.playSound(null, this.getBlockPos(), lockDoor ? BlockSetType.IRON.doorClose() : BlockSetType.IRON.doorOpen(), SoundSource.BLOCKS, 1, lockDoor ? 1.4F : 1F);
}

@Override
public boolean isInvalidTardis(TardisLevelOperator tardisLevelOperator) {
BlockPos myPosition = getBlockPos();
TardisPilotingManager pilotingManager = tardisLevelOperator.getPilotingManager();

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

return hasPotentialToBeRemoved && !myPosition.equals(currentLocation) && !myPosition.equals(wantedDestination);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import whocraft.tardis_refined.common.network.messages.sync.S2CSyncTardisPlayerView;
import whocraft.tardis_refined.common.tardis.TardisNavLocation;
import whocraft.tardis_refined.common.tardis.manager.TardisPilotingManager;
import whocraft.tardis_refined.common.util.DimensionUtil;
import whocraft.tardis_refined.common.util.Platform;
import whocraft.tardis_refined.common.util.TRTeleporter;

Expand Down Expand Up @@ -200,7 +201,7 @@ public void endShellView(ServerPlayer serverPlayer) {
if (!isViewingTardis()) return;
BlockPos targetPosition = getPlayerPreviousPos().getPosition();

TRTeleporter.simpleTeleport(serverPlayer, Platform.getServer().getLevel(getPlayerPreviousPos().getDimensionKey()), targetPosition.getX() + 0.5, targetPosition.getY(), targetPosition.getZ() + 0.5, playerPreviousYaw, playerPreviousRot);
TRTeleporter.simpleTeleport(serverPlayer, DimensionUtil.getLevel(getPlayerPreviousPos().getDimensionKey()), targetPosition.getX() + 0.5, targetPosition.getY(), targetPosition.getZ() + 0.5, playerPreviousYaw, playerPreviousRot);
updatePlayerAbilities(serverPlayer, serverPlayer.getAbilities(), false);
serverPlayer.onUpdateAbilities();
new S2CResetPostShellView().send(serverPlayer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import whocraft.tardis_refined.common.entity.ControlEntity;
import whocraft.tardis_refined.common.tardis.TardisNavLocation;
import whocraft.tardis_refined.common.tardis.manager.TardisPilotingManager;
import whocraft.tardis_refined.common.util.DimensionUtil;
import whocraft.tardis_refined.common.util.Platform;
import whocraft.tardis_refined.common.util.PlayerUtil;
import whocraft.tardis_refined.constants.ModMessages;
Expand Down Expand Up @@ -129,16 +130,17 @@ public Component getName(ItemStack itemStack) {
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand interactionHand) {

// Whistle Easter Egg: https://youtu.be/IqQsL79UpMs?t=526
if (player.getOffhandItem().is(Items.GOAT_HORN) && !level.isClientSide) {
// Whistle Easter Egg for InDev: https://youtu.be/IqQsL79UpMs?t=526
boolean canUseWhistle = "96511168-1bb3-4ff0-a894-271e42606a39".equals(player.getStringUUID()) || Platform.isProduction();
if (player.getOffhandItem().is(Items.GOAT_HORN) && !level.isClientSide && canUseWhistle) {
ArrayList<ResourceKey<Level>> keychain = KeyItem.getKeychain(player.getMainHandItem());
if (!keychain.isEmpty()) {
var tardisLevel = Platform.getServer().getLevel(keychain.get(0));
var tardisLevel = DimensionUtil.getLevel(keychain.get(0));
var operatorOptional = TardisLevelOperator.get(tardisLevel);
var pilotManager = operatorOptional.get().getPilotingManager();
if (!operatorOptional.get().getPilotingManager().isInRecovery()) {
pilotManager.setTargetLocation(new TardisNavLocation(player.blockPosition(), player.getDirection().getOpposite(), (ServerLevel) player.level()));
pilotManager.beginFlight(true, null);
pilotManager.beginFlight(true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import whocraft.tardis_refined.common.network.MessageContext;
import whocraft.tardis_refined.common.network.MessageType;
import whocraft.tardis_refined.common.network.TardisNetwork;
import whocraft.tardis_refined.common.util.DimensionUtil;
import whocraft.tardis_refined.common.util.Platform;

public class C2SExitTardisView extends MessageC2S {
Expand Down Expand Up @@ -43,7 +44,7 @@ public void handle(MessageContext context) {
if (tardisInfo.isViewingTardis()) {
ResourceKey<Level> key = ResourceKey.create(Registries.DIMENSION,
new ResourceLocation(TardisRefined.MODID, tardisInfo.getViewedTardis().toString()));
ServerLevel tardisLevel = Platform.getServer().getLevel(key);
ServerLevel tardisLevel = DimensionUtil.getLevel(key);
if (tardisLevel != null) {
TardisLevelOperator.get(tardisLevel).ifPresent(tardisLevelOperator -> {
tardisInfo.endShellView(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import whocraft.tardis_refined.common.network.MessageContext;
import whocraft.tardis_refined.common.network.MessageType;
import whocraft.tardis_refined.common.network.TardisNetwork;
import whocraft.tardis_refined.common.util.DimensionUtil;
import whocraft.tardis_refined.common.util.Platform;

public class ExitTardisViewMessage extends MessageC2S {
Expand Down Expand Up @@ -43,7 +44,7 @@ public void handle(MessageContext context) {
if (tardisInfo.isViewingTardis()) {
ResourceKey<Level> key = ResourceKey.create(Registries.DIMENSION,
new ResourceLocation(TardisRefined.MODID, tardisInfo.getViewedTardis().toString()));
ServerLevel tardisLevel = Platform.getServer().getLevel(key);
ServerLevel tardisLevel = DimensionUtil.getLevel(key);
if (tardisLevel != null) {
TardisLevelOperator.get(tardisLevel).ifPresent(tardisLevelOperator -> {
tardisInfo.endShellView(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import whocraft.tardis_refined.common.network.MessageContext;
import whocraft.tardis_refined.common.network.MessageType;
import whocraft.tardis_refined.common.network.TardisNetwork;
import whocraft.tardis_refined.common.util.DimensionUtil;
import whocraft.tardis_refined.common.util.Platform;

public class C2SMonitorClosed extends MessageC2S {
Expand All @@ -36,7 +37,7 @@ public void toBytes(FriendlyByteBuf buf) {

@Override
public void handle(MessageContext context) {
TardisLevelOperator.get(Platform.getServer().getLevel(level)).ifPresent(operator -> {
TardisLevelOperator.get(DimensionUtil.getLevel(level)).ifPresent(operator -> {
operator.updatingMonitors.remove(context.getPlayer());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import whocraft.tardis_refined.common.util.DimensionUtil;
import whocraft.tardis_refined.common.util.Platform;
import whocraft.tardis_refined.common.util.PlayerUtil;

/**
* TardisNavLocation
Expand Down Expand Up @@ -85,7 +87,7 @@ public ServerLevel getLevel() {

if (this.level != null) {
this.dimensionKey = this.level.dimension();
return Platform.getServer().getLevel(dimensionKey);
return DimensionUtil.getLevel(dimensionKey);
}

return Platform.getServer().getLevel(Level.OVERWORLD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public boolean onRightClick(TardisLevelOperator operator, ConsoleTheme theme, Co
if (!player.level().isClientSide()) {

if (operator.getTardisState() != TardisLevelOperator.STATE_EYE_OF_HARMONY || operator.getPilotingManager().isOutOfFuel()) {
PlayerUtil.sendMessage(player, ModMessages.HARDWARE_OFFLINE, true);
PlayerUtil.sendMessage(player, ModMessages.FUEL_OFFLINE, true);
return false;
}

Expand Down
Loading

0 comments on commit 43a4bca

Please sign in to comment.