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

The following examples show how to use org.bukkit.block.BlockState#getTypeId() . 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: StructureGrowDelegate.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public int getTypeId(int x, int y, int z) {
    for (BlockState state : blocks) {
        if (state.getX() == x && state.getY() == y && state.getZ() == z) {
            return state.getTypeId();
        }
    }

    return world.getBlockTypeIdAt(x, y, z);
}
 
Example 2
Source File: StructureGrowDelegate.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public int getTypeId(int x, int y, int z) {
    for (BlockState state : blocks) {
        if (state.getX() == x && state.getY() == y && state.getZ() == z) {
            return state.getTypeId();
        }
    }

    return world.getBlockTypeIdAt(x, y, z);
}
 
Example 3
Source File: BlockDropsMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This is not an event handler. It is called explicitly by BlockTransformListener after all event
 * handlers have been called.
 */
@SuppressWarnings("deprecation")
public void doBlockDrops(final BlockTransformEvent event) {
  if (!causesDrops(event.getCause())) {
    return;
  }

  final BlockDrops drops = event.getDrops();
  if (drops != null) {
    event.setCancelled(true);
    final BlockState oldState = event.getOldState();
    final BlockState newState = event.getNewState();
    final Block block = event.getOldState().getBlock();
    final int newTypeId = newState.getTypeId();
    final byte newData = newState.getRawData();

    block.setTypeIdAndData(newTypeId, newData, true);

    if (event.getCause() instanceof EntityExplodeEvent) {
      EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause();
      final float yield = explodeEvent.getYield();

      if (drops.fallChance != null
          && oldState.getType().isBlock()
          && oldState.getType() != Material.AIR
          && match.getRandom().nextFloat() < drops.fallChance) {

        FallingBlock fallingBlock =
            match
                .getWorld()
                .spawnFallingBlock(
                    block.getLocation(),
                    event.getOldState().getType(),
                    event.getOldState().getRawData());
        fallingBlock.setDropItem(false);

        if (drops.landChance != null && match.getRandom().nextFloat() >= drops.landChance) {
          this.fallingBlocksThatWillNotLand.add(fallingBlock);
        }

        Vector v = fallingBlock.getLocation().subtract(explodeEvent.getLocation()).toVector();
        double distance = v.length();
        v.normalize().multiply(BASE_FALL_SPEED * drops.fallSpeed / Math.max(1d, distance));

        // A very simple deflection model. Check for a solid
        // neighbor block and "bounce" the velocity off of it.
        Block west = block.getRelative(BlockFace.WEST);
        Block east = block.getRelative(BlockFace.EAST);
        Block down = block.getRelative(BlockFace.DOWN);
        Block up = block.getRelative(BlockFace.UP);
        Block north = block.getRelative(BlockFace.NORTH);
        Block south = block.getRelative(BlockFace.SOUTH);

        if ((v.getX() < 0 && west != null && west.getType().isSolid())
            || v.getX() > 0 && east != null && east.getType().isSolid()) {
          v.setX(-v.getX());
        }

        if ((v.getY() < 0 && down != null && down.getType().isSolid())
            || v.getY() > 0 && up != null && up.getType().isSolid()) {
          v.setY(-v.getY());
        }

        if ((v.getZ() < 0 && north != null && north.getType().isSolid())
            || v.getZ() > 0 && south != null && south.getType().isSolid()) {
          v.setZ(-v.getZ());
        }

        fallingBlock.setVelocity(v);
      }

      // Defer item drops so the explosion doesn't destroy them
      match
          .getExecutor(MatchScope.RUNNING)
          .execute(() -> dropItems(drops, newState.getLocation(), yield));
    } else {
      MatchPlayer player = ParticipantBlockTransformEvent.getParticipant(event);
      if (player == null
          || player.getBukkit().getGameMode()
              != GameMode.CREATIVE) { // Don't drop items in creative mode
        dropItems(drops, newState.getLocation(), 1d);
        dropExperience(drops, newState.getLocation());
      }
    }
  }
}
 
Example 4
Source File: BlockDropsMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This is not an event handler. It is called explicitly by BlockTransformListener
 * after all event handlers have been called.
 */
@SuppressWarnings("deprecation")
public void doBlockDrops(final BlockTransformEvent event) {
    if(!causesDrops(event.getCause())) {
        return;
    }

    final BlockDrops drops = event.getDrops();
    if(drops != null) {
        event.setCancelled(true);
        final BlockState oldState = event.getOldState();
        final BlockState newState = event.getNewState();
        final Block block = event.getOldState().getBlock();
        final int newTypeId = newState.getTypeId();
        final byte newData = newState.getRawData();

        block.setTypeIdAndData(newTypeId, newData, true);

        boolean explosion = false;
        MatchPlayer player = ParticipantBlockTransformEvent.getParticipant(event);

        if(event.getCause() instanceof EntityExplodeEvent) {
            EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause();
            explosion = true;

            if(drops.fallChance != null &&
               oldState.getType().isBlock() &&
               oldState.getType() != Material.AIR &&
               this.getMatch().getRandom().nextFloat() < drops.fallChance) {

                FallingBlock fallingBlock = event.getOldState().spawnFallingBlock();
                fallingBlock.setDropItem(false);

                if(drops.landChance != null && this.getMatch().getRandom().nextFloat() >= drops.landChance) {
                    this.fallingBlocksThatWillNotLand.add(fallingBlock);
                }

                Vector v = fallingBlock.getLocation().subtract(explodeEvent.getLocation()).toVector();
                double distance = v.length();
                v.normalize().multiply(BASE_FALL_SPEED * drops.fallSpeed / Math.max(1d, distance));

                // A very simple deflection model. Check for a solid
                // neighbor block and "bounce" the velocity off of it.
                Block west = block.getRelative(BlockFace.WEST);
                Block east = block.getRelative(BlockFace.EAST);
                Block down = block.getRelative(BlockFace.DOWN);
                Block up = block.getRelative(BlockFace.UP);
                Block north = block.getRelative(BlockFace.NORTH);
                Block south = block.getRelative(BlockFace.SOUTH);

                if((v.getX() < 0 && west != null && Materials.isColliding(west.getType())) ||
                    v.getX() > 0 && east != null && Materials.isColliding(east.getType())) {
                    v.setX(-v.getX());
                }

                if((v.getY() < 0 && down != null && Materials.isColliding(down.getType())) ||
                    v.getY() > 0 && up != null && Materials.isColliding(up.getType())) {
                    v.setY(-v.getY());
                }

                if((v.getZ() < 0 && north != null && Materials.isColliding(north.getType())) ||
                    v.getZ() > 0 && south != null && Materials.isColliding(south.getType())) {
                    v.setZ(-v.getZ());
                }

                fallingBlock.setVelocity(v);
            }
        }

        dropObjects(drops, player, newState.getLocation(), 1d, explosion);

    }
}
 
Example 5
Source File: ItemManager.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static int getId(BlockState newState) {
	return newState.getTypeId();
}