예제 #1
0
 @Override
 public void onInteractBy(
     Entity entity, Block block, PlayerInteractEvent.Action type, BlockFace clickedFace) {
   super.onInteractBy(entity, block, type, clickedFace);
   if (type != PlayerInteractEvent.Action.RIGHT_CLICK) {
     return;
   }
   Slot inv = PlayerUtil.getHeldSlot(entity);
   if (inv != null && inv.get() != null && inv.get().isMaterial(Dye.BONE_MEAL)) {
     if (!PlayerUtil.isCostSuppressed(entity)) {
       inv.addAmount(-1);
     }
     final BlockMaterial mushroomType = block.getMaterial();
     final VariableHeightObject mushroom;
     if (mushroomType == VanillaMaterials.RED_MUSHROOM) {
       mushroom = new HugeMushroomObject(HugeMushroomType.RED);
     } else {
       mushroom = new HugeMushroomObject(HugeMushroomType.BROWN);
     }
     final World world = block.getWorld();
     final int x = block.getX();
     final int y = block.getY();
     final int z = block.getZ();
     if (mushroom.canPlaceObject(world, x, y, z)) {
       mushroom.placeObject(world, x, y, z);
     }
   }
 }
예제 #2
0
 public static void growTree(Sapling sapling, Block pos, Random random) {
   final TreeObject tree;
   final World world = pos.getWorld();
   final int y = pos.getY();
   if (sapling == Sapling.JUNGLE) {
     final int x = pos.getX();
     final int z = pos.getZ();
     byte saplingCount = 0;
     Block firstSapling = null;
     for (byte xx = -1; xx < 2; xx++) {
       for (byte zz = -1; zz < 2; zz++) {
         if (world.getBlockMaterial(x + xx, y, z + zz) == Sapling.JUNGLE) {
           saplingCount++;
           if (saplingCount == 1) {
             firstSapling = world.getBlock(x + xx, y, z + zz);
           }
         }
       }
     }
     if (saplingCount > 3
         && firstSapling.translate(1, 0, 1).isMaterial(Sapling.JUNGLE)
         && firstSapling.translate(0, 0, 1).isMaterial(Sapling.JUNGLE)
         && firstSapling.translate(1, 0, 0).isMaterial(Sapling.JUNGLE)) {
       pos = firstSapling;
       tree = new HugeTreeObject();
     } else {
       tree = new SmallTreeObject();
       tree.setTreeType(TreeObject.TreeType.JUNGLE);
       tree.setBaseHeight((byte) 4);
       tree.setRandomHeight((byte) 10);
       ((SmallTreeObject) tree).addLogVines(true);
       ((SmallTreeObject) tree).addCocoaPlants(true);
     }
   } else if (sapling == Sapling.BIRCH) {
     tree = new SmallTreeObject();
     tree.setTreeType(TreeObject.TreeType.BIRCH);
   } else if (sapling == Sapling.SPRUCE) {
     if (random.nextBoolean()) {
       tree = new PineTreeObject();
     } else {
       tree = new SpruceTreeObject();
     }
   } else {
     if (random.nextInt(10) == 0) {
       tree = new BigTreeObject();
     } else {
       tree = new SmallTreeObject();
     }
   }
   tree.setRandom(random);
   tree.randomize();
   final int x = pos.getX();
   final int z = pos.getZ();
   if (tree.canPlaceObject(world, x, y, z)) {
     tree.placeObject(world, x, y, z);
   }
 }
예제 #3
0
 @Override
 public void onUpdate(BlockMaterial oldMaterial, Block block) {
   super.onUpdate(oldMaterial, block);
   if (!block.translate(BlockFace.BOTTOM).getMaterial().isPlacementObstacle()) {
     // turn this block into a mobile block
     Entity e =
         block
             .getWorld()
             .createAndSpawnEntity(block.getPosition(), FallingBlock.class, LoadOption.NO_LOAD);
     e.add(FallingBlock.class).setMaterial(this);
     block.setMaterial(VanillaMaterials.AIR);
   }
 }
 /**
  * Gets if rain is falling nearby the block specified
  *
  * @param block to check it nearby of
  * @return True if it is raining, False if not
  */
 public static boolean hasRainNearby(Block block) {
   Sky sky = block.getWorld().get(Sky.class);
   if (sky != null && sky.hasWeather()) {
     if (sky.getWeatherSimulator().isRainingAt(block.getX(), block.getY(), block.getZ(), false)) {
       for (BlockFace face : BlockFaces.NESW) {
         if (block.translate(face).isAtSurface()) {
           return true;
         }
       }
     }
   }
   return false;
 }
