net.minecraft.util.math.BlockPos.add()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中net.minecraft.util.math.BlockPos.add()方法的一些代码示例,展示了BlockPos.add()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BlockPos.add()方法的具体详情如下:
包路径:net.minecraft.util.math.BlockPos
类名称:BlockPos
方法名:add

BlockPos.add介绍

暂无

代码示例

代码示例来源:origin: Vazkii/Botania

private AxisAlignedBB getPortalAABB() {
  AxisAlignedBB aabb = new AxisAlignedBB(pos.add(-1, 1, 0), pos.add(2, 4, 1));
  if(world.getBlockState(getPos()).getValue(BotaniaStateProps.ALFPORTAL_STATE) == AlfPortalState.ON_X)
    aabb = new AxisAlignedBB(pos.add(0, 1, -1), pos.add(1, 4, 2));
  return aabb;
}

代码示例来源:origin: Vazkii/Botania

public static void removeBlocksInIteration(EntityPlayer player, ItemStack stack, World world, BlockPos centerPos,
                      Vec3i startDelta, Vec3i endDelta, Predicate<IBlockState> filter,
                      boolean dispose) {
  for (BlockPos iterPos : BlockPos.getAllInBox(centerPos.add(startDelta), centerPos.add(endDelta))) {
    if (iterPos.equals(centerPos)) // skip original block space to avoid crash, vanilla code in the tool class will handle it
      continue;
    removeBlockWithDrops(player, stack, world, iterPos, filter, dispose);
  }
}

代码示例来源:origin: Vazkii/Botania

private List<BlockPos> getCoordsToPut(BlockPos pos) {
  List<BlockPos> possibleCoords = new ArrayList<>();
  int range = 4;
  int rangeY = 4;
  for (BlockPos bPos : BlockPos.getAllInBox(pos.add(-range, -rangeY, -range), pos.add(range, rangeY, range))) {
    IBlockState state = world.getBlockState(bPos);
    Block block = state.getBlock();
    if(block.isReplaceableOreGen(state, world, bPos, BlockStateMatcher.forBlock(Blocks.STONE)))
      possibleCoords.add(bPos);
  }
  Collections.shuffle(possibleCoords, rand);
  return possibleCoords.stream().limit(64).collect(Collectors.toList());
}

代码示例来源:origin: Vazkii/Botania

public static boolean canEnchanterExist(World world, BlockPos pos, EnumFacing.Axis axis) {
  for(BlockPos obsidian : OBSIDIAN_LOCATIONS)
    if(world.getBlockState(pos.add(obsidian)).getBlock() != Blocks.OBSIDIAN)
      return false;
  for(BlockPos pylon : PYLON_LOCATIONS.get(axis))
    if(world.getBlockState(pos.add(pylon)).getBlock() != ModBlocks.pylon || !BotaniaAPI.internalHandler.isBotaniaFlower(world, pos.add(pylon).down()))
      return false;
  for(BlockPos flower : FLOWER_LOCATIONS)
    if(!BotaniaAPI.internalHandler.isBotaniaFlower(world, pos.add(flower)))
      return false;
  return true;
}

代码示例来源:origin: Vazkii/Botania

int[][] getCellTable() {
  int diam = RANGE * 2 + 1;
  int[][] table = new int[diam][diam];
  BlockPos pos = supertile.getPos();
  for(int i = 0; i < diam; i++)
    for(int j = 0; j < diam; j++) {
      BlockPos pos_ = pos.add(-RANGE + i, 0, -RANGE + j);
      table[i][j] = getCellGeneration(pos_);
    }
  return table;
}

代码示例来源:origin: Vazkii/Botania

List<EntityItem> getItems() {
  return world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos, pos.add(1, 1, 1)));
}

代码示例来源:origin: Vazkii/Botania

