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

The following examples show how to use org.bukkit.block.BlockState#setRawData() . 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: XBlock.java    From XSeries with MIT License 6 votes vote down vote up
/**
 * Sets the type of any block that can be colored.
 *
 * @param block the block to color.
 * @param color the color to use.
 * @return true if the block can be colored, otherwise false.
 */
public static boolean setColor(Block block, DyeColor color) {
    if (ISFLAT) {
        String type = block.getType().name();
        int index = type.indexOf('_');
        if (index == -1) return false;

        String realType = type.substring(index);
        Material material = Material.getMaterial(color.name() + '_' + realType);
        if (material == null) return false;
        block.setType(material);
        return true;
    }

    BlockState state = block.getState();
    state.setRawData(color.getWoolData());
    state.update(true);
    return false;
}
 
Example 2
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the type of any block that can be colored.
 *
 * @param block the block to color.
 * @param color the color to use.
 * @return true if the block can be colored, otherwise false.
 */
public static boolean setColor(Block block, DyeColor color) {
    if (XMaterial.ISFLAT) {
        String type = block.getType().name();
        if (type.endsWith("WOOL")) block.setType(Material.getMaterial(color.name() + "_WOOL"));
        else if (type.endsWith("BED")) block.setType(Material.getMaterial(color.name() + "_BED"));
        else if (type.endsWith("STAINED_GLASS"))
            block.setType(Material.getMaterial(color.name() + "_STAINED_GLASS"));
        else if (type.endsWith("STAINED_GLASS_PANE"))
            block.setType(Material.getMaterial(color.name() + "_STAINED_GLASS_PANE"));
        else if (type.endsWith("TERRACOTTA")) block.setType(Material.getMaterial(color.name() + "_TERRACOTTA"));
        else if (type.endsWith("GLAZED_TERRACOTTA"))
            block.setType(Material.getMaterial(color.name() + "_GLAZED_TERRACOTTA"));
        else if (type.endsWith("BANNER")) block.setType(Material.getMaterial(color.name() + "_BANNER"));
        else if (type.endsWith("WALL_BANNER")) block.setType(Material.getMaterial(color.name() + "_WALL_BANNER"));
        else if (type.endsWith("CARPET")) block.setType(Material.getMaterial(color.name() + "_CARPET"));
        else if (type.endsWith("SHULKER_BOX")) block.setType(Material.getMaterial(color.name() + "_SHULKERBOX"));
        else if (type.endsWith("CONCRETE")) block.setType(Material.getMaterial(color.name() + "_CONCRETE"));
        else if (type.endsWith("CONCRETE_POWDER"))
            block.setType(Material.getMaterial(color.name() + "_CONCRETE_POWDER"));
        else return false;
        return true;
    }

    BlockState state = block.getState();
    state.setRawData(color.getWoolData());
    state.update(true);
    return false;
}
 
Example 3
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
public static void setEnderPearlOnFrame(Block endPortalFrame, boolean eye) {
    BlockState state = endPortalFrame.getState();
    if (ISFLAT) {
        BlockData data = state.getBlockData();
        EndPortalFrame frame = (EndPortalFrame) data;
        frame.setEye(eye);
        state.setBlockData(frame);
    } else {
        state.setRawData((byte) (eye ? 4 : 0));
    }
    state.update(true);
}
 
Example 4
Source File: BlockImage.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public BlockState getState(BlockVector pos) {
  int offset = this.offset(pos);
  BlockState state = pos.toLocation(this.world).getBlock().getState();
  state.setTypeId(this.blockIds[offset]);
  state.setRawData(this.blockData[offset]);
  return state;
}
 
Example 5
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventWrapper
public void onBlockFromTo(BlockFromToEvent event) {
  if (event.getToBlock().getType() != event.getBlock().getType()) {
    BlockState oldState = event.getToBlock().getState();
    BlockState newState = event.getToBlock().getState();
    newState.setType(event.getBlock().getType());
    newState.setRawData(event.getBlock().getData());

    // Check for lava ownership
    this.callEvent(event, oldState, newState, Trackers.getOwner(event.getBlock()));
  }
}
 
