Search in sources :

Example 1 with BeehiveBlock

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

the class ShearsDispenserBehavior 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) {
        if (Config.ALLOW_SHEARS.get()) {
            int i = blockstate.getValue(BeehiveBlock.HONEY_LEVEL);
            if (i >= 5) {
                if (stack.hurt(1, world.random, null)) {
                    stack.setCount(0);
                }
                TieredBeehiveBlock.dropResourceHoneycomb((TieredBeehiveBlock) blockstate.getBlock(), world, blockpos, false);
                ((BeehiveBlock) blockstate.getBlock()).releaseBeesAndResetHoneyLevel(world, blockstate, blockpos, null, BeehiveBlockEntity.BeeReleaseStatus.BEE_RELEASED);
            }
        }
    } else {
        return getDefaultShearsDispenseBehavior().dispense(source, stack);
    }
    return stack;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock) TieredBeehiveBlock(com.teamresourceful.resourcefulbees.block.TieredBeehiveBlock) TieredBeehiveBlock(com.teamresourceful.resourcefulbees.block.TieredBeehiveBlock) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with BeehiveBlock

use of net.minecraft.world.level.block.BeehiveBlock in project Silent-Gear by SilentChaos512.

the class GearShearsItem method useOn.

@Override
public InteractionResult useOn(UseOnContext context) {
    Level world = context.getLevel();
    BlockPos pos = context.getClickedPos();
    BlockState state = world.getBlockState(pos);
    Player player = context.getPlayer();
    if (player != null && getHoneyLevel(state) >= 5) {
        world.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BEEHIVE_SHEAR, SoundSource.NEUTRAL, 1.0F, 1.0F);
        BeehiveBlock.dropHoneycomb(world, pos);
        context.getItemInHand().hurtAndBreak(1, player, (playerEntity) -> {
            playerEntity.broadcastBreakEvent(context.getHand());
        });
        BeehiveBlock block = (BeehiveBlock) state.getBlock();
        if (!CampfireBlock.isSmokeyPos(world, pos)) {
            if (block.hiveContainsBees(world, pos)) {
                block.angerNearbyBees(world, pos);
            }
            block.releaseBeesAndResetHoneyLevel(world, state, pos, player, BeehiveBlockEntity.BeeReleaseStatus.EMERGENCY);
        } else {
            block.resetHoneyLevel(world, state, pos);
        }
        return InteractionResult.sidedSuccess(world.isClientSide);
    }
    return GearHelper.onItemUse(context);
}
Also used : Player(net.minecraft.world.entity.player.Player) BlockState(net.minecraft.world.level.block.state.BlockState) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock)

Example 3 with BeehiveBlock

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

the class IMovedDispenseItemBehaviour method init.

