Skip to content

[NEEDS TESTING] fix: load the chunk before falling #1309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package dev.amble.ait.core.tardis.control.impl;

import dev.amble.lib.data.CachedDirectedGlobalPos;

import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;

import dev.amble.ait.AITMod;
import dev.amble.ait.core.AITBlocks;
import dev.amble.ait.core.AITSounds;
import dev.amble.ait.core.engine.SubSystem;
import dev.amble.ait.core.tardis.Tardis;
Expand All @@ -27,13 +24,7 @@ public Result runServer(Tardis tardis, ServerPlayerEntity player, ServerWorld wo
super.runServer(tardis, player, world, console, leftClick);

tardis.travel().antigravs().toggle();

CachedDirectedGlobalPos globalPos = tardis.travel().position();
ServerWorld targetWorld = globalPos.getWorld();
BlockPos pos = globalPos.getPos();

targetWorld.getChunkManager().markForUpdate(pos);
world.scheduleBlockTick(pos, AITBlocks.EXTERIOR_BLOCK, 2);
tardis.travel().scheduleExteriorUpdate();
return tardis.travel().antigravs().get() ? Result.SUCCESS : Result.SUCCESS_ALT;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.server.world.ChunkTicketType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;

import dev.amble.ait.AITMod;
Expand Down Expand Up @@ -191,11 +193,26 @@ private ExteriorBlockEntity placeExterior(CachedDirectedGlobalPos globalPos, boo
this.runAnimations(exterior);

if (schedule && !this.antigravs.get())
world.scheduleBlockTick(pos, AITBlocks.EXTERIOR_BLOCK, 2);
this.scheduleExteriorUpdate();

return exterior;
}

public void scheduleExteriorUpdate() {
ServerWorld world = this.position.get().getWorld();
BlockPos pos = this.position.get().getPos();

ChunkPos chunkPos = new ChunkPos(pos);

Scheduler.get().runTaskLater(() -> world.setChunkForced(chunkPos.x, chunkPos.z, false), TimeUnit.TICKS, 20);

world.setChunkForced(chunkPos.x, chunkPos.z, true);
//world.getChunkManager().setChunkForced(chunkPos, true);
world.getChunkManager().markForUpdate(pos);

Scheduler.get().runTaskLater(() -> world.scheduleBlockTick(pos, AITBlocks.EXTERIOR_BLOCK, 2), TimeUnit.TICKS, 10);
}

private void runAnimations(ExteriorBlockEntity exterior) {
State state = this.getState();
ExteriorAnimation animation = exterior.getAnimation();
Expand Down Expand Up @@ -380,7 +397,7 @@ private void finishForceRemat(CachedDirectedGlobalPos pos) {

this.tardis.getDesktop().playSoundAtEveryConsole(sound, SoundCategory.BLOCKS, 2f, 1f);
//System.out.println(sound.getId());
this.placeExterior(true); // we schedule block update in #finishRemat
this.placeExterior(true);
}

public void finishRemat() {
Expand Down