Example #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);
     }
   }
 }
Example #2
0
  @Override
  public void setAttachedFace(Block block, BlockFace attachedFace, Cause<?> cause) {
    if (attachedFace == BlockFace.BOTTOM) {
      // Attached to the ground
      block.setData(0x1, cause);

      // This below bit is completely wrong - rotation is not stored in the block data
      // It is stored in the block component instead
      // It should be set to 0x1, but it needs to be fully tested first
      // Skull type needs to be set somewhere too, most likely in the block component
      // TODO: Finish this off...
      /*
      short data = 0;
      Object source = cause.getSource();
      if (source instanceof Entity) {
      	Vector3 direction = block.getPosition().subtract(((Entity) source).getTransform().getPosition());
      	float rotation = direction.rotationTo(Vector3.RIGHT).getYaw();
      	rotation = rotation / 360f * 16f;
      	data = (short) rotation;
      }
      if (block.setMaterial(this, data)) {
      	block.queueUpdate(EffectRange.THIS);
      }
      */
    } else {
      // Attached to a wall
      block.setData(BlockFaces.NSWE.indexOf(attachedFace, 0) + 2, cause);
    }
  }
Example #3
0
  @Override
  public void onInteract(Entity entity, Block block, Action type, BlockFace clickedface) {
    super.onInteract(entity, block, type, clickedface);
    if (type == Action.RIGHT_CLICK) {
      BlockMaterial clickedmat = block.getMaterial();
      Cause<Entity> cause;
      if (entity instanceof Player) {
        cause = new PlayerCause((Player) entity);
      } else {
        cause = new EntityCause(entity);
      }
      if (clickedmat.equals(VanillaMaterials.TNT)) {
        // Detonate TntBlock
        VanillaMaterials.TNT.onIgnite(block, cause);
      } else {
        // Default fire creation
        Block target = block.translate(clickedface);
        // Default fire placement
        if (VanillaMaterials.FIRE.canCreate(target, (short) 0, cause)) {
          VanillaMaterials.FIRE.onCreate(target, (short) 0, cause);
          Slot held = PlayerUtil.getHeldSlot(entity);
          if (held != null && !PlayerUtil.isCostSuppressed(entity)) {
            held.addData(1);
          }
        }

        // Handle the creation of portals
        Point pos = target.translate(BlockFace.BOTTOM).getPosition();
        VanillaObjects.NETHER_PORTAL.setActive(
            pos.getWorld(), pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), true);
      }
    }
  }
Example #4
0
  @Override
  public void populate(Chunk source, Random random) {
    if (source.getY() < 4) {
      return;
    }
    if (random.nextInt(100) > chance) {
      return;
    }

    int x = source.getBlockX();
    int z = source.getBlockZ();
    int y;
    int numSteps = random.nextInt(maxSteps - minSteps + 1) + minSteps;
    for (int i = 0; i < numSteps; i++) {
      x += random.nextInt(3) - 1;
      z += random.nextInt(3) - 1;
      y = source.getBlockY() + 15;
      Block b = source.getWorld().getBlock(x, y, z);
      while (b.getMaterial() == VanillaMaterials.AIR) {
        b = b.translate(BlockFace.BOTTOM);
        if (--y < 0) {
          return;
        }
      }
      if (b.getMaterial() == VanillaMaterials.GRASS) {
        b = b.translate(BlockFace.TOP).setMaterial(VanillaMaterials.TALL_GRASS);
      }
    }
  }
Example #5
0
 /**
  * Sets whether this pressure plate is pressed down
  *
  * @param block to set it of
  * @param pressed whether it is pressed
  */
 public void setPressed(Block block, boolean pressed) {
   if (this.isPressed(block) != pressed) {
     block.setDataBits(0x1, pressed);
     GeneralEffects.BLOCK_PRESS.playGlobal(block.getPosition(), pressed);
   }
   block.resetDynamic();
 }
Example #6
0
 @Override
 public void onUpdate(Block block) {
   BlockMaterial below = block.translate(BlockFace.BOTTOM).getMaterial();
   if (below.getMaterial() == VanillaMaterials.AIR) {
     block.setMaterial(VanillaMaterials.AIR).update(true);
   }
 }
Example #7
0
  @Override
  public void onInteract(Entity entity, Block block, Action type, BlockFace clickedface) {
    super.onInteract(entity, block, type, clickedface);
    if (type == Action.RIGHT_CLICK) {
      BlockMaterial clickedmat = block.getMaterial();
      if (clickedmat.equals(VanillaMaterials.TNT)) {
        // Detonate TntBlock
        VanillaMaterials.TNT.onIgnite(block);
        return;
      } else {
        // Default fire creation
        Block target = block.translate(clickedface);

        // Default fire placement
        clickedface = clickedface.getOpposite();
        if (VanillaMaterials.FIRE.canPlace(target, (short) 0)) {
          if (VanillaMaterials.FIRE.onPlacement(target, (short) 0)) {
            PlayerQuickbar inv = entity.get(Human.class).getInventory().getQuickbar();
            inv.addData(inv.getCurrentSlot(), 1);
          }
        }

        // Handle the creation of portals
        if (VanillaMaterials.PORTAL.createPortal(target.translate(BlockFace.BOTTOM))) {
          return;
        }
      }
    }
  }
 /**
  * Gets the other half of a double chest
  *
  * @param block of the Double chest
  * @return the other half, or null if there is none
  */
 public Block getOtherHalf(Block block) {
   for (BlockFace face : BlockFaces.NESW) {
     if (block.translate(face).getMaterial().equals(this)) {
       return block.translate(face);
     }
   }
   return null;
 }
