當前位置: 首頁>>代碼示例>>Java>>正文


Java Vector3i.add方法代碼示例

本文整理匯總了Java中com.flowpowered.math.vector.Vector3i.add方法的典型用法代碼示例。如果您正苦於以下問題:Java Vector3i.add方法的具體用法?Java Vector3i.add怎麽用?Java Vector3i.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.flowpowered.math.vector.Vector3i的用法示例。


在下文中一共展示了Vector3i.add方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBlock

import com.flowpowered.math.vector.Vector3i; //導入方法依賴的package包/類
public Optional<Transform<World>> getBlock(final Transform<World> location, final boolean safe) {
	int max = location.getExtent().getBlockMax().getY() + 1;
	Vector3i destinationMax = new Vector3i(location.getLocation().getBlockX(), location.getLocation().getBlockY(), location.getLocation().getBlockZ());
	Vector3i destinationMin = new Vector3i(location.getLocation().getBlockX(), location.getLocation().getBlockY() - 1, location.getLocation().getBlockZ());
	Vector3i destination = null;
	while (destination == null && (destinationMin.getY() >= 0 || destinationMax.getY() <= max)) {
		if (destinationMax.getY() <= max && isBlock(location.getExtent(), destinationMax, safe)) {
			destination = destinationMax;
		} else if (destinationMin.getY() > 0 && isBlock(location.getExtent(), destinationMin, safe)) {
			destination = destinationMin;
		}
		if (destination == null) {
			if (destinationMax.getY() <= max) {
				destinationMax = destinationMax.add(0, 1, 0);
			}
			if (destinationMin.getY() >= 0) {
				destinationMin = destinationMin.sub(0, 1, 0);
			}
		}
	}
	if (destination != null){
		return Optional.of(location.setPosition(destination.toDouble().add(0.5, 0, 0.5)));
	}
	return Optional.empty();
}
 
開發者ID:EverCraft,項目名稱:EverAPI,代碼行數:26,代碼來源:UtilsLocation.java

示例2: handleItemInteraction

import com.flowpowered.math.vector.Vector3i; //導入方法依賴的package包/類
@Override
public BehaviorResult handleItemInteraction(Server server, Player player, Vector3i against, BlockFace face, ItemStack withItem) {
    if (withItem.getItemType() == ItemTypes.DIAMOND_HOE || withItem.getItemType() == ItemTypes.GOLDEN_HOE ||
            withItem.getItemType() == ItemTypes.IRON_HOE || withItem.getItemType() == ItemTypes.STONE_HOE ||
            withItem.getItemType() == ItemTypes.WOODEN_HOE) {
        Vector3i adjusted = against.add(face.getOffset());
        Optional<Block> originalBlockOptional = player.getLevel().getBlockIfChunkLoaded(adjusted);
        if (!originalBlockOptional.isPresent()) {
            return BehaviorResult.NOTHING;
        }

        if (BehaviorUtils.replaceBlockState(player, originalBlockOptional.get(), new BasicBlockState(BlockTypes.FARMLAND, null, null))) {
            return BehaviorResult.REDUCE_DURABILITY;
        } else {
            return BehaviorResult.NOTHING;
        }
    }
    return super.handleItemInteraction(server, player, against, face, withItem);
}
 
開發者ID:voxelwind,項目名稱:voxelwind,代碼行數:20,代碼來源:DirtBlockBehavior.java

示例3: addTarget