예제 #5
0
 public static void growTree(Sapling sapling, Block pos, Random random) {
   final TreeObject tree;
   final World world = pos.getWorld();
   final int y = pos.getY();
   if (sapling == Sapling.JUNGLE) {
     final int x = pos.getX();
     final int z = pos.getZ();
     byte saplingCount = 0;
     Block firstSapling = null;
     for (byte xx = -1; xx < 2; xx++) {
       for (byte zz = -1; zz < 2; zz++) {
         if (world.getBlockMaterial(x + xx, y, z + zz) == Sapling.JUNGLE) {
           saplingCount++;
           if (saplingCount == 1) {
             firstSapling = world.getBlock(x + xx, y, z + zz);
           }
         }
       }
     }
     if (saplingCount > 3
         && firstSapling.translate(1, 0, 1).isMaterial(Sapling.JUNGLE)
         && firstSapling.translate(0, 0, 1).isMaterial(Sapling.JUNGLE)
         && firstSapling.translate(1, 0, 0).isMaterial(Sapling.JUNGLE)) {
       pos = firstSapling;
       tree = VanillaObjects.HUGE_JUNGLE_TREE;
     } else {
       tree = VanillaObjects.SMALL_JUNGLE_TREE;
     }
   } else if (sapling == Sapling.BIRCH) {
     tree = VanillaObjects.SMALL_BIRCH_TREE;
   } else if (sapling == Sapling.SPRUCE) {
     if (random.nextBoolean()) {
       tree = VanillaObjects.PINE_TREE;
     } else {
       tree = VanillaObjects.SPRUCE_TREE;
     }
   } else {
     if (random.nextInt(10) == 0) {
       tree = VanillaObjects.BIG_OAK_TREE;
     } else {
       tree = VanillaObjects.SMALL_OAK_TREE;
     }
   }
   tree.setRandom(random);
   tree.randomize();
   final int x = pos.getX();
   final int z = pos.getZ();
   if (tree.canPlaceObject(world, x, y, z)) {
     tree.placeObject(world, x, y, z);
   }
 }
예제 #6
0
 @Override
 public boolean equals(Object other) {
   if (other == this) {
     return true;
   } else if (other != null && other instanceof Block) {
     Block b = (Block) other;
     return b.getWorld() == this.getWorld()
         && b.getX() == this.getX()
         && b.getY() == this.getY()
         && b.getZ() == this.getZ();
   } else {
     return false;
   }
 }
예제 #7
0
  @Override
  public void onTick(float dt) {
    Block block = getBlock();
    HashSet<Player> nearby = new HashSet<Player>();
    nearby.addAll(block.getWorld().getNearbyPlayers(block.getPosition(), range));
    if (nearby == null || nearby.isEmpty()) {
      return;
    }

    if (dirty.isEmpty() || !dirty.containsAll(nearby)) {
      nearby.removeAll(dirty);
      dirty = nearby;
      update();
    }
  }
예제 #8
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 ?
 }
예제 #9
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;
 }
예제 #10
0
 @Override
 public void onUpdate(BlockMaterial oldMaterial, Block block) {
   super.onUpdate(oldMaterial, block);
   block.syncResetDynamic();
   block.dynamicUpdate(block.getWorld().getAge() + this.getFlowDelay());
 }
예제 #11
0
 public SpoutBlock(Block source) {
   this(source.getWorld(), source.getX(), source.getY(), source.getZ(), source.getSource());
   if (source instanceof SpoutBlock) {
     this.chunk = ((SpoutBlock) source).chunk;
   }
 }
예제 #12
0
 public static BlockWorldVector toWorldVector(Block block) {
   return new BlockWorldVector(
       getLocalWorld(block.getWorld()), block.getX(), block.getY(), block.getZ());
 }
예제 #13
0
 /**
  * Gets if rain is falling on top of the block specified
  *
  * @param block to check
  * @return True if rain is falling on the Block, false if not
  */
 public static boolean isRaining(Block block) {
   return block.getWorld().getData().get(VanillaData.WORLD_WEATHER).isRaining()
       && block.isAtSurface();
 }
예제 #14
0
 @Override
 public void handlePlacement(Block block, short data, BlockFace attachedFace) {
   block.getWorld().createAndSpawnEntity(block.getPosition(), Sign.class, LoadOption.NO_LOAD);
   this.setAttachedFace(block, attachedFace);
 }