Example #9
0
 @Override
 public void setToggled(Block block, boolean toggled) {
   if (this.isToggled(block) != toggled) {
     block.setDataBits(0x8, toggled);
     GeneralEffects.BLOCK_PRESS.playGlobal(block.getPosition(), toggled);
   }
   block.resetDynamic();
 }
Example #10
0
 /**
  * Called when this liquid created a new liquid because it spread
  *
  * @param block of the Liquid that got created
  * @param from where it spread
  * @return True to notify spreading was allowed, False to deny
  */
 public void onSpread(Block block, int newLevel, BlockFace from) {
   block.getMaterial().destroy(block);
   block.setMaterial(this.getFlowingMaterial());
   this.setLevel(block, newLevel);
   if (from == BlockFace.TOP) {
     this.setFlowingDown(block, true);
   }
 }
Example #11
0
 @Override
 public boolean isValidPosition(Block block, BlockFace attachedFace, boolean seekAlternative) {
   if (super.isValidPosition(block, attachedFace, seekAlternative)) {
     final Block under = block.translate(BlockFace.BOTTOM);
     return under.isMaterial(VanillaMaterials.MYCELIUM)
         || block.getLight() <= 12 && under.getMaterial().isOpaque();
   }
   return false;
 }
Example #12
0
 @Override
 public boolean canDecayAt(Block block) {
   block = block.translate(BlockFace.TOP);
   BlockMaterial mat = block.getMaterial();
   if ((!(mat instanceof Snow)) || (!(mat.isMaterial(VanillaMaterials.SLAB)))) {
     return (block.getMaterial().getOpacity() > 0 && VanillaLighting.getLight(block) < 4);
   }
   return false;
 }
Example #13
0
 @EventHandler
 public void onSpoutEvent(PlayerInteractEvent event) {
   final Point point = event.getInteractedPoint();
   Block block =
       point
           .getWorld()
           .getBlock(point, (org.spout.api.plugin.Plugin) plugin.getFrameworkPlugin());
   event.getPlayer().sendMessage("Stop messing with that " + block.getMaterial() + "!");
 }
Example #14
0
 public void placeDoor(int xx, int yy, int zz, DoorBlock door, BlockFace facing) {
   final Block bottom = getBlock(xx, yy, zz);
   door.create(
       getBlock(xx, yy, zz),
       bottom.translate(BlockFace.TOP),
       BlockFace.fromYaw(facing.getDirection().getYaw() + rotation.getYaw()),
       false,
       false);
 }
Example #15
0
 public void fillDownwards(int xx, int yy, int zz, int limit, BlockMaterial material, short data) {
   short counter = 0;
   Block block;
   while (((block = getBlock(xx, yy, zz)).getMaterial().isMaterial(VanillaMaterials.AIR)
           || block.getMaterial() instanceof Liquid)
       && counter++ < limit) {
     block.setMaterial(material, data);
     yy--;
   }
 }
Example #16
0
 /**
  * Sets whether this Jukebox is playing or not
  *
  * @param playing
  */
 public void setPlaying(boolean playing) {
   Block block = this.getBlock();
   block.setData(
       playing
           ? 1
           : 0); // TODO hmmm? doesn't seem useful at all, since you don't know when the music
   // stops playing...
   Music music = playing ? this.getMusic() : Music.NONE;
   playBlockEffect(block, null, 48, PlayEffectMessage.Messages.MUSIC_DISC, music.getId());
 }
Example #17
0
 public void attachMaterial(int xx, int yy, int zz, Attachable attachable) {
   final Block block = getBlock(xx, yy, zz);
   for (BlockFace face : BlockFaces.BTNSWE) {
     final Block adjacent = block.translate(face);
     if (attachable.canAttachTo(adjacent, face.getOpposite())) {
       block.setMaterial((BlockMaterial) attachable);
       attachable.setAttachedFace(block, face, null);
     }
   }
 }
