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"));
}
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));
}
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));
}
}
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));
});
}
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;
}
Aggregations