use of org.spongepowered.api.world.chunk.WorldChunk in project SpongeCommon by SpongePowered.
the class ChunkMapMixin method impl$onSave.
@Inject(method = "save", at = @At(value = "HEAD"), cancellable = true)
private void impl$onSave(final ChunkAccess var1, final CallbackInfoReturnable<Boolean> cir) {
if (var1 instanceof WorldChunk) {
if (ShouldFire.CHUNK_EVENT_SAVE_PRE) {
final Vector3i chunkPos = new Vector3i(var1.getPos().x, 0, var1.getPos().z);
final ChunkEvent.Save.Pre postSave = SpongeEventFactory.createChunkEventSavePre(PhaseTracker.getInstance().currentCause(), ((WorldChunk) var1), chunkPos, (ResourceKey) (Object) this.level.dimension().location());
SpongeCommon.post(postSave);
if (postSave.isCancelled()) {
cir.setReturnValue(false);
}
}
}
}
use of org.spongepowered.api.world.chunk.WorldChunk in project SpongeCommon by SpongePowered.
the class EntityVolumeTest method onRegisterCommands.
@Listener
public void onRegisterCommands(final RegisterCommandEvent<Command.Parameterized> event) {
Command.Parameterized command = Command.builder().executor((ctx) -> {
final Object root = ctx.cause().root();
if (!(root instanceof Locatable)) {
throw new CommandException(Component.text("You must be locatable to use this command!"));
}
final Audience audience = ctx.cause().audience();
final ServerLocation serverLocation = ((Locatable) root).serverLocation();
final WorldChunk chunk = serverLocation.world().chunk(serverLocation.chunkPosition());
final Collection<? extends Entity> chunkEntities = chunk.entities();
final Collection<? extends Entity> worldEntities = serverLocation.world().entities();
final boolean worldContainsChunkEntities = serverLocation.world().entities().containsAll(chunkEntities);
audience.sendMessage(testResult("World contains chunk entities test", worldContainsChunkEntities));
final boolean worldContainsMoreEntitiesThanChunk = worldEntities.size() > chunkEntities.size();
audience.sendMessage(testResult("World contains more entities than chunk test", worldContainsMoreEntitiesThanChunk).append(Component.text(" (World " + worldEntities.size() + " vs Chunk " + chunkEntities.size() + ")")));
final boolean chunkEntitiesIsSameAsAABB = chunk.entities(AABB.of(chunk.min(), chunk.max())).equals(chunkEntities);
audience.sendMessage(testResult(".entities is the same as AABB of chunk", chunkEntitiesIsSameAsAABB));
audience.sendMessage(Component.text("See console for a list of all entities."));
this.logger.info(chunkEntities.size() + " entities in chunk " + chunk.chunkPosition() + ":\n" + chunkEntities);
this.logger.info("---------");
this.logger.info(worldEntities.size() + " entities in world " + serverLocation.world().properties().key() + ":\n" + worldEntities);
return CommandResult.success();
}).build();
event.register(this.plugin, command, "checkentitymethods");
}
use of org.spongepowered.api.world.chunk.WorldChunk in project SpongeCommon by SpongePowered.
the class LevelChunkMixin_API method blockEntityStream.
@Override
public VolumeStream<WorldChunk, BlockEntity> blockEntityStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
VolumeStreamUtils.validateStreamArgs(Objects.requireNonNull(min, "min"), Objects.requireNonNull(max, "max"), Objects.requireNonNull(options, "options"));
final boolean shouldCarbonCopy = options.carbonCopy();
final Vector3i size = max.sub(min).add(1, 1, 1);
@MonotonicNonNull final ObjectArrayMutableBlockEntityBuffer backingVolume;
if (shouldCarbonCopy) {
backingVolume = new ObjectArrayMutableBlockEntityBuffer(min, size);
} else {
backingVolume = null;
}
return VolumeStreamUtils.<WorldChunk, BlockEntity, net.minecraft.world.level.block.entity.BlockEntity, ChunkAccess, BlockPos>generateStream(options, // Ref
(WorldChunk) this, (LevelChunk) (Object) this, // Entity Accessor
this::impl$getBlockEntitiesStream, // IdentityFunction
VolumeStreamUtils.getBlockEntityOrCloneToBackingVolume(shouldCarbonCopy, backingVolume, this.level), // Biome by block position
(key, biome) -> key, // Filtered Position Entity Accessor
(blockPos, world) -> {
final net.minecraft.world.level.block.entity.@Nullable BlockEntity tileEntity = shouldCarbonCopy ? (net.minecraft.world.level.block.entity.BlockEntity) backingVolume.blockEntity(blockPos.getX(), blockPos.getY(), blockPos.getZ()).orElse(null) : ((LevelReader) world).getBlockEntity(blockPos);
return new Tuple<>(blockPos, tileEntity);
});
}
Aggregations