Search in sources :

Example 1 with Mirror

use of org.spongepowered.api.util.mirror.Mirror in project SpongeCommon by SpongePowered.

the class AbstractReferentArchetypeVolume method applyTransformationsToStream.

private <T> VolumeStream<ArchetypeVolume, T> applyTransformationsToStream(final Vector3i min, final Vector3i max, final StreamOptions options, final StreamCreator<A, T> streamCreator, final VolumeStreamUtils.TriFunction<VolumeElement<ArchetypeVolume, T>, Supplier<Rotation>, Supplier<Mirror>, T> elementTransform) {
    final Vector3i transformedMin = this.min();
    final Vector3i transformedMax = this.max();
    VolumeStreamUtils.validateStreamArgs(min, max, transformedMin, transformedMax, options);
    final Vector3i minDiff = min.sub(transformedMin);
    final Vector3i maxDiff = transformedMax.sub(max);
    final boolean xMirror = this.transformation.mirror(Axis.X);
    final boolean zMirror = this.transformation.mirror(Axis.Z);
    final Supplier<Mirror> mirror = xMirror ? Mirrors.FRONT_BACK : zMirror ? Mirrors.LEFT_RIGHT : Mirrors.NONE;
    return this.applyReference(a -> streamCreator.createStream(a, a.min().add(minDiff), a.max().sub(maxDiff), options)).transform(e -> VolumeElement.of(this, elementTransform.apply(e, this.transformation::rotation, mirror), this.transformStreamBlockPosition(e.position().add(VolumePositionTranslators.BLOCK_OFFSET)).sub(VolumePositionTranslators.BLOCK_OFFSET)));
}
Also used : FluidState(org.spongepowered.api.fluid.FluidState) BiFunction(java.util.function.BiFunction) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Biome(org.spongepowered.api.world.biome.Biome) Rotation(org.spongepowered.api.util.rotation.Rotation) Mirror(org.spongepowered.api.util.mirror.Mirror) Map(java.util.Map) EntityArchetypeVolume(org.spongepowered.api.world.volume.archetype.entity.EntityArchetypeVolume) ArchetypeVolume(org.spongepowered.api.world.volume.archetype.ArchetypeVolume) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockEntityArchetype(org.spongepowered.api.block.entity.BlockEntityArchetype) BiomeVolume(org.spongepowered.api.world.volume.biome.BiomeVolume) VolumeStream(org.spongepowered.api.world.volume.stream.VolumeStream) BlockEntityArchetypeVolume(org.spongepowered.api.world.volume.archetype.block.entity.BlockEntityArchetypeVolume) VolumePositionTranslators(org.spongepowered.api.world.volume.stream.VolumePositionTranslators) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Axis(org.spongepowered.api.util.Axis) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) Collectors(java.util.stream.Collectors) BlockState(org.spongepowered.api.block.BlockState) Mirrors(org.spongepowered.api.util.mirror.Mirrors) Transformation(org.spongepowered.api.util.transformation.Transformation) Objects(java.util.Objects) Consumer(java.util.function.Consumer) Stream(java.util.stream.Stream) Vector3d(org.spongepowered.math.vector.Vector3d) Volume(org.spongepowered.api.world.volume.Volume) VolumeStreamUtils(org.spongepowered.common.world.volume.VolumeStreamUtils) EntityArchetypeEntry(org.spongepowered.api.world.volume.archetype.entity.EntityArchetypeEntry) MemoizedSupplier(org.spongepowered.common.util.MemoizedSupplier) Optional(java.util.Optional) BlockVolume(org.spongepowered.api.world.volume.block.BlockVolume) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) Vector3i(org.spongepowered.math.vector.Vector3i) Vector3i(org.spongepowered.math.vector.Vector3i) Mirror(org.spongepowered.api.util.mirror.Mirror)

Example 2 with Mirror

use of org.spongepowered.api.util.mirror.Mirror in project SpongeCommon by SpongePowered.

the class VolumeTransformationTest method setup.

