Exemplo n.º 1
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);
   }
 }
Exemplo n.º 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 = 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);
   }
 }
Exemplo n.º 3
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);
     }
   }
 }
 /**
  * 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;
 }
Exemplo n.º 5
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;
   }
 }
Exemplo n.º 6
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;
 }
  /**
   * Gets the chance of a crop block growing<br>
   * The higher the value, the lower the chance.
   *
   * @param block to check
   * @return the growth chance
   */
  public static int getCropGrowthChance(Block block) {
    BlockMaterial material = block.getMaterial();
    float rate = 1.0f;
    float farmLandRate;
    Block rel;
    for (IntVector3 coord : FARMLAND_CHECK_RANGE) {
      rel = block.translate(coord);
      if (rel.isMaterial(VanillaMaterials.FARMLAND)) {
        if (VanillaMaterials.FARMLAND.isWet(rel)) {
          farmLandRate = 3.0f;
        } else {
          farmLandRate = 1.0f;
        }
        if (rel.getX() != 0 && rel.getZ() != 0) {
          // this is farmland at a neighbor
          farmLandRate /= 4.0f;
        }
        rate += farmLandRate;
      }
    }

    // Half, yes or no? Check for neighboring crops
    if (block.translate(-1, 0, -1).isMaterial(material)
        || block.translate(1, 0, 1).isMaterial(material)
        || block.translate(-1, 0, 1).isMaterial(material)
        || block.translate(1, 0, -1).isMaterial(material)) {
      return (int) (50f / rate);
    }
    if ((block.translate(-1, 0, 0).isMaterial(material)
            || block.translate(1, 0, 0).isMaterial(material))
        && (block.translate(0, 0, -1).isMaterial(material)
            || block.translate(0, 0, 1).isMaterial(material))) {
      return (int) (50f / rate);
    }
    return (int) (25f / rate);
  }
Exemplo n.º 8
0
 private void update() {
   Block block = getBlock();
   VanillaNetworkSynchronizer.sendPacket(
       dirty.toArray(new Player[dirty.size()]),
       new UpdateSignMessage(block.getX(), block.getY(), block.getZ(), text));
 }
Exemplo n.º 9
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;
   }
 }
Exemplo n.º 10
0
 public static BlockWorldVector toWorldVector(Block block) {
   return new BlockWorldVector(
       getLocalWorld(block.getWorld()), block.getX(), block.getY(), block.getZ());
 }
Exemplo n.º 11
0
 public static BlockVector toVector(Block block) {
   return new BlockVector(block.getX(), block.getY(), block.getZ());
 }
Exemplo n.º 12
0
 public BlockBreakAnimationMessage(Entity entity, Block block, byte stage, RepositionManager rm) {
   this(entity.getId(), block.getX(), block.getY(), block.getZ(), stage, rm);
 }
 @EventHandler
 public Message onBlockControllerData(BlockControllerDataEvent event) {
   Block b = event.getBlock();
   return new EntityTileDataMessage(
       b.getX(), b.getY(), b.getZ(), event.getAction(), event.getData());
 }
 @EventHandler
 public Message onSignUpdate(SignUpdateEvent event) {
   Block block = (Block) event.getSign().getPlacedBlock();
   return new SignMessage(block.getX(), block.getY(), block.getZ(), event.getLines());
 }