Search in sources :

Example 1 with StubbedRegistry

use of org.spongepowered.common.test.stub.registry.StubbedRegistry 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)

Example 2 with StubbedRegistry

use of org.spongepowered.common.test.stub.registry.StubbedRegistry in project SpongeCommon by SpongePowered.

the class VolumeTransformationTest method fillVolume.

private static SpongeArchetypeVolume fillVolume(final Vector3i min, final Vector3i max, final Vector3i origin) {
    final Vector3i rawMin = min.min(max);
    final Vector3i rawMax = max.max(min);
    final Vector3i size = rawMax.sub(rawMin).add(Vector3i.ONE);
    final Vector3i relativeMin = rawMin.sub(origin);
    final RegistryHolder holder = Sponge.game();
    final SpongeArchetypeVolume volume = new SpongeArchetypeVolume(relativeMin, size, holder);
    final StubbedRegistry<BlockType> blockRegistry = (StubbedRegistry<BlockType>) RegistryTypes.BLOCK_TYPE.get();
    final Vector3i volMax = volume.max().add(Vector3i.ONE);
    IntStream.range(relativeMin.x(), volMax.x()).forEach(x -> IntStream.range(relativeMin.z(), volMax.z()).forEach(z -> IntStream.range(relativeMin.y(), volMax.y()).forEach(y -> {
        final BlockType block = blockRegistry.createEntry("minecraft", String.format("volumetest{%d, %d, %d}", x, y, z));
        final BlockState blockState = block.defaultState();
        volume.setBlock(x, y, z, blockState);
    })));
    return volume;
}
Also used : Game(org.spongepowered.api.Game) SpongeBuilderProvider(org.spongepowered.common.registry.SpongeBuilderProvider) Inject(com.google.inject.Inject) StubBlock(org.spongepowered.common.test.stub.block.StubBlock) AbstractReferentArchetypeVolume(org.spongepowered.common.world.volume.buffer.archetype.AbstractReferentArchetypeVolume) Biome(org.spongepowered.api.world.biome.Biome) PaletteReference(org.spongepowered.api.world.schematic.PaletteReference) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Mirror(org.spongepowered.api.util.mirror.Mirror) SpongeFactoryProvider(org.spongepowered.common.registry.SpongeFactoryProvider) PaletteType(org.spongepowered.api.world.schematic.PaletteType) ArchetypeVolume(org.spongepowered.api.world.volume.archetype.ArchetypeVolume) StubMirror(org.spongepowered.common.test.stub.util.StubMirror) StubBlockStatePaletteType(org.spongepowered.common.test.stub.world.schematic.StubBlockStatePaletteType) MethodSource(org.junit.jupiter.params.provider.MethodSource) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) StubPaletteType(org.spongepowered.common.test.stub.world.schematic.StubPaletteType) Sponge(org.spongepowered.api.Sponge) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) Arguments(org.junit.jupiter.params.provider.Arguments) BlockState(org.spongepowered.api.block.BlockState) Transformation(org.spongepowered.api.util.transformation.Transformation) Rotations(org.spongepowered.api.util.rotation.Rotations) Stream(java.util.stream.Stream) StubModule(org.spongepowered.common.test.stub.StubModule) SpongeArchetypeVolume(org.spongepowered.common.world.volume.buffer.archetype.SpongeArchetypeVolume) BlockType(org.spongepowered.api.block.BlockType) StubRegistryHolder(org.spongepowered.common.test.stub.registry.StubRegistryHolder) Strictness(org.mockito.quality.Strictness) IntStream(java.util.stream.IntStream) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) RegistryHolder(org.spongepowered.api.registry.RegistryHolder) StubbedRegistry(org.spongepowered.common.test.stub.registry.StubbedRegistry) Rotation(org.spongepowered.api.util.rotation.Rotation) SpongeRegistryType(org.spongepowered.common.registry.SpongeRegistryType) StubRotations(org.spongepowered.common.test.stub.util.StubRotations) ResourceKey(org.spongepowered.api.ResourceKey) StubKey(org.spongepowered.common.test.stub.StubKey) RegistryKey(org.spongepowered.api.registry.RegistryKey) VolumePositionTranslators(org.spongepowered.api.world.volume.stream.VolumePositionTranslators) SpongePaletteReferenceFactory(org.spongepowered.common.world.schematic.SpongePaletteReferenceFactory) RegistryType(org.spongepowered.api.registry.RegistryType) RegistryTypes(org.spongepowered.api.registry.RegistryTypes) SpongeRegistryKey(org.spongepowered.common.registry.SpongeRegistryKey) Injector(com.google.inject.Injector) StubRegistryFactory(org.spongepowered.common.test.stub.registry.StubRegistryFactory) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) StubState(org.spongepowered.common.test.stub.block.StubState) SpongeStreamOptionsBuilder(org.spongepowered.common.world.volume.stream.SpongeStreamOptionsBuilder) Vector3d(org.spongepowered.math.vector.Vector3d) Assertions(org.junit.jupiter.api.Assertions) Guice(com.google.inject.Guice) StubGame(org.spongepowered.common.test.stub.StubGame) Vector3i(org.spongepowered.math.vector.Vector3i) BlockState(org.spongepowered.api.block.BlockState) SpongeArchetypeVolume(org.spongepowered.common.world.volume.buffer.archetype.SpongeArchetypeVolume) BlockType(org.spongepowered.api.block.BlockType) Vector3i(org.spongepowered.math.vector.Vector3i) StubbedRegistry(org.spongepowered.common.test.stub.registry.StubbedRegistry) StubRegistryHolder(org.spongepowered.common.test.stub.registry.StubRegistryHolder) RegistryHolder(org.spongepowered.api.registry.RegistryHolder)

Aggregations

BeforeAll (org.junit.jupiter.api.BeforeAll)2 ResourceKey (org.spongepowered.api.ResourceKey)2 BlockType (org.spongepowered.api.block.BlockType)2 RegistryKey (org.spongepowered.api.registry.RegistryKey)2 RegistryType (org.spongepowered.api.registry.RegistryType)2 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 PaletteReference (org.spongepowered.api.world.schematic.PaletteReference)2 PaletteType (org.spongepowered.api.world.schematic.PaletteType)2 StreamOptions (org.spongepowered.api.world.volume.stream.StreamOptions)2 SpongeBuilderProvider (org.spongepowered.common.registry.SpongeBuilderProvider)2 SpongeFactoryProvider (org.spongepowered.common.registry.SpongeFactoryProvider)2 SpongeRegistryKey (org.spongepowered.common.registry.SpongeRegistryKey)2 SpongeRegistryType (org.spongepowered.common.registry.SpongeRegistryType)2 StubGame (org.spongepowered.common.test.stub.StubGame)2 StubKey (org.spongepowered.common.test.stub.StubKey)2 StubBlock (org.spongepowered.common.test.stub.block.StubBlock)2 StubRegistryFactory (org.spongepowered.common.test.stub.registry.StubRegistryFactory)2