static void init() {
    MovedProjectileDispenserBehaviour movedPotionDispenseItemBehaviour = new MovedProjectileDispenserBehaviour() {

        @Override
        protected Projectile getProjectileEntity(Level world, double x, double y, double z, ItemStack itemStack) {
            return Util.make(new ThrownPotion(world, x, y, z), (p_218411_1_) -> p_218411_1_.setItem(itemStack));
        }

        protected float getProjectileInaccuracy() {
            return super.getProjectileInaccuracy() * 0.5F;
        }

        protected float getProjectileVelocity() {
            return super.getProjectileVelocity() * .5F;
        }
    };
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.SPLASH_POTION, movedPotionDispenseItemBehaviour);
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.LINGERING_POTION, movedPotionDispenseItemBehaviour);
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.TNT, new MovedDefaultDispenseItemBehaviour() {

        @Override
        protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
            double x = pos.getX() + facing.x * .7 + .5;
            double y = pos.getY() + facing.y * .7 + .5;
            double z = pos.getZ() + facing.z * .7 + .5;
            PrimedTnt tntentity = new PrimedTnt(context.world, x, y, z, null);
            tntentity.push(context.motion.x, context.motion.y, context.motion.z);
            context.world.addFreshEntity(tntentity);
            context.world.playSound(null, tntentity.getX(), tntentity.getY(), tntentity.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
            itemStack.shrink(1);
            return itemStack;
        }
    });
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.FIREWORK_ROCKET, new MovedDefaultDispenseItemBehaviour() {

        @Override
        protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
            double x = pos.getX() + facing.x * .7 + .5;
            double y = pos.getY() + facing.y * .7 + .5;
            double z = pos.getZ() + facing.z * .7 + .5;
            FireworkRocketEntity fireworkrocketentity = new FireworkRocketEntity(context.world, itemStack, x, y, z, true);
            fireworkrocketentity.shoot(facing.x, facing.y, facing.z, 0.5F, 1.0F);
            context.world.addFreshEntity(fireworkrocketentity);
            itemStack.shrink(1);
            return itemStack;
        }

        @Override
        protected void playDispenseSound(LevelAccessor world, BlockPos pos) {
            world.levelEvent(1004, pos, 0);
        }
    });
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.FIRE_CHARGE, new MovedDefaultDispenseItemBehaviour() {

        @Override
        protected void playDispenseSound(LevelAccessor world, BlockPos pos) {
            world.levelEvent(1018, pos, 0);
        }

        @Override
        protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
            Random random = context.world.random;
            double x = pos.getX() + facing.x * .7 + .5;
            double y = pos.getY() + facing.y * .7 + .5;
            double z = pos.getZ() + facing.z * .7 + .5;
            context.world.addFreshEntity(Util.make(new SmallFireball(context.world, x, y, z, random.nextGaussian() * 0.05D + facing.x + context.motion.x, random.nextGaussian() * 0.05D + facing.y + context.motion.y, random.nextGaussian() * 0.05D + facing.z + context.motion.z), (p_229425_1_) -> p_229425_1_.setItem(itemStack)));
            itemStack.shrink(1);
            return itemStack;
        }
    });
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.GLASS_BOTTLE, new MovedOptionalDispenseBehaviour() {

        @Override
        protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
            this.successful = false;
            BlockPos interactAt = pos.relative(getClosestFacingDirection(facing));
            BlockState state = context.world.getBlockState(interactAt);
            Block block = state.getBlock();
            if (state.is(BlockTags.BEEHIVES) && state.getValue(BeehiveBlock.HONEY_LEVEL) >= 5) {
                ((BeehiveBlock) block).releaseBeesAndResetHoneyLevel(context.world, state, interactAt, null, BeehiveBlockEntity.BeeReleaseStatus.BEE_RELEASED);
                this.successful = true;
                return placeItemInInventory(itemStack, new ItemStack(Items.HONEY_BOTTLE), context, pos, facing);
            } else if (context.world.getFluidState(interactAt).is(FluidTags.WATER)) {
                this.successful = true;
                return placeItemInInventory(itemStack, PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER), context, pos, facing);
            } else {
                return super.dispenseStack(itemStack, context, pos, facing);
            }
        }
    });
    DispenserMovementBehaviour.registerMovedDispenseItemBehaviour(Items.BUCKET, new MovedDefaultDispenseItemBehaviour() {

        @Override
        protected ItemStack dispenseStack(ItemStack itemStack, MovementContext context, BlockPos pos, Vec3 facing) {
            BlockPos interactAt = pos.relative(getClosestFacingDirection(facing));
            BlockState state = context.world.getBlockState(interactAt);
            Block block = state.getBlock();
            if (block instanceof BucketPickup) {
                ItemStack bucket = ((BucketPickup) block).pickupBlock(context.world, interactAt, state);
                return placeItemInInventory(itemStack, bucket, context, pos, facing);
            }
            return super.dispenseStack(itemStack, context, pos, facing);
        }
    });
}
Also used : PrimedTnt(net.minecraft.world.entity.item.PrimedTnt) LevelAccessor(net.minecraft.world.level.LevelAccessor) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) BucketPickup(net.minecraft.world.level.block.BucketPickup) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) Vec3(net.minecraft.world.phys.Vec3) ThrownPotion(net.minecraft.world.entity.projectile.ThrownPotion) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock) Block(net.minecraft.world.level.block.Block) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) SmallFireball(net.minecraft.world.entity.projectile.SmallFireball) ItemStack(net.minecraft.world.item.ItemStack) MovementContext(com.simibubi.create.content.contraptions.components.structureMovement.MovementContext)

