Exemplo n.º 1
0
 @Override
 public void onUpdate(BlockMaterial oldMaterial, Block block) {
   super.onUpdate(oldMaterial, block);
   boolean power = isReceivingPower(block);
   if (power) {
     block.setData(HAS_REDSTONE_POWER);
   } else {
     block.setData(HAS_NO_REDSTONE_POWER);
     for (BlockFace face : BlockFaces.BTEWNS) {
       Block other = block.translate(face);
       if (other.getMaterial() instanceof RedstoneLamp) {
         if (other.getData() == HAS_REDSTONE_POWER) {
           power = true;
           break;
         }
       }
     }
   }
   if (on != power) {
     if (power) {
       block.setMaterial(VanillaMaterials.REDSTONE_LAMP_ON);
     } else {
       block.setMaterial(VanillaMaterials.REDSTONE_LAMP_OFF);
     }
   }
 }
Exemplo n.º 2
0
 @Override
 public void onDynamicUpdate(Block block, long updateTime, int data) {
   if (willMeltAt(block)) {
     short dataBlock = block.getData();
     if (dataBlock > 0) {
       block.setData(dataBlock - 1);
     } else {
       block.setMaterial(VanillaMaterials.AIR);
     }
   } else { // not warm enough to melt the snow and last poll was a long time ago, might as well
            // skip repeated polls
     long age = block.getWorld().getAge();
     if (age - updateTime > POLL_TIME) {
       block.dynamicUpdate(age + new Random().nextInt((int) POLL_TIME), true);
       return;
     }
   }
   block.dynamicUpdate(updateTime + POLL_TIME, true);
   // TODO : Delay before next check ?
 }
Exemplo n.º 3
0
 /**
  * Let's this liquid flow from the block to the direction given
  *
  * @param block to flow from
  * @param to flow to
  * @return True if flowing was successful
  */
 public boolean onFlow(Block block, BlockFace to) {
   int level;
   if (to == BlockFace.BOTTOM) {
     level = this.getMaxLevel();
   } else {
     level = this.getLevel(block) - 1;
     if (level < 0) {
       return false;
     }
   }
   Block spread =
       block.getWorld().getBlock(block.getX(), block.getY(), block.getZ(), this).translate(to);
   BlockMaterial spreadMat = spread.getMaterial();
   if (this.isMaterial(spreadMat)) {
     if (this.isMaximumLevel(spread)) {
       // If the block above was a non-flowing source, return false to make it spread outwards
       // If the block above was not a source, return true to stop spreading
       return !this.isSource(block);
     } else {
       // Compare levels
       if (level > this.getLevel(spread)) {
         if (spreadMat != this.getFlowingMaterial()) {
           // Make sure the material is adjusted
           spread.setMaterial(this.getFlowingMaterial(), spread.getData());
         }
         this.setLevel(spread, level);
         if (to == BlockFace.BOTTOM) {
           this.setFlowingDown(spread, true);
         }
         // Update blocks around
         return true;
       }
     }
   } else if (!isLiquidObstacle(spreadMat)) {
     // Create a new liquid
     this.onSpread(spread, level, to.getOpposite());
     return true;
   }
   return false;
 }
Exemplo n.º 4
0
 @Override
 public BlockFace getAttachedFace(Block block) {
   return BlockFaces.NSEWB.get(block.getData() - 1, BlockFace.BOTTOM);
 }
Exemplo n.º 5
0
 @Override
 public void toggleOpen(Block block) {
   block.setData(block.getData() ^ 0x4);
 }
Exemplo n.º 6
0
 @Override
 public BlockFace getAttachedFace(Block block) {
   return BlockFaces.WESN.get(block.getData() & ~0x4);
 }
Exemplo n.º 7
0
 /**
  * Sets if this half slab is the top-half
  *
  * @param block to set it for
  * @param top state
  */
 public void setTop(Block block, boolean top) {
   block.setData(LogicUtil.setBit(block.getData(), 0x8, top));
 }
Exemplo n.º 8
0
 /**
  * Gets if this half slab is the top-half
  *
  * @param block to get it of
  * @return True if it is the block half
  */
 public boolean isTop(Block block) {
   return LogicUtil.getBit(block.getData(), 0x8);
 }
Exemplo n.º 9
0
 @Override
 public BlockFace getFacing(Block block) {
   return BlockFaces.EWNS.get(block.getData() - 2);
 }
Exemplo n.º 10
0
 /**
  * Gets whether this liquid is a source
  *
  * @param block of the liquid
  * @return True if it is a source, False if not
  */
 public boolean isSource(Block block) {
   return block.getData() == 0x0;
 }
Exemplo n.º 11
0
 @Override
 public RailsState getState(Block block) {
   return RailsState.get(block.getData());
 }
Exemplo n.º 12
0
 @Override
 public boolean isFullyGrown(Block block) {
   return block.getData() == 0x7;
 }