use of net.minecraft.world.level.chunk.LevelChunk 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 net.minecraft.world.level.chunk.LevelChunk in project SpongeCommon by SpongePowered.
the class UpdateOrCreateNewTileEntityPostPlacementEffect method processSideEffect.
@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
final ServerLevel serverWorld = pipeline.getServerWorld();
final LevelChunk chunk = pipeline.getAffectedChunk();
@Nullable final BlockEntity maybeNewTileEntity = chunk.getBlockEntity(oldState.pos, LevelChunk.EntityCreationType.CHECK);
if (((BlockStateBridge) newState).bridge$hasTileEntity()) {
if (maybeNewTileEntity == null) {
// tileentity1 = ((ITileEntityProvider)block).createNewTileEntity(this.world); // Vanilla
// tileentity1 = state.createTileEntity(this.world); // Forge
// We cast to our bridge for easy access
serverWorld.setBlockEntity(oldState.pos, ((BlockStateBridge) newState).bridge$createNewTileEntity(serverWorld));
} else {
maybeNewTileEntity.clearCache();
}
}
return EffectResult.NULL_PASS;
}
use of net.minecraft.world.level.chunk.LevelChunk in project SpongeCommon by SpongePowered.
the class PacketState method associateNeighborStateNotifier.
@Override
public void associateNeighborStateNotifier(final P unwindingContext, final BlockPos sourcePos, final Block block, final BlockPos notifyPos, final ServerLevel minecraftWorld, final PlayerTracker.Type notifier) {
final Player player = unwindingContext.getSpongePlayer();
final LevelChunk chunk = minecraftWorld.getChunkAt(notifyPos);
((LevelChunkBridge) chunk).bridge$setBlockNotifier(notifyPos, player.uniqueId());
}
use of net.minecraft.world.level.chunk.LevelChunk in project SpongeCommon by SpongePowered.
the class ChunkMapMixin method impl$onSetUnloaded.
@Redirect(method = "lambda$scheduleUnload$10", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;unload(Lnet/minecraft/world/level/chunk/LevelChunk;)V"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;save(Lnet/minecraft/world/level/chunk/ChunkAccess;)Z")))
private void impl$onSetUnloaded(final ServerLevel level, final LevelChunk chunk) {
final Vector3i chunkPos = new Vector3i(chunk.getPos().x, 0, chunk.getPos().z);
if (ShouldFire.CHUNK_EVENT_UNLOAD_PRE) {
final ChunkEvent.Unload event = SpongeEventFactory.createChunkEventUnloadPre(PhaseTracker.getInstance().currentCause(), (WorldChunk) chunk, chunkPos, (ResourceKey) (Object) this.level.dimension().location());
SpongeCommon.post(event);
}
level.unload(chunk);
for (final Direction dir : Constants.Chunk.CARDINAL_DIRECTIONS) {
final Vector3i neighborPos = chunkPos.add(dir.asBlockOffset());
final ChunkAccess neighbor = this.level.getChunk(neighborPos.x(), neighborPos.z(), ChunkStatus.EMPTY, false);
if (neighbor instanceof LevelChunk) {
final int index = DirectionUtil.directionToIndex(dir);
final int oppositeIndex = DirectionUtil.directionToIndex(dir.opposite());
((LevelChunkBridge) chunk).bridge$setNeighborChunk(index, null);
((LevelChunkBridge) neighbor).bridge$setNeighborChunk(oppositeIndex, null);
}
}
if (ShouldFire.CHUNK_EVENT_UNLOAD_POST) {
final ChunkEvent.Unload event = SpongeEventFactory.createChunkEventUnloadPost(PhaseTracker.getInstance().currentCause(), chunkPos, (ResourceKey) (Object) this.level.dimension().location());
SpongeCommon.post(event);
}
}
use of net.minecraft.world.level.chunk.LevelChunk in project SpongeCommon by SpongePowered.
the class ChunkHolderMixin method impl$throwChunkGeneratedEvent.
@Inject(method = "replaceProtoChunk(Lnet/minecraft/world/level/chunk/ImposterProtoChunk;)V", at = @At("TAIL"))
private void impl$throwChunkGeneratedEvent(final ImposterProtoChunk imposter, final CallbackInfo ci) {
if (!ShouldFire.CHUNK_EVENT_GENERATED) {
return;
}
final LevelChunk chunk = imposter.getWrapped();
final Vector3i chunkPos = VecHelper.toVector3i(chunk.getPos());
final ChunkEvent.Generated event = SpongeEventFactory.createChunkEventGenerated(PhaseTracker.getInstance().currentCause(), chunkPos, (ResourceKey) (Object) chunk.getLevel().dimension().location());
SpongeCommon.post(event);
}
Aggregations