示例#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 void onDrink(Entity entity, Slot slot) {
    if (this.effect != null) {
      entity
          .add(EffectsComponent.class)
          .addEffect(new StatusEffectContainer(effect, this.getTime(), this.getTier()));
    }

    slot.addAmount(-1);
    entity
        .get(PlayerInventory.class)
        .getMain()
        .add(new ItemStack(VanillaMaterials.GLASS_BOTTLE, 1));
  }
示例#3
0
 @Override
 public void onInteract(Entity entity, Action type) {
   super.onInteract(entity, type, 10f);
   if (type == Action.RIGHT_CLICK) {
     Slot slot = PlayerUtil.getHeldSlot(entity);
     if (!PlayerUtil.isCostSuppressed(entity)
         && slot != null
         && slot.get() != null
         && VanillaMaterials.ENDER_PEARL.equals(slot.get().getMaterial())) {
       slot.addAmount(-1);
     }
   }
 }
示例#4
0
 @Override
 public void onInteractBy(
     Entity entity, Block block, PlayerInteractEvent.Action type, BlockFace clickedFace) {
   super.onInteractBy(entity, block, type, clickedFace);
   Slot inv = PlayerUtil.getHeldSlot(entity);
   if (inv != null && inv.get() != null && inv.get().isMaterial(Dye.BONE_MEAL)) {
     if (this.getGrowthStage(block) != 0x7) {
       if (!PlayerUtil.isCostSuppressed(entity)) {
         inv.addAmount(-1);
       }
       this.setGrowthStage(block, 0x7);
     }
   }
 }
示例#5
0
  @Override
  public void onInteractBy(Entity entity, Block block, Action type, BlockFace clickedFace) {
    super.onInteractBy(entity, block, type, clickedFace);
    Slot inv = PlayerUtil.getHeldSlot(entity);

    if (inv != null
        && inv.get() != null
        && inv.get().isMaterial(Dye.BONE_MEAL)
        && type.equals(Action.RIGHT_CLICK)) {
      if (!PlayerUtil.isCostSuppressed(entity)) {
        inv.addAmount(-1);
      }
      final Random random = GenericMath.getRandom();
      // Minecraft does grass growing by Bone Meal as follows. Keep in mind the radius is 8.
      // - Tall Grass is placed 9/10 times.
      // - If Tall Grass fails, place Dandelion 2/3 times (within the 1/10 window Tall Grass failed
      // on)
      // - If Dandelion fails, place Rose within the 1/3 times window that Dandelion failed (which
      // is within the 1/10 window Tall Grass failed on).
      for (int dx = -4; dx < 4; dx++) {
        for (int dy = -1; dy <= 1; dy++) {
          for (int dz = -4; dz < 4; dz++) {
            // Fertilization only occurs 1/3 times.
            if (random.nextInt(3) != 2) {
              continue;
            }
            // Grass/flowers have lower chance to go to a lower/higher height than the center block
            // is at.
            // It incurs another 1/3 times. Only do this when iterating over -1 or 1 on the dy,
            // otherwise its on the same
            // plane and we don't care.
            if (dy != 0) {
              if (random.nextInt(3) != 2) {
                continue;
              }
            }

            final Block around = block.translate(dx, dy, dz);

            // Only spread to Grass blocks
            if (!around.getMaterial().equals(VanillaMaterials.GRASS)) {
              continue;
            }

            final Block aboveAround = around.translate(BlockFace.TOP);

            // Make sure the block above the translated one is Air.
            if (!aboveAround.getMaterial().equals(VanillaMaterials.AIR)) {
              continue;
            }

            if (random.nextInt(10) != 0) {
              if (VanillaMaterials.TALL_GRASS.canAttachTo(around, BlockFace.TOP)) {
                aboveAround.setMaterial(VanillaMaterials.TALL_GRASS);
              }
            } else if (random.nextInt(3) != 0) {
              if (VanillaMaterials.DANDELION.canAttachTo(around, BlockFace.TOP)) {
                aboveAround.setMaterial(VanillaMaterials.DANDELION);
              }
            } else {
              if (VanillaMaterials.ROSE.canAttachTo(around, BlockFace.TOP)) {
                aboveAround.setMaterial(VanillaMaterials.ROSE);
              }
            }
          }
        }
      }
    }
  }