From 240926f5015fe93af6b8f91435202cbd96ddac3f Mon Sep 17 00:00:00 2001 From: Craig Date: Mon, 19 Feb 2024 10:50:33 +0000 Subject: [PATCH] Uncommited changes --- .../common/block/shell/GlobalShellBlock.java | 12 +++++++++ .../shell/ShellBaseBlockEntity.java | 26 ++++++++++++++++++- .../common/capability/upgrades/Upgrade.java | 2 +- .../common/capability/upgrades/Upgrades.java | 4 +-- .../manager/TardisFlightEventManager.java | 7 ++--- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/whocraft/tardis_refined/common/block/shell/GlobalShellBlock.java b/common/src/main/java/whocraft/tardis_refined/common/block/shell/GlobalShellBlock.java index 13462641c..19413ec5f 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/block/shell/GlobalShellBlock.java +++ b/common/src/main/java/whocraft/tardis_refined/common/block/shell/GlobalShellBlock.java @@ -14,6 +14,8 @@ 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.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.phys.BlockHitResult; @@ -22,6 +24,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; 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.tardis.themes.ShellTheme; @@ -73,6 +76,15 @@ public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { return new GlobalShellBlockEntity(blockPos, blockState); } + @Nullable + @Override + public BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType blockEntityType) { + return (level1, blockPos, block, t) -> { + if (t instanceof ShellBaseBlockEntity shellBaseBlockEntity) { + shellBaseBlockEntity.tick(level1, blockPos, blockState, shellBaseBlockEntity); + } + }; } + @Override public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) { 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 fed584ecd..fe061ecdb 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 @@ -15,7 +15,9 @@ 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.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.entity.TickingBlockEntity; import net.minecraft.world.level.block.state.BlockState; import whocraft.tardis_refined.TardisRefined; import whocraft.tardis_refined.common.block.shell.ShellBaseBlock; @@ -26,13 +28,14 @@ import whocraft.tardis_refined.common.tardis.ExteriorShell; import whocraft.tardis_refined.common.tardis.TardisDesktops; import whocraft.tardis_refined.common.tardis.themes.DesktopTheme; +import whocraft.tardis_refined.common.util.Platform; import whocraft.tardis_refined.common.util.PlayerUtil; import whocraft.tardis_refined.compat.ModCompatChecker; import whocraft.tardis_refined.compat.portals.ImmersivePortals; import whocraft.tardis_refined.constants.ModMessages; import whocraft.tardis_refined.constants.NbtConstants; -public abstract class ShellBaseBlockEntity extends BlockEntity implements ExteriorShell { +public abstract class ShellBaseBlockEntity extends BlockEntity implements ExteriorShell, BlockEntityTicker { protected ResourceKey TARDIS_ID; public AnimationState liveliness = new AnimationState(); @@ -133,4 +136,25 @@ public BlockPos getExitPosition() { public DesktopTheme getAssociatedTheme() { return TardisDesktops.FACTORY_THEME; } + + private final int DUPLICATION_CHECK_TIME = 1200; // A minute + + @Override + public void tick(Level level, BlockPos blockPos, BlockState blockState, ShellBaseBlockEntity blockEntity) { + if(level.getGameTime() % DUPLICATION_CHECK_TIME == 0 && !level.isClientSide){ + ResourceKey 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); + } + }); + } + } } diff --git a/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrade.java b/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrade.java index 51ebf9bee..e90bc5fd9 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrade.java +++ b/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrade.java @@ -75,7 +75,7 @@ public int getSkillPointsRequired() { return this.cost; } - public Upgrade setPosition(int x, int y) { + public Upgrade setPosition(double x, double y) { this.posSet = true; this.posX = x; this.posY = y; diff --git a/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrades.java b/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrades.java index 015299740..37ebc1469 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrades.java +++ b/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrades.java @@ -49,10 +49,10 @@ public class Upgrades { .setSkillPointsRequired(50).setPosition(1, 2)); public static final RegistrySupplier EXPLORER_II = UPGRADE_DEFERRED_REGISTRY.register("explorer_ii", () -> new IncrementUpgrade(Items.COMPASS::getDefaultInstance, EXPLORER, RegistryHelper.makeKey("explorer_ii"), Upgrade.UpgradeType.SUB_UPGRADE).setIncrementAmount(2500) - .setSkillPointsRequired(50).setPosition(2, 2)); + .setSkillPointsRequired(50).setPosition(1.5, 2)); public static final RegistrySupplier EXPLORER_III = UPGRADE_DEFERRED_REGISTRY.register("explorer_iii", () -> new IncrementUpgrade(Items.COMPASS::getDefaultInstance, EXPLORER_II, RegistryHelper.makeKey("explorer_iii"), Upgrade.UpgradeType.SUB_UPGRADE).setIncrementAmount(5000) - .setSkillPointsRequired(50).setPosition(3, 2)); + .setSkillPointsRequired(50).setPosition(2, 2)); public static final RegistrySupplier DIMENSION_TRAVEL = UPGRADE_DEFERRED_REGISTRY.register("dimension_travel", () -> new Upgrade(Blocks.NETHER_BRICKS.asItem()::getDefaultInstance, NAVIGATION_SYSTEM, RegistryHelper.makeKey("dimension_travel"), Upgrade.UpgradeType.SUB_UPGRADE) .setSkillPointsRequired(50).setPosition(0, 3)); 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 a0b10f6db..f264fc4dd 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 @@ -249,13 +249,14 @@ public void tickDangerLevels() { ticksInTheDangerZone++; // Tick every second var scaleForDanger = 0.5f; + var gameTime = operator.getLevel().getGameTime(); - if (operator.getLevel().getGameTime() % (10 * 20) == 0) { + if (gameTime % (10 * 20) == 0) { this.requiredDangerZoneRequests++; } if (dangerZoneSecondsPast(10)) { - if (operator.getLevel().getGameTime() % (6 * 20) == 0) { + if (gameTime % (6 * 20) == 0) { this.operator.getLevel().playSound(null, TardisArchitectureHandler.DESKTOP_CENTER_POS, SoundEvents.MINECART_INSIDE, SoundSource.BLOCKS, 1000f, 0.1f); } @@ -263,7 +264,7 @@ public void tickDangerLevels() { } if (dangerZoneSecondsPast(30)) { - if (operator.getLevel().getGameTime() % (3 * 20) == 0) { + if (gameTime % (3 * 20) == 0) { TardisHelper.playCloisterBell(operator); }