本文整理匯總了Java中org.bukkit.block.BlockState.setData方法的典型用法代碼示例。如果您正苦於以下問題:Java BlockState.setData方法的具體用法?Java BlockState.setData怎麽用?Java BlockState.setData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.block.BlockState
的用法示例。
在下文中一共展示了BlockState.setData方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setRawTypeIdAndData
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
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;
}
示例2: replaceBlock
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
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);
}
}
}
示例3: getNewState
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
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;
}
}
示例4: onBlockPistonExtend
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
@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);
}
示例5: onLeverOrButton
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
@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!");
}
}
示例6: clientNewSign
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
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());
}