Example #1
0
  @Override
  public void onInteract(Entity entity, Action type) {
    super.onInteract(entity, type);
    if (type == Action.RIGHT_CLICK && entity.has(HeadComponent.class)) {
      BlockIterator iterator = entity.get(HeadComponent.class).getBlockView();
      if (iterator == null || !iterator.hasNext()) {
        return;
      }
      Block block = iterator.next().translate(BlockFace.TOP);
      if (this.canPlace(block, (short) 0)) {
        Cause<Entity> cause;
        if (entity instanceof Player) {
          cause = new PlayerBreakCause((Player) entity, block);
        } else {
          cause = new EntityCause(entity);
        }
        this.onPlacement(block, (short) 0, cause);

        // TODO Subtract from inventory component
        // Subtract item
        if (!entity.getData().get(VanillaData.GAMEMODE).equals(GameMode.SURVIVAL)) {
          return;
        }
        PlayerQuickbar inv = entity.get(PlayerInventory.class).getQuickbar();
        if (inv != null) {
          inv.addAmount(inv.getCurrentSlot(), -1);
        }
      }
    }
  }
Example #2
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 #3
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);
     }
   }
 }
Example #4
0
 @Override
 public void initialize() {
   super.initialize();
   this.setHardness(0.1F).setResistance(0.2F).setOpacity((byte) 1);
 }