use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.
the class LevelChunkMixin_API method blockStateStream.
@Override
public VolumeStream<WorldChunk, BlockState> blockStateStream(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 ArrayMutableBlockBuffer backingVolume;
if (shouldCarbonCopy) {
backingVolume = new ArrayMutableBlockBuffer(min, size);
} else {
backingVolume = null;
}
return VolumeStreamUtils.<WorldChunk, BlockState, net.minecraft.world.level.block.state.BlockState, ChunkAccess, BlockPos>generateStream(options, // Ref
(WorldChunk) this, (LevelChunk) (Object) this, // Entity Accessor
VolumeStreamUtils.getBlockStatesForSections(min, max), // IdentityFunction
(pos, blockState) -> {
if (shouldCarbonCopy) {
backingVolume.setBlock(pos, blockState);
}
}, // Biome by block position
(key, biome) -> key, // Filtered Position Entity Accessor
(blockPos, world) -> {
final net.minecraft.world.level.block.state.BlockState tileEntity = shouldCarbonCopy ? backingVolume.getBlock(blockPos) : ((LevelReader) world).getBlockState(blockPos);
return new Tuple<>(blockPos, tileEntity);
});
}
use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.
the class LevelChunkMixin_API method entityStream.
@Override
public VolumeStream<WorldChunk, Entity> entityStream(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 ObjectArrayMutableEntityBuffer backingVolume;
if (shouldCarbonCopy) {
backingVolume = new ObjectArrayMutableEntityBuffer(min, size);
} else {
backingVolume = null;
}
return VolumeStreamUtils.<WorldChunk, Entity, net.minecraft.world.entity.Entity, LevelChunk, UUID>generateStream(options, this, (LevelChunk) (Object) this, // Entity Accessor
(chunk) -> VolumeStreamUtils.getEntitiesFromChunk(min, max, chunk), // Entity Identity Function
VolumeStreamUtils.getOrCloneEntityWithVolume(shouldCarbonCopy, backingVolume, this.level), (key, entity) -> entity.getUUID(), // Filtered Position Entity Accessor
(entityUuid, chunk) -> {
final net.minecraft.world.entity.@Nullable Entity entity = shouldCarbonCopy ? (net.minecraft.world.entity.Entity) backingVolume.entity(entityUuid).orElse(null) : (net.minecraft.world.entity.Entity) chunk.world().entity(entityUuid).orElse(null);
if (entity == null) {
return null;
}
return new Tuple<>(entity.blockPosition(), entity);
});
}
use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.
the class LevelChunkMixin_API method biomeStream.
@Override
public VolumeStream<WorldChunk, Biome> biomeStream(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 ObjectArrayMutableBiomeBuffer backingVolume;
if (shouldCarbonCopy) {
final Registry<net.minecraft.world.level.biome.Biome> biomeRegistry = this.level.registryAccess().registry(Registry.BIOME_REGISTRY).map(wr -> ((Registry<net.minecraft.world.level.biome.Biome>) wr)).orElse(BuiltinRegistries.BIOME);
backingVolume = new ObjectArrayMutableBiomeBuffer(min, size, VolumeStreamUtils.nativeToSpongeRegistry(biomeRegistry));
} else {
backingVolume = null;
}
return VolumeStreamUtils.<WorldChunk, Biome, net.minecraft.world.level.biome.Biome, ChunkAccess, BlockPos>generateStream(options, // Ref
(WorldChunk) this, (LevelChunk) (Object) this, // Entity Accessor
VolumeStreamUtils.getBiomesForChunkByPos((LevelReader) (Object) this, min, max), // IdentityFunction
(pos, biome) -> {
if (shouldCarbonCopy) {
backingVolume.setBiome(pos, biome);
}
}, // Biome by block position
(key, biome) -> key, // Filtered Position Entity Accessor
(blockPos, world) -> {
final net.minecraft.world.level.biome.Biome biome = shouldCarbonCopy ? backingVolume.getNativeBiome(blockPos.getX(), blockPos.getY(), blockPos.getZ()) : ((LevelReader) world.world()).getBiome(blockPos);
return new Tuple<>(blockPos, biome);
});
}
use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.
the class LevelStemMixin method bridge$populateFromLevelData.
@Override
public void bridge$populateFromLevelData(final PrimaryLevelData levelData) {
final PrimaryLevelDataBridge levelDataBridge = (PrimaryLevelDataBridge) levelData;
this.impl$gameMode = (ResourceLocation) (Object) RegistryTypes.GAME_MODE.get().valueKey((GameMode) (Object) levelData.getGameType());
this.impl$difficulty = (ResourceLocation) (Object) RegistryTypes.DIFFICULTY.get().valueKey((Difficulty) (Object) levelData.getDifficulty());
this.impl$serializationBehavior = levelDataBridge.bridge$serializationBehavior().orElse(null);
this.impl$displayName = levelDataBridge.bridge$displayName().orElse(null);
this.impl$viewDistance = levelDataBridge.bridge$viewDistance().orElse(null);
this.impl$spawnPosition = new Vector3i(levelData.getXSpawn(), levelData.getYSpawn(), levelData.getZSpawn());
this.impl$loadOnStartup = levelDataBridge.bridge$loadOnStartup();
this.impl$performsSpawnLogic = levelDataBridge.bridge$performsSpawnLogic();
this.impl$hardcore = levelData.isHardcore();
this.impl$commands = levelData.getAllowCommands();
this.impl$pvp = levelDataBridge.bridge$pvp().orElse(null);
}
use of org.spongepowered.math.vector.Vector3i 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)));
}
Aggregations