예제 #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);
     }
   }
 }
예제 #2
0
파일: Snow.java 프로젝트: aginsun/Vanilla
 @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 ?
 }
예제 #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;
 }
예제 #4
0
 @Override
 public BlockFace getAttachedFace(Block block) {
   return BlockFaces.NSEWB.get(block.getData() - 1, BlockFace.BOTTOM);
 }
예제 #5
0
 @Override
 public void toggleOpen(Block block) {
   block.setData(block.getData() ^ 0x4);
 }
예제 #6
0
 @Override
 public BlockFace getAttachedFace(Block block) {
   return BlockFaces.WESN.get(block.getData() & ~0x4);
 }
예제 #7
0
파일: Slab.java 프로젝트: TomyLobo/Vanilla
 /**
  * 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));
 }
예제 #8
0
파일: Slab.java 프로젝트: TomyLobo/Vanilla
 /**
  * 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);
 }
예제 #9
0
 @Override
 public BlockFace getFacing(Block block) {
   return BlockFaces.EWNS.get(block.getData() - 2);
 }
예제 #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;
 }
예제 #11
0
 @Override
 public RailsState getState(Block block) {
   return RailsState.get(block.getData());
 }
예제 #12
0
파일: Stem.java 프로젝트: stewbasic/Vanilla
 @Override
 public boolean isFullyGrown(Block block) {
   return block.getData() == 0x7;
 }