コード例 #1
0
ファイル: FlintAndSteel.java プロジェクト: Karang/Vanilla
  @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);
      }
    }
  }
コード例 #2
0
ファイル: Mushroom.java プロジェクト: stewbasic/Vanilla
 @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);
     }
   }
 }
コード例 #3
0
ファイル: EnderPearlItem.java プロジェクト: Sleaker/Vanilla
 @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
ファイル: Stem.java プロジェクト: stewbasic/Vanilla
 @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
ファイル: AbstractWindow.java プロジェクト: Sleaker/Vanilla
  /** Reloads the window's items */
  @ServerOnly
  public final void reload() {
    if (Spout.getPlatform() == Platform.CLIENT) {
      throw new IllegalStateException("Cannot reload window in client mode.");
    }

    ItemStack[] items = new ItemStack[getSize()];
    for (int i = 0; i < items.length; i++) {
      Slot entry = getSlot(i);
      if (entry != null) {
        items[i] = entry.get();
      }
    }

    callProtocolEvent(new WindowItemsEvent(this, items));
  }
コード例 #6
0
ファイル: Potion.java プロジェクト: Karang/Vanilla
  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));
  }
コード例 #7
0
ファイル: Grass.java プロジェクト: joansmith/Vanilla
  @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);
              }
            }
          }
        }
      }
    }
  }