Skip to content

Commit

Permalink
Uncommited changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeryn99 committed Feb 19, 2024
1 parent 1cc779e commit 240926f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -73,6 +76,15 @@ public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new GlobalShellBlockEntity(blockPos, blockState);
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> 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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ShellBaseBlockEntity> {

protected ResourceKey<Level> TARDIS_ID;
public AnimationState liveliness = new AnimationState();
Expand Down Expand Up @@ -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<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);
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public class Upgrades {
.setSkillPointsRequired(50).setPosition(1, 2));

public static final RegistrySupplier<Upgrade> 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<Upgrade> 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<Upgrade> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,22 @@ 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);
}

scaleForDanger = 0.7f;
}

if (dangerZoneSecondsPast(30)) {
if (operator.getLevel().getGameTime() % (3 * 20) == 0) {
if (gameTime % (3 * 20) == 0) {
TardisHelper.playCloisterBell(operator);
}

Expand Down

0 comments on commit 240926f

Please sign in to comment.