예제 #1
0
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void onBlockPhysics(BlockPhysicsEvent event) {
   final Block block = event.getBlock();
   final Material type = block.getType();
   if (MaterialUtil.ISSIGN.get(type)) {
     if (Util.isSupported(block)) {
       // Check for potential redstone changes
       updateRedstonePower(block);
     } else {
       // Remove from block power storage
       poweredBlocks.remove(block);
     }
   } else if (MaterialUtil.ISREDSTONETORCH.get(type)) {
     // Send proper update events for all signs around this power source
     for (BlockFace face : FaceUtil.RADIAL) {
       final Block rel = event.getBlock().getRelative(face);
       if (MaterialUtil.ISSIGN.get(rel)) {
         CommonUtil.nextTick(
             new Runnable() {
               public void run() {
                 updateRedstonePower(rel);
               }
             });
       }
     }
   }
 }
예제 #2
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onBlockRedstoneChange(BlockRedstoneEvent event) {
   if (TrainCarts.isWorldDisabled(event)) {
     return;
   }
   Material type = event.getBlock().getType();
   if (BlockUtil.isType(type, Material.LEVER)) {
     Block up = event.getBlock().getRelative(BlockFace.UP);
     Block down = event.getBlock().getRelative(BlockFace.DOWN);
     if (MaterialUtil.ISSIGN.get(up)) {
       updateRedstonePower(up, event.getNewCurrent() > 0);
     }
     if (MaterialUtil.ISSIGN.get(down)) {
       updateRedstonePower(down, event.getNewCurrent() > 0);
     }
     ignoreOutputLever(event.getBlock());
   } else if (MaterialUtil.ISSIGN.get(type)) {
     updateRedstonePower(event.getBlock(), event.getNewCurrent() > 0);
   }
 }
예제 #3
0
 /**
  * Ignores signs of current-tick redstone changes caused by the lever
  *
  * @param lever to ignore
  */
 public void ignoreOutputLever(Block lever) {
   // Ignore signs that are attached to the block the lever is attached to
   Block att = BlockUtil.getAttachedBlock(lever);
   for (BlockFace face : FaceUtil.ATTACHEDFACES) {
     Block signblock = att.getRelative(face);
     if (MaterialUtil.ISSIGN.get(signblock)
         && BlockUtil.getAttachedFace(signblock) == face.getOppositeFace()) {
       if (ignoredSigns.isEmpty()) {
         // clear this the next tick
         CommonUtil.nextTick(
             new Runnable() {
               public void run() {
                 ignoredSigns.clear();
               }
             });
       }
       ignoredSigns.add(signblock);
     }
   }
 }