Search in sources :

Example 1 with BeehiveBlockEntity

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

the class HoneyDipper method useOn.

@Override
@NotNull
public InteractionResult useOn(@NotNull UseOnContext useContext) {
    if (!useContext.getLevel().isClientSide()) {
        Block clickedBlock = useContext.getLevel().getBlockState(useContext.getClickedPos()).getBlock();
        if (selectedBee instanceof CustomBeeEntity) {
            CoreData beeData = ((CustomBeeEntity) selectedBee).getCoreData();
            if (!beeData.getBlockFlowers().isEmpty() && beeData.getBlockFlowers().contains(clickedBlock)) {
                setFlowerPosition(useContext);
                return InteractionResult.SUCCESS;
            }
        } else if (selectedBee != null && clickedBlock.is(BlockTags.FLOWERS)) {
            setFlowerPosition(useContext);
            return InteractionResult.SUCCESS;
        }
        BlockEntity clickedTile = useContext.getLevel().getBlockEntity(useContext.getClickedPos());
        if (selectedBee != null && (clickedTile instanceof BeehiveBlockEntity || clickedTile instanceof ApiaryTileEntity)) {
            selectedBee.hivePos = useContext.getClickedPos();
            sendMessageToPlayer(useContext.getPlayer(), MessageTypes.HIVE, useContext.getClickedPos());
            selectedBee = null;
            return InteractionResult.SUCCESS;
        }
    }
    return super.useOn(useContext);
}
Also used : CustomBeeEntity(com.teamresourceful.resourcefulbees.entity.passive.CustomBeeEntity) CoreData(com.teamresourceful.resourcefulbees.api.beedata.CoreData) ApiaryTileEntity(com.teamresourceful.resourcefulbees.tileentity.multiblocks.apiary.ApiaryTileEntity) Block(net.minecraft.world.level.block.Block) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with BeehiveBlockEntity

use of net.minecraft.world.level.block.entity.BeehiveBlockEntity 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)

Example 3 with BeehiveBlockEntity

use of net.minecraft.world.level.block.entity.BeehiveBlockEntity in project BYG by AOCAWOL.

the class BeeHiveFeature method place.

public boolean place(WorldGenLevel world, ChunkGenerator generator, Random rand, BlockPos pos, NoneFeatureConfiguration config) {
    if (world.isEmptyBlock(pos) && world.isEmptyBlock(pos.below())) {
        if (world.getBlockState(pos.above()).is(BlockTags.LEAVES) || world.getBlockState(pos.above()).is(BlockTags.LOGS) || world.getBlockState(pos.above()).is(BYGBlocks.EMBUR_GEL_BLOCK)) {
            Direction direction;
            if (world.isEmptyBlock(pos.north()))
                direction = Direction.NORTH;
            else if (world.isEmptyBlock(pos.south()))
                direction = Direction.SOUTH;
            else if (world.isEmptyBlock(pos.west()))
                direction = Direction.WEST;
            else
                direction = Direction.EAST;
            BlockState beeHiveState = Blocks.BEE_NEST.defaultBlockState().setValue(BeehiveBlock.FACING, direction);
            world.setBlock(pos, beeHiveState, 2);
            BlockEntity tileEntity = world.getBlockEntity(pos);
            if (tileEntity instanceof BeehiveBlockEntity) {
                BeehiveBlockEntity beehiveTileEntity = (BeehiveBlockEntity) tileEntity;
                int beeCount = rand.nextInt(4);
                for (int bee = 0; bee <= beeCount; bee++) {
                    Bee beeEntity = new Bee(EntityType.BEE, world.getLevel());
                    beehiveTileEntity.addOccupantWithPresetTicks(beeEntity, false, rand.nextInt(599));
                }
            }
            return true;
        }
    }
    return false;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Bee(net.minecraft.world.entity.animal.Bee) Direction(net.minecraft.core.Direction) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity)

Example 4 with BeehiveBlockEntity

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

the class MixinEnterBeehiveGoal method start.

/**
 * @author epic_oreo
 * @reason crashes when switching to vanilla code due to hivePos being null. retained vanilla checks in overwrite.
 */
@Overwrite()
public void start() {
    if (beeEntity.hivePos != null) {
        BlockEntity tileentity = beeEntity.level.getBlockEntity(beeEntity.hivePos);
        if (tileentity != null) {
            if (tileentity instanceof BeehiveBlockEntity) {
                BeehiveBlockEntity beehivetileentity = (BeehiveBlockEntity) tileentity;
                beehivetileentity.addOccupant(beeEntity, beeEntity.hasNectar());
            } else if (tileentity instanceof ApiaryTileEntity) {
                ApiaryTileEntity apiaryTileEntity = (ApiaryTileEntity) tileentity;
                apiaryTileEntity.tryEnterHive(beeEntity, beeEntity.hasNectar(), false);
            }
        }
    }
}
Also used : ApiaryTileEntity(com.teamresourceful.resourcefulbees.tileentity.multiblocks.apiary.ApiaryTileEntity) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 5 with BeehiveBlockEntity

use of net.minecraft.world.level.block.entity.BeehiveBlockEntity in project Mohist by MohistMC.

the class CraftBeehive method releaseEntities.

@Override
public List<Bee> releaseEntities() {
    ensureNoWorldGeneration();
    List<Bee> bees = new ArrayList<>();
    if (isPlaced()) {
        BeehiveBlockEntity beehive = ((BeehiveBlockEntity) this.getTileEntityFromWorld());
        for (Entity bee : beehive.releaseBees(this.getHandle(), BeehiveBlockEntity.BeeReleaseStatus.BEE_RELEASED, true)) {
            bees.add((Bee) bee.getBukkitEntity());
        }
    }
    return bees;
}
Also used : Entity(net.minecraft.world.entity.Entity) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) CraftBee(org.bukkit.craftbukkit.v1_18_R2.entity.CraftBee) Bee(org.bukkit.entity.Bee) ArrayList(java.util.ArrayList) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity)

Aggregations

BeehiveBlockEntity (net.minecraft.world.level.block.entity.BeehiveBlockEntity)6 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)4 Bee (net.minecraft.world.entity.animal.Bee)3 ApiaryTileEntity (com.teamresourceful.resourcefulbees.tileentity.multiblocks.apiary.ApiaryTileEntity)2 Random (java.util.Random)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 CoreData (com.teamresourceful.resourcefulbees.api.beedata.CoreData)1 CustomBeeEntity (com.teamresourceful.resourcefulbees.entity.passive.CustomBeeEntity)1 ArrayList (java.util.ArrayList)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 Entity (net.minecraft.world.entity.Entity)1 ItemEntity (net.minecraft.world.entity.item.ItemEntity)1 ItemStack (net.minecraft.world.item.ItemStack)1 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)1 BeehiveBlock (net.minecraft.world.level.block.BeehiveBlock)1 Block (net.minecraft.world.level.block.Block)1 AABB (net.minecraft.world.phys.AABB)1 CraftBee (org.bukkit.craftbukkit.v1_18_R2.entity.CraftBee)1 Bee (org.bukkit.entity.Bee)1