Java Code Examples for org.bukkit.block.Block#setTypeId()

The following examples show how to use org.bukkit.block.Block#setTypeId() . 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: CraftBlockState.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public boolean update(boolean force, boolean applyPhysics) {
    Block block = getBlock();

    if (block.getType() != getType()) {
        if (force) {
            block.setTypeId(getTypeId(), applyPhysics);
        } else {
            return false;
        }
    }

    block.setData(getRawData(), applyPhysics);
    world.getHandle().markBlockForUpdate(x, y, z);
    // Cauldron start - restore TE data from snapshot
    if (nbt != null)
    {
        TileEntity te = world.getHandle().getTileEntity(x, y, z);
        if (te != null)
        {
            te.readFromNBT(nbt);
        }
    }
    // Cauldron end

    return true;
}
 
Example 2
Source File: ItemManager.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static void setTypeId(Block block, int typeId) {
	block.setTypeId(typeId);
}
 
Example 3
Source File: IslandBlock.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Paste this block at blockLoc
 * @param nms
 * @param blockLoc
 */
//@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
public void paste(NMSAbstraction nms, Location blockLoc, boolean usePhysics, Biome biome) {
    // Only paste air if it is below the sea level and in the overworld
    Block block = new Location(blockLoc.getWorld(), x, y, z).add(blockLoc).getBlock();
    block.setBiome(biome);
    nms.setBlockSuperFast(block, typeId, data, usePhysics);
    if (signText != null) {
        if (block.getTypeId() != typeId) {
            block.setTypeId(typeId);
        }
        // Sign
        Sign sign = (Sign) block.getState();
        int index = 0;
        for (String line : signText) {
            sign.setLine(index++, line);
        }
        sign.update(true, false);
    } else if (banner != null) {
        banner.set(block);
    } else if (skull != null){
        skull.set(block);
    } else if (pot != null){
        pot.set(nms, block);
    } else if (spawnerBlockType != null) {
        if (block.getTypeId() != typeId) {
            block.setTypeId(typeId);
        }
        CreatureSpawner cs = (CreatureSpawner)block.getState();
        cs.setSpawnedType(spawnerBlockType);
        //Bukkit.getLogger().info("DEBUG: setting spawner");
        cs.update(true, false);
    } else if (!chestContents.isEmpty()) {
        if (block.getTypeId() != typeId) {
            block.setTypeId(typeId);
        }
        //Bukkit.getLogger().info("DEBUG: inventory holder "+ block.getType());
        // Check if this is a double chest
        
        InventoryHolder chestBlock = (InventoryHolder) block.getState();
        //InventoryHolder iH = chestBlock.getInventory().getHolder();
        if (chestBlock instanceof DoubleChest) {
            //Bukkit.getLogger().info("DEBUG: double chest");
            DoubleChest doubleChest = (DoubleChest) chestBlock;
            for (ItemStack chestItem: chestContents.values()) {
                doubleChest.getInventory().addItem(chestItem);
            }
        } else {
            // Single chest
            for (Entry<Byte, ItemStack> en : chestContents.entrySet()) {
                //Bukkit.getLogger().info("DEBUG: " + en.getKey() + ","  + en.getValue());
                chestBlock.getInventory().setItem(en.getKey(), en.getValue());
            }
        }
    }
}
 
Example 4
Source File: ExtensionLeaderboardPodium.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public void update(Map<String, Statistic> statistics, boolean forceBlocks, boolean delete) {
	BlockFace2D rightDir = direction.right();
	BlockFace2D leftDir = direction.left();
	
	BlockFace rightFace = rightDir.getBlockFace3D();
	BlockFace leftFace = leftDir.getBlockFace3D();
	
	Block baseBlock = baseLocation.getBlock();
	if (delete) {
		baseBlock.setType(Material.AIR);
	}
	
	SignLayout layout = layoutConfig.getLayout();
	
	Iterator<Entry<String, Statistic>> iterator = statistics != null ? statistics.entrySet().iterator() : null;
	for (int i = 0; i < size.getStatisticAmount(); i++) {
		Entry<String, Statistic> entry = iterator != null && iterator.hasNext() ? iterator.next() : null;
		
		Block position = null;
		Material type = null;
		
		switch (i) {
		case 0:
			//Top
			position = baseBlock.getRelative(BlockFace.UP);
			type = Material.DIAMOND_BLOCK;
			break;
		case 1:
			//First left
			position = baseBlock.getRelative(leftFace);
			type = Material.GOLD_BLOCK;
			break;
		case 2:
			//First right
			position = baseBlock.getRelative(rightFace);
			type = Material.IRON_BLOCK;
			break;
		case 3:
			//Second left
			position = baseBlock.getRelative(leftFace, 2);
			type = Material.DOUBLE_STEP;
			break;
		case 4:
			//Second right
			position = baseBlock.getRelative(rightFace, 2);
			type = Material.DOUBLE_STEP;
			break;
		}
		
		if (position == null) {
			continue;
		}
		
		Block signBlock = position.getRelative(direction.getBlockFace3D());
		Block skullBlock = position.getRelative(BlockFace.UP);
		
		if (delete) {
			signBlock.setType(Material.AIR);
			skullBlock.setType(Material.AIR);
			position.setType(Material.AIR);
			continue;
		}
		
		if (baseBlock.getType() == Material.AIR || forceBlocks) {
			baseBlock.setType(Material.DOUBLE_STEP);
		}
		
		if (position.getType() == Material.AIR || forceBlocks) {
			position.setType(type);
		}
		
		if (entry == null) {
			continue;
		}
		
		/* For legacy reasons and compatibility */
		signBlock.setTypeId(Material.WALL_SIGN.getId(), false);
		skullBlock.setTypeId(Material.SKULL.getId(), false);
		
		Skull skull = (Skull) skullBlock.getState();
		skull.setRotation(direction.getBlockFace3D());
		skull.setSkullType(SkullType.PLAYER);
		skull.setOwner(entry.getKey());
		skull.setRawData(SKULL_ON_FLOOR);
		skull.update(true, false);
		
		Sign sign = (Sign) signBlock.getState();
		
		Set<Variable> variables = Sets.newHashSet();
		entry.getValue().supply(variables, null);
		variables.add(new Variable("player", entry.getKey()));
		variables.add(new Variable("rank", i + 1));
		
		layout.inflate(sign, variables);
		org.bukkit.material.Sign data = new org.bukkit.material.Sign(Material.WALL_SIGN);
		data.setFacingDirection(direction.getBlockFace3D());
		sign.setData(data);
		sign.update();
	}
}