Search in sources :

Example 6 with BeehiveBlock

use of net.minecraft.world.level.block.BeehiveBlock in project ResourcefulBees by Resourceful-Bees.

the class ApiaryUpgradeRecipe method getRemainingItems.

@Override
@NotNull
public NonNullList<ItemStack> getRemainingItems(@NotNull CraftingContainer inventory) {
    NonNullList<ItemStack> remainingItems = super.getRemainingItems(inventory);
    for (int i = 0; i < inventory.getContainerSize(); i++) {
        ItemStack item = inventory.getItem(i);
        Block block = Block.byItem(item.getItem());
        if (block instanceof ApiaryBlock || block instanceof BeehiveBlock) {
            ItemStack box = getBeeBoxFromHive(item);
            if (box == null)
                continue;
            remainingItems.set(i, box);
        }
    }
    return remainingItems;
}
Also used : ApiaryBlock(com.teamresourceful.resourcefulbees.block.multiblocks.apiary.ApiaryBlock) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock) ApiaryBlock(com.teamresourceful.resourcefulbees.block.multiblocks.apiary.ApiaryBlock) Block(net.minecraft.world.level.block.Block) ItemStack(net.minecraft.world.item.ItemStack) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with BeehiveBlock

use of net.minecraft.world.level.block.BeehiveBlock in project ResourcefulBees by Resourceful-Bees.

the class ScraperDispenserBehavior method execute.

@NotNull
@Override
protected ItemStack execute(@NotNull BlockSource source, @NotNull ItemStack stack) {
    ServerLevel world = source.getLevel();
    BlockPos blockpos = source.getPos().relative(source.getBlockState().getValue(DispenserBlock.FACING));
    BlockState blockstate = world.getBlockState(blockpos);
    if (blockstate.getBlock() instanceof TieredBeehiveBlock) {
        int i = blockstate.getValue(BeehiveBlock.HONEY_LEVEL);
        if (i >= 5) {
            if (stack.hurt(1, world.random, null)) {
                stack.setCount(0);
            }
            if (TieredBeehiveBlock.dropResourceHoneycomb((TieredBeehiveBlock) blockstate.getBlock(), world, blockpos, true)) {
                ((BeehiveBlock) blockstate.getBlock()).releaseBeesAndResetHoneyLevel(world, blockstate, blockpos, null, BeehiveBlockEntity.BeeReleaseStatus.BEE_RELEASED);
            }
        }
    }
    return stack;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) TieredBeehiveBlock(com.teamresourceful.resourcefulbees.block.TieredBeehiveBlock) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock) TieredBeehiveBlock(com.teamresourceful.resourcefulbees.block.TieredBeehiveBlock) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with BeehiveBlock

use of net.minecraft.world.level.block.BeehiveBlock in project Create by Creators-of-Create.

the class DeployerHandler method safeOnBeehiveUse.

protected static InteractionResult safeOnBeehiveUse(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand) {
    // <> BeehiveBlock#onUse
    BeehiveBlock block = (BeehiveBlock) state.getBlock();
    ItemStack prevHeldItem = player.getItemInHand(hand);
    int honeyLevel = state.getValue(BeehiveBlock.HONEY_LEVEL);
    boolean success = false;
    if (honeyLevel < 5)
        return InteractionResult.PASS;
    if (prevHeldItem.getItem() == Items.SHEARS) {
        world.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BEEHIVE_SHEAR, SoundSource.NEUTRAL, 1.0F, 1.0F);
        // <> BeehiveBlock#dropHoneycomb
        player.getInventory().placeItemBackInInventory(new ItemStack(Items.HONEYCOMB, 3));
        prevHeldItem.hurtAndBreak(1, player, s -> s.broadcastBreakEvent(hand));
        success = true;
    }
    if (prevHeldItem.getItem() == Items.GLASS_BOTTLE) {
        prevHeldItem.shrink(1);
        world.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BOTTLE_FILL, SoundSource.NEUTRAL, 1.0F, 1.0F);
        ItemStack honeyBottle = new ItemStack(Items.HONEY_BOTTLE);
        if (prevHeldItem.isEmpty())
            player.setItemInHand(hand, honeyBottle);
        else
            player.getInventory().placeItemBackInInventory(honeyBottle);
        success = true;
    }
    if (!success)
        return InteractionResult.PASS;
    block.resetHoneyLevel(world, state, pos);
    return InteractionResult.SUCCESS;
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock)

Aggregations

BeehiveBlock (net.minecraft.world.level.block.BeehiveBlock)8 BlockState (net.minecraft.world.level.block.state.BlockState)6 BlockPos (net.minecraft.core.BlockPos)5 ItemStack (net.minecraft.world.item.ItemStack)4 ServerLevel (net.minecraft.server.level.ServerLevel)3 Level (net.minecraft.world.level.Level)3 NotNull (org.jetbrains.annotations.NotNull)3 TieredBeehiveBlock (com.teamresourceful.resourcefulbees.block.TieredBeehiveBlock)2 Random (java.util.Random)2 Player (net.minecraft.world.entity.player.Player)2 Block (net.minecraft.world.level.block.Block)2 MovementContext (com.simibubi.create.content.contraptions.components.structureMovement.MovementContext)1 ApiaryBlock (com.teamresourceful.resourcefulbees.block.multiblocks.apiary.ApiaryBlock)1 Bee (net.minecraft.world.entity.animal.Bee)1 ItemEntity (net.minecraft.world.entity.item.ItemEntity)1 PrimedTnt (net.minecraft.world.entity.item.PrimedTnt)1 FireworkRocketEntity (net.minecraft.world.entity.projectile.FireworkRocketEntity)1 SmallFireball (net.minecraft.world.entity.projectile.SmallFireball)1 ThrownPotion (net.minecraft.world.entity.projectile.ThrownPotion)1 LevelAccessor (net.minecraft.world.level.LevelAccessor)1