Search in sources :

Example 21 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class MutableMapBlockEntityArchetypeBuffer method addBlockEntity.

@Override
public void addBlockEntity(final int x, final int y, final int z, final BlockEntityArchetype archetype) {
    this.checkRange(x, y, z);
    this.blockEntities.put(new Vector3i(x, y, z), Objects.requireNonNull(archetype, "Archetype cannot be null"));
}
Also used : Vector3i(org.spongepowered.math.vector.Vector3i)

Example 22 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class ReferentSchematicVolume method copyFrom.

@Override
public DataTransactionResult copyFrom(final int xTo, final int yTo, final int zTo, final int xFrom, final int yFrom, final int zFrom, final MergeFunction function) {
    final Vector3i transformed = this.inverseTransform(xTo, yTo, zTo);
    final Vector3i from = this.inverseTransform(xFrom, yFrom, zFrom);
    return this.applyReference(a -> a.copyFrom(transformed, from, function));
}
Also used : Vector3i(org.spongepowered.math.vector.Vector3i)

Example 23 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class BlockEvent_BreakEventMixin_Forge method bridge$syncTo.

@Override
public void bridge$syncTo(final Event event) {
    if (event instanceof ChangeBlockEvent.All && ((net.minecraftforge.eventbus.api.Event) (Object) this).isCanceled()) {
        final Vector3i pos = VecHelper.toVector3i(this.shadow$getPos());
        ((ChangeBlockEvent.All) event).transactions(Operations.BREAK.get()).filter(x -> x.original().position().equals(pos)).forEach(x -> x.setValid(false));
    }
}
Also used : ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) BlockEvent(net.minecraftforge.event.world.BlockEvent) ServerWorld(org.spongepowered.api.world.server.ServerWorld) ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) Event(org.spongepowered.api.event.Event) ForgeEventBridge_Forge(org.spongepowered.forge.launch.bridge.event.ForgeEventBridge_Forge) BlockTypes(org.spongepowered.api.block.BlockTypes) Operations(org.spongepowered.api.block.transaction.Operations) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) BlockState(org.spongepowered.api.block.BlockState) Mixin(org.spongepowered.asm.mixin.Mixin) BlockTransaction(org.spongepowered.api.block.transaction.BlockTransaction) VecHelper(org.spongepowered.common.util.VecHelper) LevelAccessor(net.minecraft.world.level.LevelAccessor) Collections(java.util.Collections) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Vector3i(org.spongepowered.math.vector.Vector3i) Vector3i(org.spongepowered.math.vector.Vector3i)

Example 24 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class VolumeTransformationTest method testTransformationsOfPositions.

