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

cn.nukkit.dispenser.ShulkerBoxDispenseBehavior Maven / Gradle / Ivy

Go to download

A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.

There is a newer version: 1.6.0.1-PN
Show newest version
package cn.nukkit.dispenser;

import cn.nukkit.block.Block;
import cn.nukkit.block.BlockDispenser;
import cn.nukkit.block.BlockID;
import cn.nukkit.block.BlockShulkerBox;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.item.Item;
import cn.nukkit.math.BlockFace;
import cn.nukkit.nbt.tag.CompoundTag;

public class ShulkerBoxDispenseBehavior extends DefaultDispenseBehavior {

    @Override
    public Item dispense(BlockDispenser block, BlockFace face, Item item) {
        Block shulkerBox = new BlockShulkerBox();
        Block target = block.getSide(face);

        this.success = block.level.getCollidingEntities(shulkerBox.getBoundingBox()).length == 0;

        if (this.success) {
            BlockFace shulkerBoxFace = target.down().getId() == BlockID.AIR ? face : BlockFace.UP;

            CompoundTag nbt = BlockEntity.getDefaultCompound(target, BlockEntity.SHULKER_BOX);
            nbt.putByte("facing", shulkerBoxFace.getIndex());

            if (item.hasCustomName()) {
                nbt.putString("CustomName", item.getCustomName());
            }

            CompoundTag tag = item.getNamedTag();

            if (tag != null) {
                if (tag.contains("Items")) {
                    nbt.putList(tag.getList("Items"));
                }
            }

            BlockEntity.createBlockEntity(BlockEntity.SHULKER_BOX, target, nbt);
            block.level.updateComparatorOutputLevel(target);
        }

        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy