Search in sources :

Example 61 with Vector3d

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

the class FireworkRocketItemMixin method impl$throwConstructPreEvent.

/**
 * Private method for bridging the duplicate between
 * {@link #spongeImpl$ThrowPreBeforeSpawning(World, PlayerEntity, Hand, CallbackInfoReturnable, ItemStack)} and
 * {@link #spongeImpl$ThrowPrimeEventsIfCancelled(ItemUseContext, CallbackInfoReturnable)}
 * since both follow the same logic, but differ in how they are called.
 *
 * @param world The world
 * @param player The player
 * @param usedItem The used item
 * @return True if the event is cancelled and the callback needs to be cancelled
 */
private boolean impl$throwConstructPreEvent(final Level world, final net.minecraft.world.entity.player.Player player, final ItemStack usedItem) {
    if (ShouldFire.CONSTRUCT_ENTITY_EVENT_PRE && !((LevelBridge) world).bridge$isFake()) {
        try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
            frame.addContext(EventContextKeys.USED_ITEM, ItemStackUtil.snapshotOf(usedItem));
            frame.addContext(EventContextKeys.PROJECTILE_SOURCE, (ProjectileSource) player);
            frame.pushCause(player);
            final ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(frame.currentCause(), ServerLocation.of((ServerWorld) world, player.getX(), player.getY(), player.getZ()), new Vector3d(0, 0, 0), EntityTypes.FIREWORK_ROCKET.get());
            return SpongeCommon.post(event);
        }
    }
    return false;
}
Also used : ConstructEntityEvent(org.spongepowered.api.event.entity.ConstructEntityEvent) ServerWorld(org.spongepowered.api.world.server.ServerWorld) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) Vector3d(org.spongepowered.math.vector.Vector3d) CauseStackManager(org.spongepowered.api.event.CauseStackManager)

Example 62 with Vector3d

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

the class SpongeAABBTest method testContainsCoordinates.

@Test
void testContainsCoordinates() {
    final AABB aabb = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
    Assertions.assertTrue(aabb.contains(5, 3, 11));
    Assertions.assertTrue(aabb.contains(7, 3, 11));
    Assertions.assertTrue(aabb.contains(5, 4, 11));
    Assertions.assertTrue(aabb.contains(5, 3, 13));
    Assertions.assertFalse(aabb.contains(-1, 3, 11));
    Assertions.assertFalse(aabb.contains(5, 11, 11));
    Assertions.assertFalse(aabb.contains(5, 3, 14));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 63 with Vector3d

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

the class SpongeAABBTest method testOffsetVector3i.

@Test
void testOffsetVector3i() {
    final AABB aabb1 = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
    final AABB aabb2 = new SpongeAABB(new Vector3d(11, 0, 4), new Vector3d(17, 8, 14));
    Assertions.assertEquals(aabb2, aabb1.offset(new Vector3i(10, -2, 1)));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) Vector3i(org.spongepowered.math.vector.Vector3i) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 64 with Vector3d

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

the class SpongeAABBTest method testContainsVector3i.

@Test
void testContainsVector3i() {
    final AABB aabb = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
    Assertions.assertTrue(aabb.contains(new Vector3i(5, 3, 11)));
    Assertions.assertFalse(aabb.contains(new Vector3i(-1, 3, 11)));
    Assertions.assertFalse(aabb.contains(new Vector3i(5, 11, 11)));
    Assertions.assertFalse(aabb.contains(new Vector3i(5, 3, 14)));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) Vector3i(org.spongepowered.math.vector.Vector3i) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 65 with Vector3d

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

the class SpongeAABBTest method testOffsetVector3d.

@Test
void testOffsetVector3d() {
    final AABB aabb1 = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
    final AABB aabb2 = new SpongeAABB(new Vector3d(11, 0, 4), new Vector3d(17, 8, 14));
    Assertions.assertEquals(aabb2, aabb1.offset(new Vector3d(10, -2, 1)));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Aggregations

Vector3d (org.spongepowered.math.vector.Vector3d)71 Vector3i (org.spongepowered.math.vector.Vector3i)16 CauseStackManager (org.spongepowered.api.event.CauseStackManager)14 AABB (org.spongepowered.api.util.AABB)14 Test (org.junit.jupiter.api.Test)13 ServerWorld (org.spongepowered.api.world.server.ServerWorld)13 BlockPos (net.minecraft.core.BlockPos)8 ServerLevel (net.minecraft.server.level.ServerLevel)7 BlockState (org.spongepowered.api.block.BlockState)7 Transformation (org.spongepowered.api.util.transformation.Transformation)7 Function (java.util.function.Function)6 IntStream (java.util.stream.IntStream)6 Stream (java.util.stream.Stream)6 Entity (org.spongepowered.api.entity.Entity)6 MoveEntityEvent (org.spongepowered.api.event.entity.MoveEntityEvent)6 ServerLocation (org.spongepowered.api.world.server.ServerLocation)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)5 BlockType (org.spongepowered.api.block.BlockType)5