当前位置: 首页>>代码示例>>Java>>正文


Java AABB类代码示例

本文整理汇总了Java中org.spongepowered.api.util.AABB的典型用法代码示例。如果您正苦于以下问题:Java AABB类的具体用法?Java AABB怎么用?Java AABB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AABB类属于org.spongepowered.api.util包,在下文中一共展示了AABB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBlockSelectionBox

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
@Override
public Optional<AABB> getBlockSelectionBox(int x, int y, int z) {
    final BlockState block = getBlock(x, y, z);
    if (block.getType() == BlockTypes.AIR) {
        return Optional.empty();
    }
    final ObjectProvider<AABB> aabbObjectProvider = ((LanternBlockType) block.getType()).getBoundingBoxProvider();
    if (aabbObjectProvider == null) {
        return Optional.empty();
    }
    final AABB aabb;
    if (aabbObjectProvider instanceof ConstantObjectProvider || aabbObjectProvider instanceof CachedSimpleObjectProvider
            || aabbObjectProvider instanceof SimpleObjectProvider) {
        aabb = aabbObjectProvider.get(block, null, null);
    } else {
        aabb = aabbObjectProvider.get(block, new Location<>(this.world, x, y, z), null);
    }
    return aabb == null ? Optional.empty() : Optional.of(aabb.offset(x, y, z));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:20,代码来源:LanternChunk.java

示例2: getIntersectingEntities

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
@Override
public Set<Entity> getIntersectingEntities(AABB box, Predicate<Entity> filter) {
    checkNotNull(box, "box");
    checkNotNull(filter, "filter");
    final ImmutableSet.Builder<Entity> entities = ImmutableSet.builder();
    final int maxX = ((int) Math.ceil(box.getMax().getX() + 2.0)) >> 4;
    final int minX = ((int) Math.floor(box.getMin().getX() - 2.0)) >> 4;
    final int maxYSection = fixEntityYSection(((int) Math.round(box.getMax().getY() + 2.0)) >> 4);
    final int minYSection = fixEntityYSection(((int) Math.round(box.getMin().getY() - 2.0)) >> 4);
    final int maxZ = ((int) Math.ceil(box.getMax().getZ() + 2.0)) >> 4;
    final int minZ = ((int) Math.floor(box.getMin().getZ() - 2.0)) >> 4;
    for (int x = minX; x <= maxX; x++) {
        for (int z = minZ; z <= maxZ; z++) {
            final LanternChunk chunk = getChunkManager().getChunkIfLoaded(x, z);
            if (chunk != null) {
                chunk.addIntersectingEntities(entities, maxYSection, minYSection, box, filter);
            }
        }
    }
    return entities.build();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:22,代码来源:LanternWorld.java

示例3: compileSidePropertyBitSet

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
private static BitSet compileSidePropertyBitSet(AABB boundingBox) {
    final BitSet bitSet = new BitSet(DIRECTION_INDEXES);
    if (isSideSolid(boundingBox, Direction.DOWN)) {
        bitSet.set(INDEX_DOWN);
    }
    if (isSideSolid(boundingBox, Direction.UP)) {
        bitSet.set(INDEX_UP);
    }
    if (isSideSolid(boundingBox, Direction.WEST)) {
        bitSet.set(INDEX_WEST);
    }
    if (isSideSolid(boundingBox, Direction.EAST)) {
        bitSet.set(INDEX_EAST);
    }
    if (isSideSolid(boundingBox, Direction.NORTH)) {
        bitSet.set(INDEX_NORTH);
    }
    if (isSideSolid(boundingBox, Direction.SOUTH)) {
        bitSet.set(INDEX_SOUTH);
    }
    return bitSet;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:BlockTypeBuilderImpl.java

示例4: isSideSolid

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
private static boolean isSideSolid(AABB boundingBox, @Nullable Direction face) {
    final Vector3d min = boundingBox.getMin();
    final Vector3d max = boundingBox.getMax();

    if (face == Direction.NORTH) {
        return min.getZ() == 0.0 && min.getX() == 0.0 && min.getY() == 0.0 && max.getX() >= 1.0 && max.getY() >= 1.0;
    } else if (face == Direction.SOUTH) {
        return min.getZ() == 1.0 && min.getX() == 0.0 && min.getY() == 0.0 && max.getX() >= 1.0 && max.getY() >= 1.0;
    } else if (face == Direction.WEST) {
        return min.getZ() == 0.0 && min.getY() == 0.0 && min.getZ() == 0.0 && max.getY() >= 1.0 && max.getZ() >= 1.0;
    } else if (face == Direction.EAST) {
        return min.getZ() == 1.0 && min.getY() == 0.0 && min.getZ() == 0.0 && max.getY() >= 1.0 && max.getZ() >= 1.0;
    } else if (face == Direction.DOWN) {
        return min.getZ() == 0.0 && min.getX() == 0.0 && min.getZ() == 0.0 && max.getX() == 1.0 && max.getZ() == 1.0;
    } else if (face == Direction.UP) {
        return min.getZ() == 1.0 && min.getX() == 0.0 && min.getZ() == 0.0 && max.getX() == 1.0 && max.getZ() == 1.0;
    } else {
        return false;
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:21,代码来源:BlockTypeBuilderImpl.java

示例5: getExtendedAABB

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
private static AABB getExtendedAABB(Direction direction) {
    switch (direction) {
        case NORTH:
            return NORTH;
        case EAST:
            return EAST;
        case WEST:
            return WEST;
        case SOUTH:
            return SOUTH;
        case UP:
            return UP;
        case DOWN:
            return DOWN;
        default:
            throw new UnsupportedOperationException();
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:19,代码来源:ShulkerBoxInteractionBehavior.java

示例6: validateOpenableSpace

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
@Override
protected boolean validateOpenableSpace(BehaviorContext context, Location<World> location, List<Runnable> tasks) {
    final Direction facing = location.getBlock().getTraitValue(LanternEnumTraits.FACING).get();
    final Location<World> relLocation = location.getBlockRelative(facing);
    final AABB aabb = relLocation.getExtent().getBlockSelectionBox(
            relLocation.getBlockPosition()).orElse(null);
    if (aabb != null && getExtendedAABB(facing).offset(
            relLocation.getBlockPosition()).intersects(aabb)) {
        final ReplaceableProperty replaceableProperty = relLocation.getProperty(ReplaceableProperty.class).orElse(null);
        // Replaceable blocks will be replaced when opened
        if (replaceableProperty != null && replaceableProperty.getValue()) {
            tasks.add(() -> context.addBlockChange(BlockSnapshotBuilder.create()
                    .location(relLocation)
                    .blockState(BlockTypes.AIR.getDefaultState())
                    .build()));
            // TODO: Use break block pipeline instead
            return true;
        }
        return false;
    }
    return true;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:ShulkerBoxInteractionBehavior.java

示例7: torch

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
public static AABB torch(BlockState blockState) {
    final Direction direction = blockState.get(Keys.DIRECTION).get();
    switch (direction) {
        case UP:
            return Torch.UP;
        case NORTH:
            return Torch.NORTH;
        case EAST:
            return Torch.EAST;
        case SOUTH:
            return Torch.SOUTH;
        case WEST:
            return Torch.WEST;
        default:
            throw new IllegalArgumentException();
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:BoundingBoxes.java

示例8: doubleChest

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
public static AABB doubleChest(BlockState blockState, @Nullable Location<World> location, @Nullable Direction face) {
    if (location != null) {
        for (Direction direction : Chest.DIRECTIONS) {
            if (blockState.getType() == location.getBlockRelative(direction).getBlock().getType()) {
                switch (direction) {
                    case NORTH:
                        return Chest.CONNECTED_NORTH;
                    case EAST:
                        return Chest.CONNECTED_EAST;
                    case SOUTH:
                        return Chest.CONNECTED_SOUTH;
                    case WEST:
                        return Chest.CONNECTED_WEST;
                    default:
                        throw new IllegalStateException();
                }
            }
        }
    }
    return Chest.DEFAULT;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:22,代码来源:BoundingBoxes.java

示例9: findArmorStandsAt

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
public Set<ArmorStand> findArmorStandsAt(Block block) {
    Chunk chunk = block.getChunk()
            .orElseThrow(() -> new IllegalStateException("Could not access the chunk of this block."));
    Vector3i blockPosition = block.getPosition();
    AABB aabb = new AABB(blockPosition, blockPosition.add(Vector3i.ONE));
    Set<Entity> entities = chunk.getIntersectingEntities(aabb, CustomItemServiceImpl::isCustomBlockArmorStand);
    Iterator<Entity> entityIterator = entities.iterator();

    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(entityIterator, Spliterator.ORDERED), false)
            .map(ArmorStand.class::cast)
            .collect(Collectors.toSet());
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:13,代码来源:CustomItemServiceImpl.java

示例10: getIntersectingBlockCollisionBoxes

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
@Override
public Set<AABB> getIntersectingBlockCollisionBoxes(AABB box) {
    checkNotNull(box, "box");
    final Vector3i min = box.getMin().toInt();
    final Vector3i max = box.getMax().toInt();
    checkVolumeBounds(min);
    checkVolumeBounds(max);
    final ImmutableSet.Builder<AABB> builder = ImmutableSet.builder();
    final int minX = min.getX();
    final int minY = min.getY();
    final int minZ = min.getZ();
    final int maxX = max.getX();
    final int maxY = max.getY();
    final int maxZ = max.getZ();
    for (int x = minX; x <= maxX; x++) {
        for (int z = minZ; z <= maxZ; z++) {
            for (int y = minY; y <= maxY; y++) {
                final Optional<AABB> optAABB = getBlockSelectionBox(x, y, z);
                if (optAABB.isPresent()) {
                    final AABB aabb = optAABB.get();
                    if (aabb.intersects(box)) {
                        builder.add(box);
                    }
                }
            }
        }
    }
    return builder.build();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:30,代码来源:LanternChunk.java

示例11: getIntersectingEntities

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
@Override
public Set<Entity> getIntersectingEntities(AABB box, Predicate<Entity> filter) {
    checkNotNull(box, "box");
    checkNotNull(filter, "filter");
    final ImmutableSet.Builder<Entity> entities = ImmutableSet.builder();
    final int maxYSection = fixEntityYSection(((int) Math.ceil(box.getMax().getY() + 2.0)) >> 4);
    final int minYSection = fixEntityYSection(((int) Math.floor(box.getMin().getY() - 2.0)) >> 4);
    addIntersectingEntities(entities, maxYSection, minYSection, box, filter);
    return entities.build();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:11,代码来源:LanternChunk.java

示例12: addIntersectingEntities

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
public void addIntersectingEntities(ImmutableSet.Builder<Entity> builder, int maxYSection, int minYSection, AABB box, Predicate<Entity> filter) {
    for (int i = minYSection; i <= maxYSection; i++) {
        forEachEntity(i, entity -> {
            final Optional<AABB> aabb = entity.getBoundingBox();
            if (aabb.isPresent()) {
                if (aabb.get().intersects(box) && filter.test(entity)) {
                    builder.add(entity);
                }
            } else if (box.contains(entity.getPosition()) && filter.test(entity)) {
                builder.add(entity);
            }
        });
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:15,代码来源:LanternChunk.java

示例13: addIntersectingEntitiesBoxes

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
public void addIntersectingEntitiesBoxes(ImmutableSet.Builder<AABB> builder, int maxYSection, int minYSection,
        AABB box, Predicate<Entity> filter) {
    for (int i = minYSection; i <= maxYSection; i++) {
        forEachEntity(i, entity -> {
            final Optional<AABB> aabb = entity.getBoundingBox();
            if (aabb.isPresent()) {
                if (aabb.get().intersects(box) && filter.test(entity)) {
                    builder.add(aabb.get());
                }
            } else if (box.contains(entity.getPosition()) && filter.test(entity)) {
                builder.add(aabb.get());
            }
        });
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:16,代码来源:LanternChunk.java

示例14: finalizeHarvestEvent

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
/**
 * Finalize the {@link HarvestEntityEvent}. This will spawn all
 * the dropped {@link Item}s and {@link ExperienceOrb}s. But only
 * if the event isn't cancelled.
 *
 * @param causeStack The cause stack
 * @param event The harvest event
 */
protected void finalizeHarvestEvent(CauseStack causeStack, HarvestEntityEvent event, List<ItemStackSnapshot> itemStackSnapshots) {
    if (event.isCancelled()) {
        return;
    }
    try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
        frame.pushCause(event);

        final int exp = event.getExperience();
        // No experience, don't spawn any entity
        if (exp > 0) {
            frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.EXPERIENCE);
            // Spawn a experience orb with the experience value
            LanternWorld.handleEntitySpawning(EntityTypes.EXPERIENCE_ORB, getTransform(),
                    entity -> entity.offer(Keys.CONTAINED_EXPERIENCE, exp));
        }

        frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
        // Collect entity drops
        collectDrops(causeStack, itemStackSnapshots);
        if (!itemStackSnapshots.isEmpty()) {
            final DropItemEvent.Pre preDropEvent = SpongeEventFactory.createDropItemEventPre(
                    frame.getCurrentCause(), ImmutableList.copyOf(itemStackSnapshots), Lists2.nonNullOf(itemStackSnapshots));
            Sponge.getEventManager().post(preDropEvent);
            if (!preDropEvent.isCancelled()) {
                final Transform<World> transform = getTransform().setPosition(
                        getBoundingBox().map(AABB::getCenter).orElse(Vector3d.ZERO));
                final List<EntitySpawningEntry> entries = itemStackSnapshots.stream()
                        .filter(snapshot -> !snapshot.isEmpty())
                        .map(snapshot -> new EntitySpawningEntry(EntityTypes.ITEM, transform, entity -> {
                            entity.offer(Keys.REPRESENTED_ITEM, snapshot);
                            entity.offer(Keys.PICKUP_DELAY, 15);
                        }))
                        .collect(Collectors.toList());
                LanternWorld.handleEntitySpawning(entries, SpongeEventFactory::createDropItemEventDestruct);
            }
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:47,代码来源:LanternLiving.java

示例15: pulsePhysics

import org.spongepowered.api.util.AABB; //导入依赖的package包/类
private void pulsePhysics() {
    // Get the current velocity
    Vector3d velocity = getVelocity();
    // Update the position based on the velocity
    setPosition(getPosition().add(velocity));

    // We will check if there is a collision box under the entity
    boolean ground = false;

    final AABB thisBox = getBoundingBox().get().offset(0, -0.1, 0);
    final Set<AABB> boxes = getWorld().getIntersectingBlockCollisionBoxes(thisBox);
    for (AABB box : boxes) {
        final Vector3d factor = box.getCenter().sub(thisBox.getCenter());
        if (Direction.getClosest(factor).isUpright()) {
            ground = true;
        }
    }
    if (!ground) {
        final Optional<Double> gravityFactor = get(LanternKeys.GRAVITY_FACTOR);
        if (gravityFactor.isPresent()) {
            // Apply the gravity factor
            velocity = velocity.add(0, -gravityFactor.get(), 0);
        }
    }
    velocity = velocity.mul(0.98, 0.98, 0.98);
    if (ground) {
        velocity = velocity.mul(1, -0.5, 1);
    }
    // Offer the velocity back
    offer(Keys.VELOCITY, velocity);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:32,代码来源:LanternItem.java


注:本文中的org.spongepowered.api.util.AABB类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。