Search in sources :

Example 76 with ServerLevel

use of net.minecraft.server.level.ServerLevel 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 77 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class UpdateConnectingBlocksEffect method processSideEffect.

@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
    final ServerLevel world = pipeline.getServerWorld();
    final BlockPos pos = oldState.pos;
    if (flag.updateNeighboringShapes() && limit > 0) {
        // int i = p_241211_3_ & -34; // Vanilla negates 34 to flip neighbor notification and and "state drops"
        final int withoutNeighborDropsAndNestedNeighborUpdates = flag.asNestedNeighborUpdates().getRawFlag();
        // blockstate.updateIndirectNeighbourShapes(this, p_241211_1_, i, p_241211_4_ - 1);
        oldState.state.updateIndirectNeighbourShapes(world, pos, withoutNeighborDropsAndNestedNeighborUpdates, limit - 1);
        // p_241211_2_.updateNeighbourShapes(this, p_241211_1_, i, p_241211_4_ - 1);
        newState.updateNeighbourShapes(world, pos, withoutNeighborDropsAndNestedNeighborUpdates, limit - 1);
        // p_241211_2_.updateIndirectNeighbourShapes(this, p_241211_1_, i, p_241211_4_ - 1);
        newState.updateIndirectNeighbourShapes(world, pos, withoutNeighborDropsAndNestedNeighborUpdates, limit - 1);
    }
    return EffectResult.NULL_PASS;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockPos(net.minecraft.core.BlockPos)

Example 78 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class SpawnDestructBlocksEffect method processSideEffect.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
    final ServerLevel world = pipeline.getServerWorld();
    final BlockPos pos = oldState.pos;
    final List<ItemStack> drops = oldState.drops;
    drops.forEach(drop -> Block.popResource(world, pos, drop));
    return EffectResult.NULL_PASS;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack)

Example 79 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class SpongeMapStorage method mapInfo.

@Override
public Optional<MapInfo> mapInfo(final UUID uuid) {
    this.ensureHasMapUUIDIndex();
    final MapInfo mapInfo = this.loadedMapUUIDs.get(uuid);
    if (mapInfo != null) {
        return Optional.of(mapInfo);
    }
    final Integer mapId = this.mapIdUUIDIndex.inverse().get(uuid);
    if (mapId == null) {
        return Optional.empty();
    }
    final ServerLevel defaultWorld = (ServerLevel) Sponge.server().worldManager().defaultWorld();
    final MapInfo loadedMapInfo = (MapInfo) defaultWorld.getMapData(Constants.Map.MAP_PREFIX + mapId);
    return Optional.ofNullable(loadedMapInfo);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) MapInfo(org.spongepowered.api.map.MapInfo)

Example 80 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class SpongeMapStorage method allMapInfos.

@Override
public Collection<MapInfo> allMapInfos() {
    final Set<MapInfo> mapInfos = new HashSet<>();
    final ServerLevel defaultWorld = (ServerLevel) Sponge.server().worldManager().defaultWorld();
    final int highestId = ((MapIdTrackerBridge) defaultWorld.getDataStorage().computeIfAbsent(MapIndex::new, Constants.Map.MAP_INDEX_DATA_NAME)).bridge$getHighestMapId().orElse(-1);
    for (int i = 0; i <= highestId; i++) {
        @Nullable final MapInfo mapInfo = (MapInfo) defaultWorld.getMapData(Constants.Map.MAP_PREFIX + i);
        if (mapInfo == null) {
            SpongeCommon.logger().warn("Missing map with id: " + i);
            continue;
        }
        this.addMapInfo(mapInfo);
        mapInfos.add(mapInfo);
    }
    return mapInfos;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) MapInfo(org.spongepowered.api.map.MapInfo) MapIndex(net.minecraft.world.level.saveddata.maps.MapIndex) Nullable(org.checkerframework.checker.nullness.qual.Nullable) HashSet(java.util.HashSet)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)115 BlockPos (net.minecraft.core.BlockPos)30 Nullable (org.checkerframework.checker.nullness.qual.Nullable)21 Level (net.minecraft.world.level.Level)20 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)16 Entity (net.minecraft.world.entity.Entity)14 ServerPlayer (net.minecraft.server.level.ServerPlayer)11 ItemStack (net.minecraft.world.item.ItemStack)10 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)10 IOException (java.io.IOException)9 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)9 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)9 ArrayList (java.util.ArrayList)8 BlockState (net.minecraft.world.level.block.state.BlockState)8 List (java.util.List)7 Optional (java.util.Optional)7 UUID (java.util.UUID)7 Vec3 (net.minecraft.world.phys.Vec3)7 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)7 Cause (org.spongepowered.api.event.Cause)7