Java Code Examples for org.bukkit.block.BlockState#getMaterialData()

The following examples show how to use org.bukkit.block.BlockState#getMaterialData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenewableDefinition.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean canRenew(BlockState original, BlockState current) {
  // Original block must be in the region and match the renewable filter
  if (!region.contains(original)) return false;
  BlockQuery originalQuery = new BlockQuery(original);
  if (!renewableBlocks.query(originalQuery).isAllowed()) return false;

  MaterialData originalMaterial = original.getMaterialData();
  MaterialData currentMaterial = current.getMaterialData();

  // If current world matches the original, block is already renewed
  if (originalMaterial.equals(currentMaterial)) return false;

  // If the original and current blocks are both shuffleable, block is already renewed
  if (shuffleableBlocks.query(originalQuery).isAllowed()
      && shuffleableBlocks.query(new BlockQuery(current)).isAllowed()) {
    return false;
  }

  // Otherwise, block is eligible to be renewed
  return true;
}
 
Example 2
Source File: Renewable.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
boolean isNew(BlockState currentState) {
  // If original block does not match renewable rule, block is new
  BlockVector pos = BlockVectors.position(currentState);
  if (!isOriginalRenewable(pos)) return true;

  // If original and current world are both shuffleable, block is new
  MaterialData currentMaterial = currentState.getMaterialData();
  if (isOriginalShuffleable(pos)
      && definition.shuffleableBlocks.query(new BlockQuery(currentState)).isAllowed())
    return true;

  // If current world matches original, block is new
  if (currentMaterial.equals(snapshot().getOriginalMaterial(pos))) return true;

  // Otherwise, block is not new (can be renewed)
  return false;
}
 
Example 3
Source File: Renewable.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
MaterialData sampleShuffledMaterial(BlockVector pos) {
  Random random = match.getRandom();
  int range = SHUFFLE_SAMPLE_RANGE;
  int diameter = range * 2 + 1;
  for (int i = 0; i < SHUFFLE_SAMPLE_ITERATIONS; i++) {
    BlockState block =
        snapshot()
            .getOriginalBlock(
                pos.getBlockX() + random.nextInt(diameter) - range,
                pos.getBlockY() + random.nextInt(diameter) - range,
                pos.getBlockZ() + random.nextInt(diameter) - range);
    if (definition.shuffleableBlocks.query(new BlockQuery(block)).isAllowed())
      return block.getMaterialData();
  }
  return null;
}
 
Example 4
Source File: RenewableDefinition.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean canRenew(BlockState original, BlockState current) {
    // Original block must be in the region and match the renewable filter
    if(!region.contains(original)) return false;
    BlockQuery originalQuery = new BlockQuery(original);
    if(!renewableBlocks.query(originalQuery).isAllowed()) return false;

    MaterialData originalMaterial = original.getMaterialData();
    MaterialData currentMaterial = current.getMaterialData();

    // If current material matches the original, block is already renewed
    if(originalMaterial.equals(currentMaterial)) return false;

    // If the original and current blocks are both shuffleable, block is already renewed
    if(shuffleableBlocks.query(originalQuery).isAllowed() && shuffleableBlocks.query(new BlockQuery(current)).isAllowed()) {
        return false;
    }

    // Otherwise, block is eligible to be renewed
    return true;
}
 
Example 5
Source File: BlockStates.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
static String format(BlockState state) {
  return "BlockState{pos=("
      + state.getX()
      + ", "
      + state.getY()
      + ", "
      + state.getZ()
      + ") world="
      + state.getMaterialData()
      + "}";
}
 
Example 6
Source File: Renewable.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
boolean isNew(BlockState currentState) {
    // If original block does not match renewable rule, block is new
    BlockVector pos = BlockUtils.position(currentState);
    if(!isOriginalRenewable(pos)) return true;

    // If original and current material are both shuffleable, block is new
    MaterialData currentMaterial = currentState.getMaterialData();
    if(isOriginalShuffleable(pos) && definition.shuffleableBlocks.query(new BlockQuery(currentState)).isAllowed()) return true;

    // If current material matches original, block is new
    if(currentMaterial.equals(snapshot().getOriginalMaterial(pos))) return true;

    // Otherwise, block is not new (can be renewed)
    return false;
}
 
Example 7
Source File: Renewable.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
MaterialData sampleShuffledMaterial(BlockVector pos) {
    Random random = match.getRandom();
    int range = SHUFFLE_SAMPLE_RANGE;
    int diameter = range * 2 + 1;
    for(int i = 0; i < SHUFFLE_SAMPLE_ITERATIONS; i++) {
        BlockState block = snapshot().getOriginalBlock(pos.getBlockX() + random.nextInt(diameter) - range,
                                                       pos.getBlockY() + random.nextInt(diameter) - range,
                                                       pos.getBlockZ() + random.nextInt(diameter) - range);
        if(definition.shuffleableBlocks.query(new BlockQuery(block)).isAllowed()) return block.getMaterialData();
    }
    return null;
}
 
Example 8
Source File: BlockInfo.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public BlockInfo(BlockState block, @Nullable ParticipantState owner) {
  this(block.getMaterialData(), owner);
}
 
Example 9
Source File: BlockInfo.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public BlockInfo(BlockState block, @Nullable ParticipantState owner) {
    this(block.getMaterialData(), owner);
}
 
Example 10
Source File: BlockStateUtils.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String format(BlockState state) {
    return "BlockState{pos=(" + state.getX() + ", " + state.getY() + ", " + state.getZ() +
           ") material=" + state.getMaterialData() + "}";
}