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)));
}
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);
}
}
}
}
}
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;
}
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;
}
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());
}
Aggregations