本文整理汇总了Java中org.bukkit.block.Block.setData方法的典型用法代码示例。如果您正苦于以下问题:Java Block.setData方法的具体用法?Java Block.setData怎么用?Java Block.setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.block.Block
的用法示例。
在下文中一共展示了Block.setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderBlocks
import org.bukkit.block.Block; //导入方法依赖的package包/类
private void renderBlocks(MatchTeam matchTeam) {
byte color1 = progressingTowardsTeam != null ? ColorConverter.convertChatColorToDyeColor(progressingTowardsTeam.getColor()).getWoolData() : -1;
byte color2 = controller != null && matchTeam == controller ? ColorConverter.convertChatColorToDyeColor(controller.getColor()).getWoolData() : -1;
Location center = region.getCenter();
double x = center.getX();
double z = center.getZ();
double percent = Math.toRadians(getPercent() * 3.6);
for(Block block : region.getBlocks()) {
if(!Blocks.isVisualMaterial(block.getType())) continue;
double dx = block.getX() - x;
double dz = block.getZ() - z;
double angle = Math.atan2(dz, dx);
if(angle < 0) angle += 2 * Math.PI;
byte color = angle < percent ? color1 : color2;
if (color == -1) {
Pair<Material,Byte> oldBlock = regionSave.getBlockAt(new BlockVector(block.getLocation().toVector()));
if (oldBlock.getLeft().equals(block.getType())) color = oldBlock.getRight();
}
if (color != -1) {
block.setData(color);
// Bukkit.broadcastMessage("set to " + color);
} else {
// Bukkit.broadcastMessage("color = -1");
}
}
}
示例2: update
import org.bukkit.block.Block; //导入方法依赖的package包/类
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;
}
示例3: undo
import org.bukkit.block.Block; //导入方法依赖的package包/类
private static void undo(Player p) {
if (System.currentTimeMillis() - lastUndo < 200) {
return;
}
lastUndo = System.currentTimeMillis();
if (!configs.containsKey(p.getUniqueId())) {
p.sendMessage("Nothing to clear.");
return;
}
ArrayList<Object[][]> arr = configs.get(p.getUniqueId()).history;
if (arr.isEmpty()) {
p.sendMessage("Nothing to clear.");
return;
}
Object[][] obj = arr.remove(arr.size() - 1);
for (Object[] o : obj) {
Block temp = ((World) o[0]).getBlockAt(((Location) o[1]));
temp.setType((Material) o[2]);
temp.setData((byte) o[3]);
}
p.sendMessage("Undid last paste.");
}
示例4: onWoodBreak
import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler
public void onWoodBreak(BlockBreakEvent event) {
final Block b = event.getBlock();
if (b != null && (b.getType() == Material.LOG || b.getType() == Material.LOG_2)) {
Material handType = event.getPlayer().getItemInHand().getType();
if (handType == Material.WOOD_AXE || handType == Material.STONE_AXE || handType == Material.IRON_AXE || handType == Material.GOLD_AXE || handType == Material.DIAMOND_AXE) {
dataMap.put(b, b.getData());
b.setType(Material.WOOL);
b.setData(DyeColor.BLACK.getWoolData());
Player p = event.getPlayer();
event.getPlayer().sendMessage("> +1 Woodcutting EXP");
Location loc = b.getLocation();
Vector v = p.getLocation().subtract(loc).toVector().normalize().multiply(0.5);
DropManager.dropItem(new ItemStack(Material.LOG), loc, event.getPlayer().getUniqueId()).setVelocity(v);
RScheduler.schedule(plugin, () -> {
b.setType(Material.LOG);
b.setData(dataMap.getOrDefault(b, (byte) 0));
}, RTicks.seconds(2));
}
}
}
示例5: shuffleColors
import org.bukkit.block.Block; //导入方法依赖的package包/类
public void shuffleColors() {
for (int x = 0; x < squaresPerSide; x++) {
for (int z = 0; z < squaresPerSide; z++) {
colors[x][z] = fetchRandomColor();
}
}
for (int x = 0; x < squaresPerSide * squareSizes; x++) {
int offsetX = location.getBlockX() + x;
int squareX = x / 3;
for (int z = 0; z < squaresPerSide * squareSizes; z++) {
int offsetZ = location.getBlockZ() + z;
int squareZ = z / 3;
MaterialData materialData = colors[squareX][squareZ];
Block block = new Location(location.getWorld(), offsetX, location.getY(), offsetZ).getBlock();
block.setType(materialData.getItemType());
block.setData(materialData.getData());
}
}
}
示例6: Game
import org.bukkit.block.Block; //导入方法依赖的package包/类
public Game() {
Bukkit.getLogger().info("Loading blocks in main thread. Players shouldn't join now. Parsing " + Utils.countBlocks(BLOCK1, BLOCK2) + " objects...");
long time = System.currentTimeMillis();
for(int x = Math.min(BLOCK1.getX(), BLOCK2.getX()); x <= Math.max(BLOCK1.getX(), BLOCK2.getX()); x++) {
for(int y = Math.min(BLOCK1.getY(), BLOCK2.getY()); y <= Math.max(BLOCK1.getY(), BLOCK2.getY()); y++) {
for(int z = Math.min(BLOCK1.getZ(), BLOCK2.getZ()); z <= Math.max(BLOCK1.getZ(), BLOCK2.getZ()); z++) {
Block block = BLOCK1.getWorld().getBlockAt(x, y, z);
if(PAINTABLE_BLOCKS.contains(block.getType())) {
blocks.put(block, new ArenaBlock(x, y, z));
if(block.getType() == Material.WOOL)
block.setData((byte) 0);
}
}
}
}
Bukkit.getLogger().info(blocks.values().size() + " blocks loaded out of " + Utils.countBlocks(BLOCK1, BLOCK2) + " in " + (System.currentTimeMillis() - time) + "ms");
Bukkit.getScheduler().runTaskTimer(Absorption.get(), new RegenerationLoop(), 5 * 20, 5 * 20);
}
示例7: setTagCompound
import org.bukkit.block.Block; //导入方法依赖的package包/类
/**
* Set NBT of Block.
*
* @param b Bukkit Block.
* @return Block with changed tags.
*/
public Block setTagCompound(Block b) {
setInt("x", b.getX());
setInt("y", b.getY());
setInt("z", b.getZ());
if (hasKey("id")) b.setType(new NBTParser("{id:" + getString("id") + ",Count:1}").toItem().getType());
if (hasKey("data")) b.setData(getByte("data"));
Class tileEntity = getClazz(nmsclasses, "TileEntity");
Class craftWorld = getClazz(cbclasses, "CraftWorld");
try {
Object te = craftWorld.getDeclaredMethod("getTileEntityAt", int.class, int.class, int.class).invoke(b.getWorld(), b.getX(), b.getY(), b.getZ());
if (te != null) tileEntity.getDeclaredMethod("a", getClazz(nmsclasses, "NBTTagCompound")).invoke(te, nbtTagCompound);
} catch (Exception e) {
e.printStackTrace();
}
return b;
}
示例8: placeBlock
import org.bukkit.block.Block; //导入方法依赖的package包/类
@SuppressWarnings( value = "deprecation" )
private void placeBlock( int seq, int data )
{
int x = seq % 1000;
int z = seq / 1000;
Block block = this.getWorld().getBlockAt( x, this.getHeight(), z );
if( block.getType() != Material.WOOL )
{
block.setType( Material.WOOL );
}
byte woolColor = PlaceColor.getColorById( data ).getWoolColor();
if( block.getData() != woolColor )
{
block.setData( woolColor );
FallingBlock fb = this.getWorld().spawnFallingBlock( new Location( this.getWorld(), x, this.getFallingBlockHeight(), z ), Material.WOOL, woolColor );
fb.setDropItem( false );
fb.setHurtEntities( false );
}
}
示例9: onBlockClick
import org.bukkit.block.Block; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void onBlockClick(PlayerInteractEvent evt, Block bk, boolean rightClick) {
if (!canTrigger() || MetadataManager.updateCooldownSilently(evt.getPlayer(), "lazerBk", 2))
return;
int y = getGateLocation().getBlockY();
Block above = bk.getRelative(BlockFace.UP);
if (isPuzzle(bk, y, Material.WOOL) && above.getType() == Material.AIR && rightClick) {
above.setType(Material.DIODE_BLOCK_OFF);
above.setData((byte) 0);
}
// Remove the next
if (isPuzzle(bk, y + 1, Material.DIODE_BLOCK_OFF)) {
if (!rightClick) {
bk.setType(Material.AIR);
return;
}
bk.setData((byte) (bk.getData() >= 3 ? 0 : bk.getData() + 1));
evt.setCancelled(true);
}
}
示例10: run
import org.bukkit.block.Block; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void run(PlayerInteractEvent evt) {
Block target = evt.getClickedBlock();
if (target == null) return;
Player player = evt.getPlayer();
if (fillFaceable(target) && !isFacedLog(target)) {
target.setData(fillData(target));
AzureAPI.playSound(player, Sound.BLOCK_WOOD_FALL, true);
ItemStack item = evt.getItem();
if (Item.isTool(item)) {
item.setDurability((short) (item.getDurability() + 4));
if (item.getType().getMaxDurability() <= item.getDurability()) {
player.setItemInHand(null);
AzureAPI.playSound(player, Sound.ENTITY_ITEM_BREAK, true);
}
}
} else {
AzureAPI.log(player, isFacedLog(target) ? "这块木头已削过皮了" : "这把刀只能削树皮用");
}
}
示例11: grow
import org.bukkit.block.Block; //导入方法依赖的package包/类
public static void grow(Player p, int radius) {
Block target = p.getTargetBlock((HashSet<Byte>) null, 100);
int radius_squared = radius * radius;
Block toHandle;
SchematicUserConfig cfg = getConfig(p);
ArrayList<Block> list = new ArrayList<Block>();
for (int x = -radius; x <= radius; x++) {
for (int z = -radius; z <= radius; z++) {
toHandle = target.getWorld().getHighestBlockAt(target.getX() + x, target.getZ() + z);
if (toHandle.getType() == Material.AIR && toHandle.getRelative(BlockFace.DOWN).getType() == Material.GRASS) { // Block beneath is grass
if (target.getLocation().distanceSquared(toHandle.getLocation()) <= radius_squared) { // Block is in radius
double rand = Math.random();
if (rand < cfg.growDensity * 5 / 6) {
toHandle.setType(Material.LONG_GRASS);
toHandle.setData((byte) 1);
list.add(toHandle);
} else if (rand < cfg.growDensity) {
toHandle.setType(Material.RED_ROSE); //0 4 5 6 7 8
byte data = (byte) (Math.random() * 6);
if (data > 0)
data += 3; //1 + 3 = 4, 2 + 3 = 5, ..., 5 + 3 = 8
toHandle.setData(data);
list.add(toHandle);
}
}
}
}
}
cfg.lastGrow.add(list);
if (SchematicManager.getConfig(p).verbose)
p.sendMessage("Grew with radius " + radius + ".");
}
示例12: setBlock
import org.bukkit.block.Block; //导入方法依赖的package包/类
private void setBlock(BlockVector pos, Competitor team) {
final Block block = BlockUtils.blockAt(match.getWorld(), pos);
if(this.controlPoint.getDefinition().getVisualMaterials().query(new BlockQuery(block)).isAllowed()) {
if(team != null) {
block.setData(BukkitUtils.chatColorToDyeColor(team.getColor()).getWoolData());
} else {
this.progressDisplayImage.restore(pos);
}
}
}
示例13: run
import org.bukkit.block.Block; //导入方法依赖的package包/类
@Override
public void run() {
int updated = 0;
while (!queue.isEmpty()) {
BlockPlacement p = queue.remove();
Block b = world.getBlockAt(p.x, 30, p.y);
if (p.definitelyNew || b.getData() != p.blockType) {
b.setData(p.blockType);
updated++;
Firework f = (Firework) world.spawn(new Location(world, p.x, 30, p.y), Firework.class);
FireworkMeta fm = f.getFireworkMeta();
fm.addEffect(FireworkEffect.builder()
.flicker(false)
.trail(true)
.with(FireworkEffect.Type.BALL)
.withColor(DyeColor.getByWoolData(p.blockType).getColor())
.withFade(DyeColor.getByWoolData(p.blockType).getColor())
.build());
fm.setPower(0);
f.setFireworkMeta(fm);
}
}
if (updated > 0) {
plugin.getServer().broadcastMessage(ChatColor.DARK_GREEN + "Updated " + ChatColor.GREEN + updated + ChatColor.DARK_GREEN + " blocks!");
}
}
示例14: drawBoard
import org.bukkit.block.Block; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void drawBoard(boolean disable) {
for (int x = 22; x < 32; x++) {
for (int z = 73; z < 87; z++) {
Block bk = getWorld().getBlockAt(x, 63, z);
if (bk.getType() == Material.WOOL && (bk.getData() != 15 || !isGoing())) // If the game isn't going, that means we should reset all parts of the board.
bk.setData(disable ? (byte) 15 : randColor(true)); // If the board is being disabled, set everything to black.
}
}
}
示例15: changeColor
import org.bukkit.block.Block; //导入方法依赖的package包/类
@SuppressWarnings("SuspiciousMethodCalls")
@PuzzleTrigger
public void changeColor(CommandBlock block) {
Block wool = block.getBlock().getRelative(BlockFace.UP);
int index = COLORS.indexOf(((Wool) wool.getState().getData()).getColor()) + 1;
wool.setData(COLORS.get(index >= COLORS.size() ? 0 : index).getWoolData());
scanBoard();
}