import com.flowpowered.math.vector.Vector3i; //導入方法依賴的package包/類
public void addTarget(BlockSnapshot pistonBlock, EnhancedCustomBlock block, BlockData blockData,
        Vector3i blockPos) {
    Direction pistonFacing = pistonBlock.getState().get(Keys.DIRECTION).get();
    boolean isRetracting;
    if (pistonBlock.getState().getType() == BlockTypes.PISTON_EXTENSION) {
        // Followed up from sticky piston - retraction has cause of the piston extension
        // See CustomBlockEventListeners#getPistonCause
        isRetracting = true;
    } else {
        isRetracting = pistonBlock.getState().get(Keys.EXTENDED).get();
    }
    Vector3i destPos;
    if (isRetracting) {
        destPos = blockPos.sub(pistonFacing.asBlockOffset());
    } else {
        destPos = blockPos.add(pistonFacing.asBlockOffset());
    }
    this.locations.put(destPos, new Tuple<>(blockPos, new ImmutablePair<>(block, blockData)));
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:20,代碼來源:WorldManager.java

示例4: onBlockNotify

import com.flowpowered.math.vector.Vector3i; //導入方法依賴的package包/類
@Listener
public void onBlockNotify(NotifyNeighborBlockEvent event, @First BlockSnapshot notifySource) {
    Optional<Location<World>> loc = notifySource.getLocation();
    if (!loc.isPresent()) {
        return;
    }
    Vector3i origin = loc.get().getBlockPosition();
    CustomWorld world = WorldManager.toCustomWorld(loc.get().getExtent());
    for (Iterator<Entry<Direction, BlockState>> iterator = event.getNeighbors().entrySet().iterator(); iterator
            .hasNext();) {
        Direction side = iterator.next().getKey();
        Vector3i notifyPos = origin.add(side.asBlockOffset());
        BlockNature block = world.getBlock(notifyPos);
        if (block != null) {
            boolean allow =
                    block.onNeighborNotify(world, notifyPos, notifySource.getPosition(), side.getOpposite());
            if (!allow) {
                iterator.remove();
            }
        }
    }
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:23,代碼來源:CustomBlockEventListeners.java

示例5: isChunkRequired

import com.flowpowered.math.vector.Vector3i; //導入方法依賴的package包/類
public boolean isChunkRequired(final Vector3i position)
{
    if(chunkMap.size() <= 2 || !chunkMap.containsKey(position))
        return false;

    lookup:
    for(Vector3i direction: Util.CARDINAL_DIRECTIONS)
    {
        Vector3i supported = position.add(direction);
        if(!chunkMap.containsKey(supported))
            continue;

        for(Vector3i secondDirection: Util.CARDINAL_DIRECTIONS)
        {
            Vector3i alternativeSupport = supported.add(secondDirection);
            if(alternativeSupport.equals(position))
                continue;

            if(chunkMap.containsKey(alternativeSupport))
                continue lookup;
        }

        return true;
    }

    return false;
}
 
開發者ID:GameModsBR,項目名稱:MyChunks,代碼行數:28,代碼來源:Zone.java

示例6: handleItemInteraction

import com.flowpowered.math.vector.Vector3i; //導入方法依賴的package包/類
@Override
public BehaviorResult handleItemInteraction(Server server, Player player, Vector3i against, BlockFace face, ItemStack withItem) {
    if (withItem != null) {
        if (withItem.getItemType() == BlockTypes.TOP_SNOW) {
            Vector3i adjusted = against.add(face.getOffset());
            Optional<Block> originalBlockOptional = player.getLevel().getBlockIfChunkLoaded(adjusted);
            if (!originalBlockOptional.isPresent()) {
                return BehaviorResult.NOTHING;
            }

            // Add another layer to the snow block if needed
            Block againstBlock = originalBlockOptional.get();
            if (againstBlock.getBlockState().getBlockType() == BlockTypes.TOP_SNOW && againstBlock.getBlockState().getBlockData() instanceof TopSnow) {
                int layer = ((TopSnow) againstBlock.getBlockState().getBlockData()).getLayers();
                if (layer >= 7) {
                    // Need to place a new block down.
                    return BehaviorResult.PLACE_BLOCK_AND_REMOVE_ITEM;
                } else {
                    BlockState newBlockState = new BasicBlockState(BlockTypes.TOP_SNOW, TopSnow.of(layer + 1), null);
                    return BehaviorUtils.replaceBlockState(player, againstBlock, newBlockState) ? BehaviorResult.REMOVE_ONE_ITEM : BehaviorResult.NOTHING;
                }
            }
        }
    }

    return super.handleItemInteraction(server, player, against, face, withItem);
}
 
開發者ID:voxelwind,項目名稱:voxelwind,代碼行數:28,代碼來源:TopSnowBlockBehavior.java

示例7: handleItemInteraction

import com.flowpowered.math.vector.Vector3i; //導入方法依賴的package包/類
@Override
public BehaviorResult handleItemInteraction(Server server, Player player, Vector3i against, BlockFace face, ItemStack withItem) {
    if (face == BlockFace.TOP) {
        Vector3i adjusted = against.add(face.getOffset());
        Optional<Block> originalBlockOptional = player.getLevel().getBlockIfChunkLoaded(adjusted);
        if (!originalBlockOptional.isPresent()) {
            return BehaviorResult.NOTHING;
        }

        // If a block is already on the farmland, don't proceed.
        if (originalBlockOptional.get().getBlockState().getBlockType() != BlockTypes.AIR) {
            return BehaviorResult.NOTHING;
        }

        // Seeds
        if (withItem.getItemType() == ItemTypes.SEEDS) {
            return BehaviorUtils.setBlockState(player, adjusted, new BasicBlockState(BlockTypes.CROPS, Crops.NEW, null)) ?
                    BehaviorResult.REMOVE_ONE_ITEM : BehaviorResult.NOTHING;
        }

        // TODO: Other seeds
        if (withItem.getItemType().isBlock()) {
            // Destroy the farmland.
            if (BehaviorUtils.replaceBlockState(player, originalBlockOptional.get(), new BasicBlockState(BlockTypes.DIRT, null, null))) {
                return BehaviorResult.PLACE_BLOCK_AND_REMOVE_ITEM;
            } else {
                return BehaviorResult.NOTHING;
            }
        }
    }
    return super.handleItemInteraction(server, player, against, face, withItem);
}
 
開發者ID:voxelwind,項目名稱:voxelwind,代碼行數:33,代碼來源:FarmlandBlockBehavior.java

示例8: findArmorStandsAt

import com.flowpowered.math.vector.Vector3i; //導入方法依賴的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

示例9: notifyAroundPoint

import com.flowpowered.math.vector.Vector3i; //導入方法依賴的package包/類
@Override
public void notifyAroundPoint(Vector3i pos) {
    for (Direction direction : Direction.values()) {
        if (direction.isCardinal() || direction.isUpright()) {
            Vector3i targetPos = pos.add(direction.asBlockOffset());
            BlockNature block = getBlock(targetPos);
            if (block != null) {
                block.onNeighborNotify(this, targetPos, pos, direction.getOpposite());
            }
        }
    }
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:13,代碼來源:WorldManager.java


注:本文中的com.flowpowered.math.vector.Vector3i.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。