use of net.minecraft.world.level.chunk.LevelChunk in project Tropicraft by Tropicraft.
the class TropicraftDimension method teleportPlayerNoPortal.
/**
* Finds the top Y position relative to the dimension the player is teleporting to and places
* the entity at that position. Avoids portal generation by using player.teleport() instead of
* player.changeDimension()
*
* @param player The player that will be teleported
* @param destination The target dimension to teleport to
*/
public static void teleportPlayerNoPortal(ServerPlayer player, ResourceKey<Level> destination) {
ServerLevel world = player.server.getLevel(destination);
if (world == null) {
LOGGER.error("Cannot teleport player to dimension {} as it does not exist!", destination.location());
return;
}
if (!ForgeHooks.onTravelToDimension(player, destination))
return;
int x = Mth.floor(player.getX());
int z = Mth.floor(player.getZ());
LevelChunk chunk = world.getChunk(x >> 4, z >> 4);
int topY = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, x & 15, z & 15);
player.teleportTo(world, x + 0.5, topY + 1.0, z + 0.5, player.getYRot(), player.getXRot());
BasicEventHooks.firePlayerChangedDimensionEvent(player, destination, destination);
}
use of net.minecraft.world.level.chunk.LevelChunk in project SpongeCommon by SpongePowered.
the class TileEntityPipeline method kickOff.
public static Builder kickOff(final ServerLevel world, final BlockPos pos) {
final WeakReference<ServerLevel> worldRef = new WeakReference<>(world);
final LevelChunk chunk = world.getChunkAt(pos);
final WeakReference<LevelChunk> chunkRef = new WeakReference<>(chunk);
final WeakReference<LevelChunkSection> sectionRef = new WeakReference<>(chunk.getSections()[pos.getY() >> 4]);
final Supplier<ServerLevel> worldSupplier = () -> Objects.requireNonNull(worldRef.get(), "ServerWorld de-referenced");
final Supplier<LevelChunk> chunkSupplier = () -> Objects.requireNonNull(chunkRef.get(), "Chunk de-referenced");
final Supplier<LevelChunkSection> chunkSectionSupplier = () -> Objects.requireNonNull(sectionRef.get(), "ChunkSection de-referenced");
return TileEntityPipeline.builder().chunk(chunkSupplier).world(worldSupplier).chunkSection(chunkSectionSupplier);
}
use of net.minecraft.world.level.chunk.LevelChunk in project SpongeCommon by SpongePowered.
the class ChunkChangeCompleteEffect method processSideEffect.
@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
final LevelChunk chunk = pipeline.getAffectedChunk();
chunk.markUnsaved();
return new EffectResult(oldState.state, true);
}
use of net.minecraft.world.level.chunk.LevelChunk in project SpongeCommon by SpongePowered.
the class NotifyClientEffect method processSideEffect.
@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
final LevelChunk chunk = pipeline.getAffectedChunk();
final ServerLevel world = pipeline.getServerWorld();
// if ((flags & 2) != 0 && (!this.isClientSide || (flags & 4) == 0) && (this.isClientSide || chunk.getLocationType() != null && chunk.getLocationType().isAtLeast(ChunkHolder.LocationType.TICKING))) {
if (flag.notifyClients() && (chunk.getFullStatus().isOrAfter(ChunkHolder.FullChunkStatus.TICKING))) {
// this.notifyBlockUpdate(pos, blockstate, newWorldState, flags);
world.sendBlockUpdated(oldState.pos, oldState.state, newState, flag.getRawFlag());
}
return EffectResult.NULL_PASS;
}
use of net.minecraft.world.level.chunk.LevelChunk in project SpongeCommon by SpongePowered.
the class DamageEventUtil method findFirstMatchingBlock.
public static ServerLocation findFirstMatchingBlock(final Entity entity, final AABB bb, final Predicate<BlockState> predicate) {
final int i = Mth.floor(bb.minX);
final int j = Mth.floor(bb.maxX + 1.0D);
final int k = Mth.floor(bb.minY);
final int l = Mth.floor(bb.maxY + 1.0D);
final int i1 = Mth.floor(bb.minZ);
final int j1 = Mth.floor(bb.maxZ + 1.0D);
final ChunkSource chunkSource = entity.level.getChunkSource();
for (int k1 = i; k1 < j; ++k1) {
for (int l1 = k; l1 < l; ++l1) {
for (int i2 = i1; i2 < j1; ++i2) {
final BlockPos blockPos = new BlockPos(k1, l1, i2);
final LevelChunk chunk = chunkSource.getChunk(blockPos.getX() >> 4, blockPos.getZ() >> 4, false);
if (chunk == null || chunk.isEmpty()) {
continue;
}
if (predicate.test(chunk.getBlockState(blockPos))) {
return ServerLocation.of((ServerWorld) entity.level, k1, l1, i2);
}
}
}
}
// Entity is source of fire
return ((org.spongepowered.api.entity.Entity) entity).serverLocation();
}
Aggregations