本文整理匯總了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();
}
示例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);
}
示例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)));
}
示例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();
}
}
}
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}
}
}
}