All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.item.ItemGlassBottle Maven / Gradle / Ivy

There is a newer version: 1.20.40-r1
Show newest version
package cn.nukkit.item;


import cn.nukkit.Player;
import cn.nukkit.block.Block;
import cn.nukkit.block.BlockBeehive;
import cn.nukkit.level.Level;
import cn.nukkit.level.Sound;
import cn.nukkit.level.vibration.VibrationEvent;
import cn.nukkit.level.vibration.VibrationType;
import cn.nukkit.math.BlockFace;

public class ItemGlassBottle extends Item {

    public ItemGlassBottle() {
        this(0, 1);
    }

    public ItemGlassBottle(Integer meta) {
        this(meta, 1);
    }

    public ItemGlassBottle(Integer meta, int count) {
        super(GLASS_BOTTLE, meta, count, "Glass Bottle");
    }

    @Override
    public boolean canBeActivated() {
        return true;
    }

    @Override
    public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
        Item filled = null;
        if (target.getId() == FLOWING_WATER || target.getId() == STILL_WATER) {
            filled = new ItemPotion();
        } else if (target instanceof BlockBeehive && ((BlockBeehive) target).isFull()) {
            filled = Item.get(HONEY_BOTTLE);
            ((BlockBeehive) target).honeyCollected(player);
            level.addSound(player, Sound.BUCKET_FILL_WATER);
        }
        
        if (filled != null) {
            if (this.count == 1) {
                player.getInventory().setItemInHand(filled);
            } else if (this.count > 1) {
                this.count--;
                player.getInventory().setItemInHand(this);
                if (player.getInventory().canAddItem(filled)) {
                    player.getInventory().addItem(filled);
                } else {
                    player.getLevel().dropItem(player.add(0, 1.3, 0), filled, player.getDirectionVector().multiply(0.4));
                }
            }
            
            level.getVibrationManager().callVibrationEvent(new VibrationEvent(player, target.add(0.5, 0.5, 0.5), VibrationType.FLUID_PICKUP));
        }
        
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy