org.bukkit.block.Block.setData()方法的使用及代码示例

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

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

Block.setData介绍

[英]Sets the metadata for this block
[中]设置此块的元数据

代码示例

代码示例来源:origin: GlowstoneMC/Glowstone

/**
   * Generates up to 64 flowers around the given point.
   */
  @Override
  public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    boolean succeeded = false;
    for (int i = 0; i < 64; i++) {
      int x = sourceX + random.nextInt(8) - random.nextInt(8);
      int z = sourceZ + random.nextInt(8) - random.nextInt(8);
      int y = sourceY + random.nextInt(4) - random.nextInt(4);

      Block block = world.getBlockAt(x, y, z);
      if (y < 255 && block.getType() == Material.AIR
          && block.getRelative(BlockFace.DOWN).getType() == Material.GRASS) {
        block.setType(type);
        block.setData((byte) data);
        succeeded = true;
      }
    }
    return succeeded;
  }
}

代码示例来源:origin: bergerkiller/BKCommonLib

@Override
public void setData(final byte data, boolean applyPhysics) {
  base.setData(data, applyPhysics);
}

代码示例来源:origin: bergerkiller/BKCommonLib

@Override
public void setData(final byte data) {
  base.setData(data);
}

代码示例来源:origin: TotalFreedom/TotalFreedomMod

public static void setData_Block(Block block, byte data)
{
  block.setData(data);
}

代码示例来源:origin: bergerkiller/BKCommonLib

/**
 * Sets the Material Data for a Block
 * 
 * @param block to set it for
 * @param materialData to set to
 * @param doPhysics - True to perform physics, False for 'silent'
 */
@SuppressWarnings("deprecation")
public static void setData(org.bukkit.block.Block block, MaterialData materialData, boolean doPhysics) {
  block.setData(materialData.getData(), doPhysics);
}

代码示例来源:origin: bergerkiller/BKCommonLib

/**
 * Sets the Material Data for a Block
 * 
 * @param block to set it for
 * @param materialData to set to
 */
@SuppressWarnings("deprecation")
public static void setData(org.bukkit.block.Block block, MaterialData materialData) {
  block.setData(materialData.getData());
}

代码示例来源:origin: ProjectKorra/ProjectKorra

public void setType(final Material material, final byte data) {
  this.newdata = data;
  this.block.setType(material);
  this.block.setData(data);
}

代码示例来源:origin: stackoverflow.com

public AbstractBlock readBlock(int blockNum, AbstractDBFile f)
  throws IOException {

  DBFile dbf = (DBFile) f;
  byte[] data2 = new byte[4096];
  RandomAccessFile file = new RandomAccessFile(dbf.fileName, "r");
  file.seek(4096+blockNum*4096);
  Block b = new Block();

  for (int i = 0; i < 4096; i++){
    try{  
      data2[i] = file.readByte();
    }catch(EOFException ex){
      System.out.println("End of file reached!");

      //break the loop
      break;
     }
  }
  file.close();
  b.setData(data2);
  return b;
}

代码示例来源:origin: ProjectKorra/ProjectKorra

public static void revertSand(final Block block) {
  final MaterialData materialdata = SAND_ID_ENTITIES.get(block);
  SAND_ID_ENTITIES.remove(block);
  SAND_BLOCKS.remove(block);
  if (block.getType() == Material.SAND) {
    block.setType(materialdata.getItemType());
    block.setData(materialdata.getData());
  }
}

代码示例来源:origin: ProjectKorra/ProjectKorra

public static void removeBlock(final Block block) {
  if (IGNITED_BLOCKS.containsKey(block)) {
    IGNITED_BLOCKS.remove(block);
  }
  if (IGNITED_TIMES.containsKey(block)) {
    IGNITED_TIMES.remove(block);
  }
  if (REPLACED_BLOCKS.containsKey(block.getLocation())) {
    block.setType(REPLACED_BLOCKS.get(block.getLocation()).getItemType());
    block.setData(REPLACED_BLOCKS.get(block.getLocation()).getData());
    REPLACED_BLOCKS.remove(block.getLocation());
  }
}

代码示例来源:origin: ProjectKorra/ProjectKorra

@Override
public void remove() {
  super.remove();
  for (final Block b : this.waterOrigins.keySet()) {
    if (b.getType() == Material.AIR) {
      b.setType(this.waterOrigins.get(b).getItemType());
      b.setData(this.waterOrigins.get(b).getData());
    }
  }
}

代码示例来源:origin: ProjectKorra/ProjectKorra

public static void revertBlock(final Block block, final Material defaulttype) {
  if (instances.containsKey(block)) {
    instances.get(block).revertBlock();
  } else {
    if ((defaulttype == Material.LAVA || defaulttype == Material.STATIONARY_LAVA) && GeneralMethods.isAdjacentToThreeOrMoreSources(block)) {
      block.setType(Material.LAVA);
      block.setData((byte) 0x0);
    } else if ((defaulttype == Material.WATER || defaulttype == Material.STATIONARY_WATER) && GeneralMethods.isAdjacentToThreeOrMoreSources(block)) {
      block.setType(Material.WATER);
      block.setData((byte) 0x0);
    } else {
      block.setType(defaulttype);
    }
  }
}

代码示例来源:origin: ProjectKorra/ProjectKorra

public static void removeBlock(final Block block) {
  if (isAdjacentToThreeOrMoreSources(block)) {
    block.setType(Material.WATER);
    block.setData((byte) 0x0);
  } else {
    block.setType(Material.AIR);
  }
}

代码示例来源:origin: Co0sh/BetonQuest

@SuppressWarnings("deprecation")
@Override
public void run(String playerID) throws QuestRuntimeException {
  Location location = loc.getLocation(playerID);
  location.getBlock().setType(block);
  location.getBlock().setData(data);
}

代码示例来源:origin: stackoverflow.com

@EventHandler
public void onInteractEvent(PlayerInteractEvent e) {
Block interacted = e.getClickedBlock();
//Check if this is the block you want

Block block= interacted.getRelative(BlockFace.UP, 1);    //Can be changed to any block face, and any distance

switch(block.getType()) {
case LEVER:
case REDSTONE:
case DISPENSER:
case POWERED_RAILS:
case whatever other blocks can be powered:
{
   block.setData(block.getData() | 0x8); // sets the 0x8 bit to the data, making it powered
} }

代码示例来源:origin: ProjectKorra/ProjectKorra

@Override
public void remove() {
  super.remove();
  if (this.block.getType() == Material.AIR) {
    this.block.setType(this.type);
    this.block.setData(this.data);
    if (this.type == Material.DOUBLE_PLANT) {
      this.block.getRelative(BlockFace.UP).setType(Material.DOUBLE_PLANT);
      this.block.getRelative(BlockFace.UP).setData((byte) 10);
    }
  } else {
    GeneralMethods.dropItems(this.block, GeneralMethods.getDrops(this.block, this.type, this.data, null));
  }
}

代码示例来源:origin: ProjectKorra/ProjectKorra

@Override
public void remove() {
  super.remove();
  if (this.destination != null && this.sourceBlock != null) {
    this.sourceBlock.setType(Material.AIR);
  } else if (this.sourceBlock != null) {
    if (this.sourceBlock.getType() == Material.SAND) {
      if (this.sourceBlock.getData() == (byte) 0x1) {
        this.sourceBlock.setType(this.sourceType);
        this.sourceBlock.setData((byte) 0x1);
      } else {
        this.sourceBlock.setType(this.sourceType);
      }
    } else {
      this.sourceBlock.setType(this.sourceType);
      this.sourceBlock.setData(this.sourceData);
    }
  }
}

代码示例来源:origin: ProjectKorra/ProjectKorra

/**
 * Gets a {@code Collection<ItemStack>} of item drops from a single block.
 *
 * @param block The single block
 * @param type The Material type to change the block into
 * @param data The block data to change the block into
 * @param breakitem Unused
 * @return The item drops fromt the specified block
 */
public static Collection<ItemStack> getDrops(final Block block, final Material type, final byte data, final ItemStack breakitem) {
  final BlockState tempstate = block.getState();
  block.setType(type);
  block.setData(data);
  final Collection<ItemStack> item = block.getDrops();
  tempstate.update(true);
  return item;
}

代码示例来源:origin: ProjectKorra/ProjectKorra

@Override
  public void run() {
    button.setPowered(!button.isPowered());
    btBlock.setData(button.getData());
    final Block supportBlock = btBlock.getRelative(button.getAttachedFace());
    if (supportBlock != null && supportBlock.getType() != Material.AIR) {
      final BlockState initialSupportState = supportBlock.getState();
      final BlockState supportState = supportBlock.getState();
      supportState.setType(Material.AIR);
      supportState.update(true, false);
      initialSupportState.update(true);
    }
  }
}.runTaskLater(ProjectKorra.plugin, 10);

代码示例来源:origin: ProjectKorra/ProjectKorra

@Override
  public void run() {
    button.setPowered(!button.isPowered());
    btBlock.setData(button.getData());
    final Block supportBlock = btBlock.getRelative(button.getAttachedFace());
    if (supportBlock != null && supportBlock.getType() != Material.AIR) {
      final BlockState initialSupportState = supportBlock.getState();
      final BlockState supportState = supportBlock.getState();
      supportState.setType(Material.AIR);
      supportState.update(true, false);
      initialSupportState.update(true);
    }
  }
}.runTaskLater(ProjectKorra.plugin, 15);

相关文章