@BeforeAll
static void setup() {
    VolumeTransformationTest.guice.injectMembers(new DummyInjectable());
    final StubGame game = (StubGame) Sponge.game();
    final SpongeFactoryProvider factoryProvider = game.factoryProvider();
    final SpongeBuilderProvider builderProvider = game.builderProvider();
    // Set up Rotations
    final StubbedRegistry<Rotation> rotation = new StubbedRegistry<>(() -> RegistryTypes.ROTATION, (k) -> Rotations.NONE.get());
    // Set up Blocks and BlockState
    final StubbedRegistry<BlockType> blocktypes = new StubbedRegistry<>(() -> RegistryTypes.BLOCK_TYPE, StubBlock::new);
    // Set up biomes
    final StubbedRegistry<Biome> biomes = new StubbedRegistry<>(() -> RegistryTypes.BIOME, (key) -> Mockito.mock(Biome.class));
    // Set up palettes
    final StubbedRegistry<PaletteType<?, ?>> paletteTypeRegistry = new StubbedRegistry<>(() -> RegistryTypes.PALETTE_TYPE, (key) -> new StubPaletteType<>());
    factoryProvider.registerFactory(RegistryType.Factory.class, new SpongeRegistryType.FactoryImpl());
    factoryProvider.registerFactory(RegistryKey.Factory.class, new SpongeRegistryKey.FactoryImpl());
    factoryProvider.registerFactory(PaletteReference.Factory.class, new SpongePaletteReferenceFactory());
    // and finally, set up the resourcekey stuff
    factoryProvider.registerFactory(ResourceKey.Factory.class, new StubRegistryFactory());
    game.register(rotation);
    game.register(blocktypes);
    game.register(biomes);
    game.register(paletteTypeRegistry);
    final StubbedRegistry<Mirror> mirror = new StubbedRegistry<>(() -> RegistryTypes.MIRROR, (k) -> Mockito.mock(Mirror.class));
    StubMirror.registerDefaults(mirror);
    game.register(mirror);
    builderProvider.register(Transformation.Builder.class, SpongeTransformationBuilder::new);
    builderProvider.register(StreamOptions.Builder.class, SpongeStreamOptionsBuilder::new);
    StubRotations.registerDefaults(rotation);
    paletteTypeRegistry.register(new StubKey("sponge", "block_state_palette"), new StubBlockStatePaletteType());
}
Also used : SpongeFactoryProvider(org.spongepowered.common.registry.SpongeFactoryProvider) Transformation(org.spongepowered.api.util.transformation.Transformation) StubKey(org.spongepowered.common.test.stub.StubKey) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) PaletteType(org.spongepowered.api.world.schematic.PaletteType) StubBlockStatePaletteType(org.spongepowered.common.test.stub.world.schematic.StubBlockStatePaletteType) StubPaletteType(org.spongepowered.common.test.stub.world.schematic.StubPaletteType) PaletteReference(org.spongepowered.api.world.schematic.PaletteReference) Biome(org.spongepowered.api.world.biome.Biome) SpongeRegistryType(org.spongepowered.common.registry.SpongeRegistryType) SpongeRegistryKey(org.spongepowered.common.registry.SpongeRegistryKey) StubBlock(org.spongepowered.common.test.stub.block.StubBlock) SpongeStreamOptionsBuilder(org.spongepowered.common.world.volume.stream.SpongeStreamOptionsBuilder) StubGame(org.spongepowered.common.test.stub.StubGame) StubRegistryFactory(org.spongepowered.common.test.stub.registry.StubRegistryFactory) SpongeRegistryType(org.spongepowered.common.registry.SpongeRegistryType) RegistryType(org.spongepowered.api.registry.RegistryType) SpongeBuilderProvider(org.spongepowered.common.registry.SpongeBuilderProvider) Rotation(org.spongepowered.api.util.rotation.Rotation) StubbedRegistry(org.spongepowered.common.test.stub.registry.StubbedRegistry) StubBlockStatePaletteType(org.spongepowered.common.test.stub.world.schematic.StubBlockStatePaletteType) ResourceKey(org.spongepowered.api.ResourceKey) BlockType(org.spongepowered.api.block.BlockType) Mirror(org.spongepowered.api.util.mirror.Mirror) StubMirror(org.spongepowered.common.test.stub.util.StubMirror) RegistryKey(org.spongepowered.api.registry.RegistryKey) SpongeRegistryKey(org.spongepowered.common.registry.SpongeRegistryKey) SpongePaletteReferenceFactory(org.spongepowered.common.world.schematic.SpongePaletteReferenceFactory) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

Mirror (org.spongepowered.api.util.mirror.Mirror)2 Rotation (org.spongepowered.api.util.rotation.Rotation)2 Transformation (org.spongepowered.api.util.transformation.Transformation)2 Biome (org.spongepowered.api.world.biome.Biome)2 StreamOptions (org.spongepowered.api.world.volume.stream.StreamOptions)2 Collection (java.util.Collection)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 BiFunction (java.util.function.BiFunction)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 ResourceKey (org.spongepowered.api.ResourceKey)1 BlockState (org.spongepowered.api.block.BlockState)1