Search in sources :

Example 11 with ServerWorld

use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.

the class SpongeTeleportHelper method findSafeLocation.

@Override
public Optional<ServerLocation> findSafeLocation(ServerLocation location, int height, int width, int distanceToDrop, TeleportHelperFilter filter, TeleportHelperFilter... additionalFilters) {
    final ServerWorld world = location.world();
    final Set<TeleportHelperFilter> filters = Sets.newHashSet(additionalFilters);
    filters.add(filter);
    if (SpongeConfigs.getCommon().get().teleportHelper.forceBlacklist) {
        // Always force this into the set if the user has requested it.
        filters.add(TeleportHelperFilters.CONFIG.get());
    }
    // Get the vectors to check, and get the block types with them.
    // The vectors should be sorted by distance from the centre of the checking region, so
    // this makes it easier to try to get close, because we can just iterate and get progressively further out.
    Optional<Vector3i> result = this.getSafeLocation(world, this.getBlockLocations(location, height, width), distanceToDrop, filters);
    return result.map(vector3i -> ServerLocation.of(world, vector3i.toDouble().add(0.5, 0, 0.5)));
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) TeleportHelperFilter(org.spongepowered.api.world.teleport.TeleportHelperFilter) Vector3i(org.spongepowered.math.vector.Vector3i)

Example 12 with ServerWorld

use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.

the class EntityActivationRange method activateEntities.

/**
 * Find what entities are in range of the players in the world and set
 * active if in range.
 *
 * @param world The world to perform activation checks in
 */
public static void activateEntities(final ServerLevel world) {
    if (((LevelBridge) world).bridge$isFake()) {
        return;
    }
    for (final ServerPlayer player : world.players()) {
        int maxRange = 0;
        for (final Integer range : EntityActivationRange.maxActivationRanges.values()) {
            if (range > maxRange) {
                maxRange = range;
            }
        }
        maxRange = Math.min((((ServerWorld) world).properties().viewDistance() << 4) - 8, maxRange);
        ((ActivationCapabilityBridge) player).activation$setActivatedTick(SpongeCommon.server().getTickCount());
        final AABB aabb = EntityActivationRange.maxBB;
        EntityActivationRange.growBb(aabb, player.getBoundingBox(), maxRange, 256, maxRange);
        final int i = Mth.floor(aabb.minX / 16.0D);
        final int j = Mth.floor(aabb.maxX / 16.0D);
        final int k = Mth.floor(aabb.minZ / 16.0D);
        final int l = Mth.floor(aabb.maxZ / 16.0D);
        for (int i1 = i; i1 <= j; ++i1) {
            for (int j1 = k; j1 <= l; ++j1) {
                final LevelChunk chunk = world.getChunkSource().getChunkNow(i1, j1);
                if (chunk != null) {
                    EntityActivationRange.activateChunkEntities(player, chunk);
                }
            }
        }
    }
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) ActivationCapabilityBridge(org.spongepowered.common.bridge.activation.ActivationCapabilityBridge) ServerPlayer(net.minecraft.server.level.ServerPlayer) AABB(net.minecraft.world.phys.AABB)

Example 13 with ServerWorld

use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.

the class BlockEvent_BreakEventMixin_Forge method bridge$createSpongeEvent.

@Override
@Nullable
public Event bridge$createSpongeEvent() {
    final LevelAccessor accessor = this.shadow$getWorld();
    if (accessor instanceof ServerWorld) {
        final ServerWorld serverWorld = (ServerWorld) accessor;
        final BlockTransaction transaction = new BlockTransaction(SpongeBlockSnapshot.BuilderImpl.pooled().world(serverWorld.key()).position(VecHelper.toVector3i(this.shadow$getPos())).blockState((BlockState) this.shadow$getState()).build(), SpongeBlockSnapshot.BuilderImpl.pooled().world(serverWorld.key()).position(VecHelper.toVector3i(this.shadow$getPos())).blockState(BlockState.builder().blockType(BlockTypes.AIR.get()).build()).build(), Operations.BREAK.get());
        return SpongeEventFactory.createChangeBlockEventAll(PhaseTracker.getCauseStackManager().currentCause(), Collections.singletonList(transaction), serverWorld);
    }
    return null;
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) LevelAccessor(net.minecraft.world.level.LevelAccessor) BlockTransaction(org.spongepowered.api.block.transaction.BlockTransaction) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 14 with ServerWorld

use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.

the class EnderMan_EndermanLeaveBlockGoalMixin method impl$onPlaceBlockCancel.

/**
 * @reason Makes Endermen check for block changes before they can place their blocks.
 * This allows plugins to cancel the event regardless without issue.
 */
@Redirect(method = "canPlaceBlock(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;isCollisionShapeFullBlock(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Z"))
private boolean impl$onPlaceBlockCancel(BlockState blockState, BlockGetter blockReaderIn, BlockPos blockPosIn) {
    if (blockState.isCollisionShapeFullBlock(blockReaderIn, blockPosIn)) {
        // Sponge start
        if (ShouldFire.CHANGE_BLOCK_EVENT_PRE) {
            final ServerLocation location = ServerLocation.of((ServerWorld) blockReaderIn, blockPosIn.getX(), blockPosIn.getY(), blockPosIn.getZ());
            final List<ServerLocation> list = new ArrayList<>(1);
            list.add(location);
            final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
            final ChangeBlockEvent.Pre event = SpongeEventFactory.createChangeBlockEventPre(cause, list, ((ServerWorld) this.enderman.level));
            return !SpongeCommon.post(event);
        }
        // Sponge end
        return true;
    }
    return false;
}
Also used : ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) ServerWorld(org.spongepowered.api.world.server.ServerWorld) ServerLocation(org.spongepowered.api.world.server.ServerLocation) Cause(org.spongepowered.api.event.Cause) ArrayList(java.util.ArrayList) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 15 with ServerWorld

use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.

the class TickNextTickDataMixin method bridge$setWorld.

@Override
public void bridge$setWorld(Level world) {
    checkState(this.impl$location == null, "World already known");
    final BlockPos position = this.pos;
    this.impl$location = ServerLocation.of((ServerWorld) world, position.getX(), position.getY(), position.getZ());
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) BlockPos(net.minecraft.core.BlockPos)

Aggregations

ServerWorld (org.spongepowered.api.world.server.ServerWorld)43 Vector3d (org.spongepowered.math.vector.Vector3d)13 BlockPos (net.minecraft.core.BlockPos)12 Cause (org.spongepowered.api.event.Cause)12 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)11 CauseStackManager (org.spongepowered.api.event.CauseStackManager)11 ServerLocation (org.spongepowered.api.world.server.ServerLocation)11 Inject (org.spongepowered.asm.mixin.injection.Inject)10 ArrayList (java.util.ArrayList)9 NonNull (org.checkerframework.checker.nullness.qual.NonNull)9 ResourceKey (org.spongepowered.api.ResourceKey)8 List (java.util.List)7 Optional (java.util.Optional)7 ServerLevel (net.minecraft.server.level.ServerLevel)7 Entity (net.minecraft.world.entity.Entity)7 Living (org.spongepowered.api.entity.living.Living)7 SpongeCommon (org.spongepowered.common.SpongeCommon)7 Component (net.kyori.adventure.text.Component)6 LivingEntity (net.minecraft.world.entity.LivingEntity)6 ItemStack (net.minecraft.world.item.ItemStack)6