Java Code Examples for org.bukkit.block.BlockState.setData()

The following are Jave code examples for showing how to use setData() of the org.bukkit.block.BlockState class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Uranium   File: StructureGrowDelegate.java   Source Code and License Vote up 5 votes
public boolean setRawTypeIdAndData(int x, int y, int z, int type, int data) {
    BlockState state = world.getBlockAt(x, y, z).getState();
    state.setTypeId(type);
    state.setData(new MaterialData(type, (byte) data));
    blocks.add(state);
    return true;
}
 
Example 2
Project: ProjectAres   File: BlockDropsMatchModule.java   Source Code and License Vote up 5 votes
private void replaceBlock(BlockDrops drops, Block block, MatchPlayer player) {
    if(drops.replacement != null) {
        EntityChangeBlockEvent event = new EntityChangeBlockEvent(player.getBukkit(), block, drops.replacement);
        getMatch().callEvent(event);

        if(!event.isCancelled()) {
            BlockState state = block.getState();
            state.setType(drops.replacement.getItemType());
            state.setData(drops.replacement);
            state.update(true, true);
        }
    }
}
 
Example 3
Project: ProjectAres   File: BlockTransformEvent.java   Source Code and License Vote up 5 votes
public BlockState getNewState() {
    if(this.drops == null || this.drops.replacement == null) {
        return this.newState;
    } else {
        BlockState state = this.newState.getBlock().getState();
        state.setType(this.drops.replacement.getItemType());
        state.setData(this.drops.replacement);
        return state;
    }
}
 
Example 4
Project: ProjectAres   File: BlockTransformListener.java   Source Code and License Vote up 5 votes
@EventWrapper
public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
    Map<Block, BlockState> newStates = new HashMap<>();

    // Add the arm of the piston, which will extend into the adjacent block.
    PistonExtensionMaterial pistonExtension = new PistonExtensionMaterial(Material.PISTON_EXTENSION);
    pistonExtension.setFacingDirection(event.getDirection());
    BlockState pistonExtensionState = event.getBlock().getRelative(event.getDirection()).getState();
    pistonExtensionState.setType(pistonExtension.getItemType());
    pistonExtensionState.setData(pistonExtension);
    newStates.put(event.getBlock(), pistonExtensionState);

    this.onPistonMove(event, event.getBlocks(), newStates);
}
 
Example 5
Project: MT_Core   File: GeneratorListener.java   Source Code and License Vote up 5 votes
@EventHandler
public void onLeverOrButton(PlayerInteractEvent event) {
	Block clickedBlock = event.getClickedBlock();
	Player player = event.getPlayer();

	if (clickedBlock == null)
		return;

	String chunk = clickedBlock.getLocation().getChunk().getX() + ";"
			+ clickedBlock.getLocation().getChunk().getZ();
	if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
		return;
	if (!powerable.containsKey(clickedBlock.getWorld().getName()))
		return;
	if (powerable.get(clickedBlock.getWorld().getName()).getList(chunk).contains(clickedBlock.getLocation()))
		return;

	// We cancel; send smoke particles for button, and we just turn off the
	// lever (if it was, for some reason, on).
	if (clickedBlock.getType() == Material.STONE_BUTTON || clickedBlock.getType() == Material.WOOD_BUTTON) {

		clickedBlock.getWorld().spawnParticle(Particle.SMOKE_NORMAL, clickedBlock.getLocation().add(0.5, 1, 0.5), 7,
				0, 0.2, 0, 0.03);
		player.sendMessage(MortuusTerraCore.NOTI_PREFIX + ChatColor.RED + " There is no generator in range!");

	} else if (clickedBlock.getType() == Material.LEVER) {
		BlockState state = clickedBlock.getState();
		Lever lever = (Lever) state.getData();

		lever.setPowered(false);
		state.setData(lever);
		state.update();
		clickedBlock.getWorld().spawnParticle(Particle.SMOKE_NORMAL, clickedBlock.getLocation().add(0.5, 1, 0.5), 7,
				0, 0.2, 0, 0.03);
		player.sendMessage(MortuusTerraCore.NOTI_PREFIX + ChatColor.RED + " There is no generator in range!");
	}

}
 
Example 6
Project: WebSandboxMC   File: BlockBridge.java   Source Code and License Vote up 4 votes
public void clientNewSign(ChannelHandlerContext ctx, int x, int y, int z, int face, String text) {
    if (!allowSigns) {
        webSocketServerThread.sendLine(ctx.channel(), "T,Writing on signs is not allowed");
        // TODO: revert on client
        return;
    }

    BlockFace blockFace;
    switch (face) {
        case 0: // west
            blockFace = BlockFace.WEST;
            x -= 1;
            break;
        case 1: // east
            blockFace = BlockFace.EAST;
            x += 1;
            break;
        default:
        case 2: // north
            blockFace = BlockFace.NORTH;
            z -= 1;
            break;
        case 3: // south
            blockFace = BlockFace.SOUTH;
            z += 1;
            break;
    }
    org.bukkit.material.Sign signDirection = new org.bukkit.material.Sign();
    signDirection.setFacingDirection(blockFace);

    Location location = toBukkitLocation(x, y, z);
    if (!withinSandboxRange(location)) {
        webSocketServerThread.log(Level.FINEST, "client tried to write a sign outside sandbox range");
        return;
    }

    // Create the sign
    Block block = location.getWorld().getBlockAt(location);
    /*
    block.setTypeIdAndData(Material.WALL_SIGN.getId(), data, applyPhysics);
    webSocketServerThread.log(Level.FINEST, "setting sign at "+location+" data="+data);
    */
    BlockState blockState = block.getState();
    blockState.setType(Material.WALL_SIGN);
    blockState.setData(signDirection);
    boolean force = true;
    boolean applyPhysics = false;
    blockState.update(force, applyPhysics);
    webSocketServerThread.log(Level.FINEST, "setting sign at "+location+" blockFace="+blockFace);

    // Set the sign text
    blockState = block.getState();
    if (!(blockState instanceof Sign)) {
        webSocketServerThread.log(Level.WARNING, "failed to place sign at "+location);
        return;
    }
    Sign sign = (Sign) blockState;

    // TODO: text lines by 15 characters into 5 lines
    sign.setLine(0, text);
    sign.update(force, applyPhysics);
    webSocketServerThread.log(Level.FINEST, "set sign text="+text+", signDirection="+signDirection+", blockFace="+blockFace+", block="+block+", face="+face);

    // SignChangeEvent not posted when signs created programmatically; notify web clients ourselves
    notifySignChange(location, block.getType(), block.getState(), sign.getLines());
}