@Override
public void update() {
  if (world.isRemote)
    return;
  int range = 6;
  int entityCount = world.getEntitiesWithinAABB(EntityAnimal.class, new AxisAlignedBB(pos.add(-range, -range, -range), pos.add(range + 1, range + 1, range + 1))).size();
  if(entityCount != entities) {
    entities = entityCount;
    world.updateComparatorOutputLevel(pos, world.getBlockState(pos).getBlock());
  }
}

代码示例来源:origin: Vazkii/Botania

/**
 * Gets the spark attached to the block in the coords passed in. Note that the coords passed
 * in are for the block that the spark will be on, not the coords of the spark itself.
 */
public static ICorporeaSpark getSparkForBlock(World world, BlockPos pos) {
  List<Entity> sparks = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos.up(), pos.add(1, 2, 1)), Predicates.instanceOf(ICorporeaSpark.class));
  return sparks.isEmpty() ? null : (ICorporeaSpark) sparks.get(0);
}

代码示例来源:origin: Vazkii/Botania

private BlockPos getCoordsToPut() {
  List<BlockPos> possibleCoords = new ArrayList<>();
  for(BlockPos pos : BlockPos.getAllInBox(getPos().add(-RANGE, -RANGE_Y, -RANGE), getPos().add(RANGE, RANGE_Y, RANGE))) {
    IBlockState state = supertile.getWorld().getBlockState(pos);
    if(state.getBlock().isReplaceableOreGen(state, supertile.getWorld(), pos, getReplaceMatcher()))
      possibleCoords.add(pos);
  }
  if(possibleCoords.isEmpty())
    return null;
  return possibleCoords.get(supertile.getWorld().rand.nextInt(possibleCoords.size()));
}

代码示例来源:origin: Vazkii/Botania

public List<ItemStack> getFilter() {
  List<ItemStack> filter = new ArrayList<>();
  for(EnumFacing dir : EnumFacing.HORIZONTALS) {
    List<EntityItemFrame> frames = world.getEntitiesWithinAABB(EntityItemFrame.class, new AxisAlignedBB(pos.offset(dir), pos.offset(dir).add(1, 1, 1)));
    for(EntityItemFrame frame : frames) {
      EnumFacing orientation = frame.facingDirection;
      if(orientation == dir)
        filter.add(frame.getDisplayedItem());
    }
  }
  return filter;
}

代码示例来源:origin: Vazkii/Botania

@Override
public ISparkEntity getAttachedSpark() {
  List sparks = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos.up(), pos.up().add(1, 1, 1)), Predicates.instanceOf(ISparkEntity.class));
  if(sparks.size() == 1) {
    Entity e = (Entity) sparks.get(0);
    return (ISparkEntity) e;
  }
  return null;
}

代码示例来源:origin: Vazkii/Botania

@Override
public ISparkEntity getAttachedSpark() {
  List<Entity> sparks = world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos.up(), pos.up().add(1, 1, 1)), Predicates.instanceOf(ISparkEntity.class));
  if(sparks.size() == 1) {
    Entity e = sparks.get(0);
    return (ISparkEntity) e;
  }
  return null;
}

代码示例来源:origin: Vazkii/Botania

private BlockPos getCoordsToPut() {
  List<BlockPos> possibleCoords = new ArrayList<>();
  int range = getRange();
  int rangeY = getRangeY();
  BlockStateMatcher matcher = BlockStateMatcher.forBlock(Blocks.STONE);
  for(BlockPos pos : BlockPos.getAllInBox(getPos().add(-range, -rangeY, -range), getPos().add(range, rangeY, range))) {
    IBlockState state = supertile.getWorld().getBlockState(pos);
    if(state.getBlock().isReplaceableOreGen(state, supertile.getWorld(), pos, matcher))
      possibleCoords.add(pos);
  }
  if(possibleCoords.isEmpty())
    return null;
  return possibleCoords.get(supertile.getWorld().rand.nextInt(possibleCoords.size()));
}

代码示例来源:origin: Vazkii/Botania

/**
   * Returns the multiblock component for the coordinates, adjusted based on the anchor
   */
  private MultiblockComponent getComponent(BlockPos pos) {
    return multiblock.getComponentForLocation(pos.add(new BlockPos(-anchorPos.getX(), -anchorPos.getY(), -anchorPos.getZ())));
  }
}