Example 6
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static boolean handleBlockSpreadEvent(Block block, Block source, net.minecraft.block.Block type, int data) {
    BlockState state = block.getState();
    state.setTypeId(net.minecraft.block.Block.getIdFromBlock(type));
    state.setRawData((byte) data);

    BlockSpreadEvent event = new BlockSpreadEvent(block, source, state);
    Bukkit.getPluginManager().callEvent(event);

    if (!event.isCancelled()) {
        state.update(true);
    }
    return !event.isCancelled();
}
 
Example 7
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static boolean handleBlockFormEvent(World world, BlockPos pos, IBlockState block, @Nullable Entity entity) {
    BlockState blockState = world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()).getState();
    blockState.setType(CraftMagicNumbers.getMaterial(block.getBlock()));
    blockState.setRawData((byte) block.getBlock().getMetaFromState(block));

    BlockFormEvent event = (entity == null) ? new BlockFormEvent(blockState.getBlock(), blockState) : new EntityBlockFormEvent(entity.getBukkitEntity(), blockState.getBlock(), blockState);
    world.getServer().getPluginManager().callEvent(event);

    if (!event.isCancelled()) {
        blockState.update(true);
    }

    return !event.isCancelled();
}
 
Example 8
Source File: BlockImage.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public BlockState getState(BlockVector pos) {
    int offset = this.offset(pos);
    BlockState state = pos.toLocation(this.world).getBlock().getState();
    state.setTypeId(this.blockIds[offset]);
    state.setRawData(this.blockData[offset]);
    return state;
}
 
Example 9
Source File: BlockTransformListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventWrapper
public void onBlockFromTo(BlockFromToEvent event) {
    if(event.getToBlock().getType() != event.getBlock().getType()) {
        BlockState oldState = event.getToBlock().getState();
        BlockState newState = event.getToBlock().getState();
        newState.setType(event.getBlock().getType());
        newState.setRawData(event.getBlock().getData());

        // Check for lava ownership
        this.callEvent(event, oldState, newState, blockResolver.getOwner(event.getBlock()));
    }
}
 
Example 10
Source File: BlockStateUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static BlockState cloneWithMaterial(Block block, Material material, byte data) {
    BlockState state = block.getState();
    state.setType(material);
    state.setRawData(data);
    return state;
}
 
Example 11
Source File: BlockMaterialMap.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public BlockState next() {
    Block block = BlockUtils.blockAt(world, iter.key());
    if(block == null) return null;
    BlockState state = block.getState();
    state.setTypeId(decodeTypeId(iter.value()));
    state.setRawData(decodeMetadata(iter.value()));
    return state;
}
 
Example 12
Source File: CraftEventFactory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public static void handleBlockSpreadEvent(Block block, Block source, net.minecraft.block.Block type, int data) {
    BlockState state = block.getState();
    state.setTypeId(net.minecraft.block.Block.getIdFromBlock(type));
    state.setRawData((byte) data);

    BlockSpreadEvent event = new BlockSpreadEvent(block, source, state);
    Bukkit.getPluginManager().callEvent(event);

    if (!event.isCancelled()) {
        state.update(true);
    }
}
 
Example 13
Source File: BlockStates.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
static BlockState toAir(Block block) {
  BlockState newState = block.getState(); // this creates a new copy of the state
  newState.setType(Material.AIR);
  newState.setRawData((byte) 0);
  return newState;
}
 
Example 14
Source File: BlockStates.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
static BlockState cloneWithMaterial(Block block, Material material, byte data) {
  BlockState state = block.getState();
  state.setType(material);
  state.setRawData(data);
  return state;
}
 
Example 15
Source File: BlockStateListPopulator.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public void setTypeAndData(int x, int y, int z, Block block, int data, int light) {
    BlockState state = world.getBlockAt(x, y, z).getState();
    state.setTypeId(Block.getIdFromBlock(block));
    state.setRawData((byte) data);
    list.add(state);
}
 
Example 16
Source File: BlockStateUtils.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static BlockState toAir(Block block) {
    BlockState newState = block.getState(); // this creates a new copy of the state
    newState.setType(Material.AIR);
    newState.setRawData((byte) 0);
    return newState;
}