Beispiel #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);
     }
   }
 }
Beispiel #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);
   }
 }
 /**
  * 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;
 }
Beispiel #4
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);
   }
 }
Beispiel #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;
   }
 }
Beispiel #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;
 }
 @Override
 public void populate(Chunk chunk, Random random) {
   if (chunk.getY() != 4) {
     return;
   }
   final int size = Chunk.BLOCKS.SIZE;
   final int x = chunk.getBlockX();
   final int z = chunk.getBlockZ();
   final World world = chunk.getWorld();
   final int seed = (int) (world.getSeed() * 73);
   SHIELD_BASE.setSeed(seed);
   SHIELD.setSeed(seed);
   final double[][] noise = WorldGeneratorUtils.fastNoise(SHIELD, size, size, 4, x, 63, z);
   for (int xx = 0; xx < size; xx++) {
     for (int zz = 0; zz < size; zz++) {
       if (noise[xx][zz] > 0.92) {
         final int y = world.getSurfaceHeight(x + xx, z + zz);
         for (int yy = 0; yy >= -7; yy--) {
           if (yy == 0) {
             final Block block = world.getBlock(x + xx, y + yy, z + zz, world);
             if (!canReplace(block.getMaterial())) {
               continue;
             }
             block.setMaterial(
                 block.getY() <= NormalGenerator.SEA_LEVEL
                     ? VanillaMaterials.STATIONARY_WATER
                     : VanillaMaterials.AIR);
           } else {
             if (canReplace(world.getBlockMaterial(x + xx, y + yy, z + zz))) {
               world.setBlockMaterial(
                   x + xx, y + yy, z + zz, VanillaMaterials.STONE, (short) 0, world);
             }
           }
         }
       }
     }
   }
 }
Beispiel #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));
 }
Beispiel #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;
   }
 }
Beispiel #10
0
 public static BlockWorldVector toWorldVector(Block block) {
   return new BlockWorldVector(
       getLocalWorld(block.getWorld()), block.getX(), block.getY(), block.getZ());
 }
Beispiel #11
0
 public static BlockVector toVector(Block block) {
   return new BlockVector(block.getX(), block.getY(), block.getZ());
 }
 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());
 }