我试图进入针对我的世界的bukkit编程,但出于某种原因,我一直试图设置一个块供电。 我不想在街区下面设置红石火炬。
我尝试将数据更改为活动控制杆。 如果有人可以帮助我,请。
我试过的代码:
Block n = my block;
Block block = your lever;
Lever l = (Lever) block;
l.setPowered(true); //toggles on
n.setData(l.getData());
答案 0 :(得分:2)
不幸的是,不可能直接为不是Powerable Block的块供电。
然而,你可以做一些技巧来假装它的动力:
每当您希望块为附近的块供电时(例如onInteractEvent)检测,然后向块发送电源。
@EventHandler
public void onInteractEvent(PlayerInteractEvent e) {
Block interacted = e.getClickedBlock();
//Check if this is the block you want
Block block= interacted.getRelative(BlockFace.UP, 1); //Can be changed to any block face, and any distance
switch(block.getType()) {
case LEVER:
case REDSTONE:
case DISPENSER:
case POWERED_RAILS:
case whatever other blocks can be powered:
{
block.setData(block.getData() | 0x8); // sets the 0x8 bit to the data, making it powered
} }