Example #18
0
  @Override
  public void onDynamicUpdate(Block block, long updateTime, int data) {
    if (block.translate(BlockFace.TOP).getLight() < this.getMinimumLightToGrow()) {
      block.dynamicUpdate(updateTime + getGrowthTime(block), true);
      return;
    }
    int chance = VanillaBlockMaterial.getCropGrowthChance(block) + 1;
    final Random rand = GenericMath.getRandom();
    if (rand.nextInt(chance) == 0) {
      if (isFullyGrown(block)) {
        for (int i = 0; i < BlockFaces.NESW.size(); i++) {
          Block spread = block.translate(BlockFaces.NESW.get(i));
          BlockMaterial material = spread.getMaterial();
          if (material == VanillaMaterials.AIR) {
            BlockMaterial belowSpread = spread.translate(BlockFace.BOTTOM).getMaterial();
            if (belowSpread.isMaterial(
                VanillaMaterials.FARMLAND, VanillaMaterials.DIRT, VanillaMaterials.GRASS)) {
              spread.setMaterial(this.getLastStageMaterial());
              break;
            }
          } else if (material == getLastStageMaterial()) {
            break;
          }
        }
      } else {
        block.addData(1);
      }
    }

    block.dynamicUpdate(updateTime + getGrowthTime(block), true);
  }
Example #19
0
 @Override
 public void onUpdate(BlockMaterial oldMaterial, Block block) {
   super.onUpdate(oldMaterial, block);
   boolean hasHook =
       VanillaMaterials.TRIPWIRE.findHook(block, getAttachedFace(block).getOpposite()) != null;
   if (!hasHook && !this.isToggled(block) && block.isDataBitSet(0x4)) {
     // play sound of wire snapping
     GeneralEffects.TRIPWIRE_SNAP.playGlobal(block.getPosition());
   }
   block.setDataBits(0x4, hasHook);
 }
Example #20
0
 @Override
 public boolean onPlacement(Block block, short data, BlockFace against, boolean isClickedBlock) {
   if (block.getMaterial().equals(this)) {
     block.setMaterial(this.doubletype).update();
   } else {
     block.setMaterial(this);
     this.setTop(block, against == BlockFace.TOP);
     block.update();
   }
   return true;
 }
Example #21
0
 @Override
 public ArrayList<ItemStack> getDrops(Block block) {
   ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
   if (block.getSource() instanceof Entity) {
     if (((Entity) block.getSource()).getInventory().getCurrentItem().getMaterial()
         instanceof Spade) {
       drops.add(new ItemStack(VanillaMaterials.SNOWBALL, 1));
     }
   }
   return drops;
 }
Example #22
0
 @Override
 public boolean canAttachTo(Block block, BlockFace face) {
   if (face == BlockFace.TOP) {
     if (this == DEAD_GRASS) {
       return block.isMaterial(VanillaMaterials.SAND);
     } else {
       return block.isMaterial(VanillaMaterials.GRASS, VanillaMaterials.DIRT);
     }
   }
   return false;
 }
Example #23
0
 public static boolean validToBuild(World world, Rectangle rect, Team team) {
   for (int x = (int) rect.getX(); x < rect.getX() + rect.getHeight(); x++) {
     for (int z = (int) rect.getY(); z < rect.getY() + rect.getHeight(); z++) {
       Block block = world.getBlock(x, DungeonGenerator.FLOOR_HEIGHT, z);
       if (!((DCMaterial) block.getMaterial()).isClaimedBy(block, team)
           || block.getMaterial() != DCMaterials.FLOOR) {
         return false;
       }
     }
   }
   return true;
 }
Example #24
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);
   }
 }
Example #25
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);
   }
 }
Example #26
0
 @Override
 public ArrayList<ItemStack> getDrops(Block block) {
   ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
   if (block.getSource() instanceof Entity) {
     ItemStack held = ((Entity) block.getSource()).getInventory().getCurrentItem();
     if (held != null
         && held.getMaterial()
             .equals(VanillaMaterials.IRON_PICKAXE, VanillaMaterials.DIAMOND_PICKAXE)) {
       drops.add(new ItemStack(this, 1));
     }
   }
   return drops;
 }
 /**
  * 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;
 }
Example #28
0
 private void finalizeSurface(World world, int x, int y, int z) {
   for (byte px = 0; px < 16; px++) {
     for (byte pz = 0; pz < 16; pz++) {
       for (byte py = -1; py < 4; py++) {
         final Block block = world.getBlock(x + px, y + py, z + pz, world);
         if (block.isAtSurface()) {
           final BlockMaterial material = block.getMaterial();
           if (material == VanillaMaterials.DIRT) {
             final BlockMaterial top;
             final Biome biome = block.getBiomeType();
             if (biome instanceof GrassyBiome) {
               top = ((GrassyBiome) biome).getTopCover();
             } else {
               top = VanillaMaterials.GRASS;
             }
             block.setMaterial(top);
           } else if (material == VanillaMaterials.STATIONARY_WATER
               && block.translate(0, 1, 0).isMaterial(VanillaMaterials.AIR)) {
             if (block.getBiomeType() instanceof IcyBiome) {
               block.setMaterial(VanillaMaterials.ICE);
             }
           }
         }
       }
     }
   }
 }
Example #29
0
 public MinecartTrackLogic getLogic(BlockFace direction) {
   Block block = this.block.translate(direction);
   MinecartTrackLogic logic;
   logic = create(block);
   if (logic != null) {
     return logic;
   }
   logic = create(block.translate(BlockFace.TOP));
   if (logic != null) {
     return logic;
   }
   logic = create(block.translate(BlockFace.BOTTOM));
   return logic;
 }
Example #30
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;
   }
 }