Example 4 with BeehiveBlock

use of net.minecraft.world.level.block.BeehiveBlock in project Cyclic by Lothrazar.

the class ShearsMaterial method useOn.

@Override
public InteractionResult useOn(UseOnContext context) {
    BlockPos blockPos = context.getClickedPos();
    BlockState blockState = context.getLevel().getBlockState(blockPos);
    Level worldIn = context.getLevel();
    Player player = context.getPlayer();
    if (blockState.getBlock() instanceof BeehiveBlock && blockState.getValue(BeehiveBlock.HONEY_LEVEL) >= 5) {
        // replicate the behavior of BeehiveBlock#onBlockActivated
        worldIn.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BEEHIVE_SHEAR, SoundSource.NEUTRAL, 1.0F, 1.0F);
        BeehiveBlock.dropHoneycomb(worldIn, blockPos);
        worldIn.setBlockAndUpdate(blockPos, blockState.setValue(BeehiveBlock.HONEY_LEVEL, 0));
        UtilItemStack.damageItem(player, context.getItemInHand());
        return InteractionResult.SUCCESS;
    }
    return super.useOn(context);
}
Also used : Player(net.minecraft.world.entity.player.Player) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock)

Example 5 with BeehiveBlock

use of net.minecraft.world.level.block.BeehiveBlock in project AlexsMobs by Alex-the-666.

the class GrizzlyBearAIBeehive method eatHive.

private void eatHive() {
    if (net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(bear.level, bear)) {
        BlockState blockstate = bear.level.getBlockState(this.blockPos);
        if (blockstate.is(AMTagRegistry.GRIZZLY_BEEHIVE)) {
            if (bear.level.getBlockEntity(this.blockPos) instanceof BeehiveBlockEntity) {
                Random rand = new Random();
                BeehiveBlockEntity beehivetileentity = (BeehiveBlockEntity) bear.level.getBlockEntity(this.blockPos);
                beehivetileentity.emptyAllLivingFromHive(null, blockstate, BeehiveBlockEntity.BeeReleaseStatus.EMERGENCY);
                bear.level.updateNeighbourForOutputSignal(this.blockPos, blockstate.getBlock());
                ItemStack stack = new ItemStack(Items.HONEYCOMB);
                int level = 0;
                if (blockstate.getBlock() instanceof BeehiveBlock) {
                    level = blockstate.getValue(BeehiveBlock.HONEY_LEVEL);
                }
                for (int i = 0; i < level; i++) {
                    ItemEntity itementity = new ItemEntity(bear.level, blockPos.getX() + rand.nextFloat(), blockPos.getY() + rand.nextFloat(), blockPos.getZ() + rand.nextFloat(), stack);
                    itementity.setDefaultPickUpDelay();
                    bear.level.addFreshEntity(itementity);
                }
                bear.level.destroyBlock(blockPos, false);
                if (blockstate.getBlock() instanceof BeehiveBlock) {
                    bear.level.setBlockAndUpdate(blockPos, blockstate.setValue(BeehiveBlock.HONEY_LEVEL, 0));
                }
                double d0 = 15;
                for (Bee bee : bear.level.getEntitiesOfClass(Bee.class, new AABB((double) blockPos.getX() - d0, (double) blockPos.getY() - d0, (double) blockPos.getZ() - d0, (double) blockPos.getX() + d0, (double) blockPos.getY() + d0, (double) blockPos.getZ() + d0))) {
                    bee.setRemainingPersistentAngerTime(100);
                    bee.setTarget(bear);
                    bee.setStayOutOfHiveCountdown(400);
                }
                stop();
            }
        }
    }
}
Also used : ItemEntity(net.minecraft.world.entity.item.ItemEntity) BlockState(net.minecraft.world.level.block.state.BlockState) Bee(net.minecraft.world.entity.animal.Bee) Random(java.util.Random) ItemStack(net.minecraft.world.item.ItemStack) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock) AABB(net.minecraft.world.phys.AABB)

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