Search in sources :

Example 16 with LevelChunk

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);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LevelChunk(net.minecraft.world.level.chunk.LevelChunk)

Example 17 with LevelChunk

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);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelChunkSection(net.minecraft.world.level.chunk.LevelChunkSection) WeakReference(java.lang.ref.WeakReference)

Example 18 with LevelChunk

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);
}
Also used : LevelChunk(net.minecraft.world.level.chunk.LevelChunk)

Example 19 with LevelChunk

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;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LevelChunk(net.minecraft.world.level.chunk.LevelChunk)

Example 20 with LevelChunk

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();
}
Also used : ChunkSource(net.minecraft.world.level.chunk.ChunkSource) LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(net.minecraft.world.entity.Entity) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) BlockPos(net.minecraft.core.BlockPos)

Aggregations

LevelChunk (net.minecraft.world.level.chunk.LevelChunk)36 BlockPos (net.minecraft.core.BlockPos)13 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)10 ServerLevel (net.minecraft.server.level.ServerLevel)9 LevelChunkBridge (org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)8 Vector3i (org.spongepowered.math.vector.Vector3i)7 BlockState (net.minecraft.world.level.block.state.BlockState)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)6 BlockEntity (org.spongepowered.api.block.entity.BlockEntity)5 BlockLight (com.denizenscript.denizen.nms.abstracts.BlockLight)4 ChunkCoordinate (com.denizenscript.denizen.utilities.blocks.ChunkCoordinate)4 UUID (java.util.UUID)4 Tuple (net.minecraft.util.Tuple)4 Level (net.minecraft.world.level.Level)4 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)4 CompoundTag (net.minecraft.nbt.CompoundTag)3 ChunkPos (net.minecraft.world.level.ChunkPos)3 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)3 SpongeBlockChangeFlag (org.spongepowered.common.world.SpongeBlockChangeFlag)3 BitSet (java.util.BitSet)2