代码示例来源:origin: Vazkii/Botania

public static void renderMultiblockOnPage(Multiblock mb) {
  GlStateManager.translate(-0.5, -0.5, -0.5);
  blockAccess.update(null, mb, mb.offPos);
  for(MultiblockComponent comp : mb.getComponents()) {
    BlockPos pos = comp.getRelativePosition();
    doRenderComponent(mb, comp, pos.add(mb.offPos));
  }
}

代码示例来源:origin: Vazkii/Botania

@Override
public void update() {
  boolean state = world.getBlockState(getPos()).getValue(BotaniaStateProps.POWERED);
  boolean expectedState = world.getEntitiesWithinAABB(EntityThrowable.class, new AxisAlignedBB(pos, pos.add(1, 1, 1)), Predicates.instanceOf(IManaBurst.class)).size() != 0;
  if(state != expectedState && !world.isRemote)
    world.setBlockState(getPos(), world.getBlockState(getPos()).withProperty(BotaniaStateProps.POWERED, expectedState), 1 | 2);
  if(expectedState)
    for(int i = 0; i < 4; i++)
      Botania.proxy.sparkleFX(pos.getX() + Math.random(), pos.getY() + Math.random(), pos.getZ() + Math.random(), 1F, 0.2F, 0.2F, 0.7F + 0.5F * (float) Math.random(), 5);
}

代码示例来源:origin: Vazkii/Botania

private boolean checkPosition(BlockPos pos, IBlockState state, boolean onlyCheckBlock) {
  BlockPos pos_ = getPos().add(pos);
  IBlockState stateat = world.getBlockState(pos_);
  Block blockat = stateat.getBlock();
  if(state.getBlock() == Blocks.AIR ? blockat.isAir(stateat, world, pos_) : blockat == state.getBlock())
    return onlyCheckBlock || stateat == state;
  return false;
}

代码示例来源:origin: Vazkii/Botania

@Override
public void onUpdate() {
  super.onUpdate();
  if(supertile.getWorld().isRemote || redstoneSignal > 0)
    return;
  final int cost = 20;
  List<EntityLivingBase> entities = supertile.getWorld().getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(supertile.getPos().add(-RANGE, -RANGE, -RANGE), supertile.getPos().add(RANGE + 1, RANGE + 1, RANGE + 1)));
  for(EntityLivingBase entity : entities) {
    if(!(entity instanceof EntityPlayer) && entity.getActivePotionEffect(MobEffects.POISON) == null && mana >= cost && !entity.world.isRemote && entity.getCreatureAttribute() != EnumCreatureAttribute.UNDEAD) {
      entity.addPotionEffect(new PotionEffect(MobEffects.POISON, 60, 0));
      mana -= cost;
    }
  }
}

代码示例来源:origin: Vazkii/Botania

@Override
public boolean matches(World world, BlockPos pos) {
  return world.getBlockState(pos).getBlock().isBeaconBase(world, pos, pos.add(new BlockPos(-relPos.getX(), -relPos.getY(), -relPos.getZ())));
}

代码示例来源:origin: Vazkii/Botania

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
  if(!world.isRemote && state.getBlock() == this && world.getLight(pos.up()) >= 9) {
    AltGrassVariant variant = state.getValue(BotaniaStateProps.ALTGRASS_VARIANT);
    for(int l = 0; l < 4; ++l) {
      BlockPos pos1 = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
      world.getBlockState(pos1.up()).getBlock();
      if(world.getBlockState(pos1).getBlock() == Blocks.DIRT && world.getBlockState(pos1).getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && world.getLight(pos1.up()) >= 4 && world.getBlockLightOpacity(pos1.up()) <= 2)
        world.setBlockState(pos1, getDefaultState().withProperty(BotaniaStateProps.ALTGRASS_VARIANT, variant), 1 | 2);
    }
  }
}

相关文章