@MethodSource("testTransformationsOfPositions")
@ParameterizedTest
void testTransformationsOfPositions(final Vector3i min, final Vector3i max, final Vector3i origin, final Vector3i testForRoundTrip, final int rotationCount, final StubRotations wanted) {
    final SpongeArchetypeVolume volume = VolumeTransformationTest.fillVolume(min, max, origin);
    final Vector3i size = volume.size();
    final Vector3i relativeMin = volume.min();
    final Vector3d center = volume.logicalCenter();
    ArchetypeVolume intermediary = volume;
    for (int i = 0; i < rotationCount; i++) {
        intermediary = intermediary.transform(Transformation.builder().origin(center).rotate(wanted).build());
    }
    Rotation expected = Rotations.NONE.get();
    for (int i = 0; i < rotationCount; i++) {
        expected = expected.and(wanted);
    }
    final Transformation expectedTransform = Transformation.builder().origin(center).rotate(expected).build();
    final Transformation inverse = expectedTransform.inverse();
    final ArchetypeVolume rotated = intermediary;
    if (rotationCount > 0) {
        final Vector3d preliminaryTransformed = expectedTransform.transformPosition(testForRoundTrip.toDouble());
        Vector3i unTransformed = preliminaryTransformed.round().toInt();
        for (int i = 0; i < rotationCount; i++) {
            unTransformed = ((AbstractReferentArchetypeVolume) rotated).inverseTransform(unTransformed.x(), unTransformed.y(), unTransformed.z());
        }
        Assertions.assertEquals(testForRoundTrip, unTransformed);
    }
    for (int x = 0; x < size.x(); x++) {
        for (int y = 0; y < size.y(); y++) {
            for (int z = 0; z < size.z(); z++) {
                final int relativeX = x + relativeMin.x();
                final int relativeY = y + relativeMin.y();
                final int relativeZ = z + relativeMin.z();
                final Vector3d rawRelativePosition = new Vector3d(relativeX, relativeY, relativeZ);
                final BlockState untransformedState = volume.block(relativeX, relativeY, relativeZ);
                final Vector3i transformedPosition = expectedTransform.transformPosition(rawRelativePosition).toInt();
                final BlockState transformedState = rotated.block(transformedPosition.x(), transformedPosition.y(), transformedPosition.z());
                Assertions.assertEquals(untransformedState, transformedState, () -> String.format("Block Check Failed!\nOriginal(%d, %d, %d): %s\nTransformed(%d, %d, %d): %s\n", relativeX, relativeY, relativeZ, untransformedState, transformedPosition.x(), transformedPosition.y(), transformedPosition.z(), transformedState));
            }
        }
    }
    if (rotationCount < 0) {
        return;
    }
    // At this point, we should have an abstract referent volume at least
    rotated.blockStateStream(rotated.min(), rotated.max(), StreamOptions.lazily()).forEach((rotatedRef, type, x, y, z) -> {
        final Vector3d transformedPos = new Vector3d(x, y, z);
        // We have this offset in the stream, so we have to undo it here.
        final Vector3d invertedTransformedPos = inverse.transformPosition(transformedPos.add(VolumePositionTranslators.BLOCK_OFFSET)).sub(VolumePositionTranslators.BLOCK_OFFSET);
        final Vector3i invertedBlockPos = invertedTransformedPos.toInt();
        final Vector3i expectedPos;
        Assertions.assertTrue(type instanceof StubState, () -> String.format("expected state to be a stub state for pos: [%f, %f, %f] but got %s", x, y, z, type));
        Assertions.assertNotEquals(((StubState) type).deducedPos, VolumeTransformationTest.INVALID_STUB_POSITION, () -> String.format("expected to have a positioned stub state: [%f, %f, %f] but got %s", x, y, z, type));
        expectedPos = ((StubState) type).deducedPos;
        Assertions.assertEquals(expectedPos, invertedBlockPos, () -> String.format("expected untransformed position %s for state %s does not match reverse transformed position: %s", expectedPos, type, invertedBlockPos));
        final BlockState block = volume.block(expectedPos.x(), expectedPos.y(), expectedPos.z());
        Assertions.assertEquals(type, block, () -> String.format("Expected deduced state to be equal from the original target volume but had a mismatch: Original target %s does not match %s", block, type));
    });
}
Also used : AbstractReferentArchetypeVolume(org.spongepowered.common.world.volume.buffer.archetype.AbstractReferentArchetypeVolume) ArchetypeVolume(org.spongepowered.api.world.volume.archetype.ArchetypeVolume) SpongeArchetypeVolume(org.spongepowered.common.world.volume.buffer.archetype.SpongeArchetypeVolume) Transformation(org.spongepowered.api.util.transformation.Transformation) BlockState(org.spongepowered.api.block.BlockState) SpongeArchetypeVolume(org.spongepowered.common.world.volume.buffer.archetype.SpongeArchetypeVolume) Vector3d(org.spongepowered.math.vector.Vector3d) StubState(org.spongepowered.common.test.stub.block.StubState) Vector3i(org.spongepowered.math.vector.Vector3i) Rotation(org.spongepowered.api.util.rotation.Rotation) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with Vector3i

use of org.spongepowered.math.vector.Vector3i 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

Vector3i (org.spongepowered.math.vector.Vector3i)59 Vector3d (org.spongepowered.math.vector.Vector3d)22 Nullable (org.checkerframework.checker.nullness.qual.Nullable)15 BlockPos (net.minecraft.core.BlockPos)14 BlockState (org.spongepowered.api.block.BlockState)14 Stream (java.util.stream.Stream)13 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)12 StreamOptions (org.spongepowered.api.world.volume.stream.StreamOptions)12 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)11 VolumeElement (org.spongepowered.api.world.volume.stream.VolumeElement)11 Tuple (net.minecraft.util.Tuple)10 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)10 VolumeStream (org.spongepowered.api.world.volume.stream.VolumeStream)10 Function (java.util.function.Function)9 Biome (org.spongepowered.api.world.biome.Biome)9 Collection (java.util.Collection)8 Objects (java.util.Objects)8 Optional (java.util.Optional)8 UUID (java.util.UUID)8 Entity (org.spongepowered.api.entity.Entity)8