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

The following examples show how to use org.bukkit.block.Block#getChunk() . 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 Kettle with GNU General Public License v3.0 6 votes vote down vote up
public CraftBlockState(final Block block) {
    this.world = (CraftWorld) block.getWorld();
    this.x = block.getX();
    this.y = block.getY();
    this.z = block.getZ();
    this.type = block.getTypeId();
    this.chunk = (CraftChunk) block.getChunk();
    this.flag = 3;

    createData(block.getData());
    TileEntity te = world.getHandle().getTileEntity(new BlockPos(this.x, this.y, this.z));
    if (te != null) {
        nbt = new NBTTagCompound();
        te.writeToNBT(nbt);
    } else nbt = null;
}
 
Example 2
Source File: CraftBlockState.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public CraftBlockState(final Block block) {
    this.world = (CraftWorld) block.getWorld();
    this.x = block.getX();
    this.y = block.getY();
    this.z = block.getZ();
    this.type = block.getTypeId();
    this.light = block.getLightLevel();
    this.chunk = (CraftChunk) block.getChunk();
    this.flag = 3;
    // Cauldron start - save TE data
    TileEntity te = world.getHandle().getTileEntity(x, y, z);
    if (te != null)
    {
        nbt = new NBTTagCompound();
        te.writeToNBT(nbt);
    }
    else nbt = null;
    // Cauldron end

    createData(block.getData());
}
 
Example 3
Source File: Util.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public List<Chunk> getChunks(World mapWorld) {
int size = 400;
int maxX = size/2;
int minX = -size/2;
int maxZ = size/2;
int minZ = -size/2;
int minY = 0;
int maxY = 0;
Block min = mapWorld.getBlockAt(minX, minY, minZ);
Block max = mapWorld.getBlockAt(maxX, maxY, maxZ);
Chunk cMin = min.getChunk();
Chunk cMax = max.getChunk();
List<Chunk> chunks = new ArrayList<>();

for(int cx = cMin.getX(); cx < cMax.getX(); cx++) {
	for(int cz = cMin.getZ(); cz < cMax.getZ(); cz++) {
           Chunk currentChunk = mapWorld.getChunkAt(cx, cz);
           chunks.add(currentChunk);
	}
}
return chunks;
  }
 
Example 4
Source File: ChunkEventHelper.java    From ClaimChunk with MIT License 5 votes vote down vote up
private static void handlePistonEvent(@Nonnull Block piston, @Nonnull List<Block> blocks, @Nonnull BlockFace direction, @Nonnull Cancellable e) {
    if (e.isCancelled()) return;

    // If we don't protect against pistons, no work is needed.
    if (!config.getBool("protection", "blockPistonsIntoClaims")) return;

    Chunk pistonChunk = piston.getChunk();
    List<Chunk> blockChunks = new ArrayList<>();
    blockChunks.add(piston.getRelative(direction).getChunk());

    // Add to the list of chunks possible affected by this piston
    // extension. This list should never be >2 in size but the world
    // is a weird place.
    for (Block block : blocks) {
        Chunk to = block.getRelative(direction).getChunk();

        boolean added = false;
        for (Chunk ablockChunk : blockChunks) {
            if (getChunksEqual(ablockChunk, to)) {
                added = true;
                break;
            }
        }
        if (!added) blockChunks.add(to);
    }

    // If the from and to chunks have the same owner or if the to chunk is
    // unclaimed, the piston can extend into the blockChunk.
    final ChunkHandler CHUNK = ClaimChunk.getInstance().getChunkHandler();
    boolean die = false;
    for (Chunk blockChunk : blockChunks) {
        if (!getChunksSameOwner(CHUNK, pistonChunk, blockChunk) && CHUNK.isClaimed(blockChunk)) {
            die = true;
            break;
        }
    }
    if (!die) return;

    e.setCancelled(true);
}
 
Example 5
Source File: BrewingStandContainer.java    From Transport-Pipes with MIT License 4 votes vote down vote up
public BrewingStandContainer(Block block) {
    super(block);
    this.chunk = block.getChunk();
    this.cachedBrewingStand = (BrewingStand) block.getState();
    this.cachedInv = cachedBrewingStand.getInventory();
}
 
Example 6
Source File: SimpleInventoryContainer.java    From Transport-Pipes with MIT License 4 votes vote down vote up
public SimpleInventoryContainer(Block block) {
    super(block);
    this.chunk = block.getChunk();
    this.cachedInvHolder = (InventoryHolder) block.getState();
    this.cachedInv = cachedInvHolder.getInventory();
}
 
Example 7
Source File: FurnaceContainer.java    From Transport-Pipes with MIT License 4 votes vote down vote up
public FurnaceContainer(Block block) {
    super(block);
    this.chunk = block.getChunk();
    this.cachedFurnace = (Furnace) block.getState();
    this.cachedInv = cachedFurnace.getInventory();
}
 
Example 8
Source File: GameMap.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
private void ChunkIterator(boolean message, Player sender) {
	World chunkWorld;
	chunkWorld = SkyWarsReloaded.get().getServer().getWorld(name);
	int mapSize = SkyWarsReloaded.getCfg().getMaxMapSize();
	int max1 = mapSize/2;
	int min1 = -mapSize/2;
	Block min = chunkWorld.getBlockAt(min1, 0, min1);
	Block max = chunkWorld.getBlockAt(max1, 0, max1);
	Chunk cMin = min.getChunk();
	Chunk cMax = max.getChunk();
	teamCards.clear();
	chests.clear();
	
	for(int cx = cMin.getX(); cx < cMax.getX(); cx++) {
		for(int cz = cMin.getZ(); cz < cMax.getZ(); cz++) {
	           Chunk currentChunk = chunkWorld.getChunkAt(cx, cz);
	           currentChunk.load(true);

	           for(BlockState te : currentChunk.getTileEntities()) {
	               	if(te instanceof Beacon){
		                  Beacon beacon = (Beacon) te;
		                  Block block = beacon.getBlock().getRelative(0, -1, 0);
		                  if(!block.getType().equals(Material.GOLD_BLOCK) && !block.getType().equals(Material.IRON_BLOCK) 
		                		  && !block.getType().equals(Material.DIAMOND_BLOCK)&& !block.getType().equals(Material.EMERALD_BLOCK)) {
			                  Location loc = beacon.getLocation();
			                  addTeamCard(loc);
			                  if (message) {
			                  	sender.sendMessage(new Messaging.MessageFormatter().setVariable("num", "" + getMaxPlayers()).setVariable("mapname", getDisplayName()).format("maps.addSpawn"));
							  }
		                  }
		            } else if (te instanceof Chest) {
						Chest chest = (Chest) te;
						addChest(chest, ChestPlacementType.NORMAL);
						if (message) {
							sender.sendMessage(new Messaging.MessageFormatter().setVariable("mapname", getDisplayName()).format("maps.addChest"));
						}
		            } 
	           }
	        }
     }
}