Search in sources :

Example 1 with Bee

use of net.minecraft.world.entity.animal.Bee in project ResourcefulBees by Resourceful-Bees.

the class BeeJar method fillJar.

@OnlyIn(Dist.CLIENT)
public static void fillJar(ItemStack stack, CustomBeeData beeData) {
    EntityType<?> entityType = beeData.getEntityType();
    Level world = Minecraft.getInstance().level;
    if (world == null)
        return;
    Entity entity = entityType.create(world);
    if (entity != null) {
        stack.setTag(BeeInfoUtils.createJarBeeTag((Bee) entity, NBTConstants.NBT_ENTITY));
        renameJar(stack, (Bee) entity);
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) CustomBeeEntity(com.teamresourceful.resourcefulbees.entity.passive.CustomBeeEntity) Entity(net.minecraft.world.entity.Entity) ResourcefulBee(com.teamresourceful.resourcefulbees.entity.passive.ResourcefulBee) Bee(net.minecraft.world.entity.animal.Bee) Level(net.minecraft.world.level.Level) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 2 with Bee

use of net.minecraft.world.entity.animal.Bee in project ResourcefulBees by Resourceful-Bees.

the class Smoker method use.

@Override
@NotNull
public InteractionResultHolder<ItemStack> use(Level world, @NotNull Player player, @NotNull InteractionHand hand) {
    if (!world.isClientSide) {
        int damage = player.getItemInHand(hand).getDamageValue();
        int maxDamage = player.getItemInHand(hand).getMaxDamage();
        if (flag == 1 && damage < maxDamage) {
            player.getItemInHand(hand).hurtAndBreak(1, player, player1 -> player1.broadcastBreakEvent(hand));
            flag = 0;
        } else {
            flag++;
        }
        Vec3 vec3d = player.getLookAngle();
        double x = player.getX() + vec3d.x * 2;
        double y = player.getY() + vec3d.y * 2;
        double z = player.getZ() + vec3d.z * 2;
        AABB axisalignedbb = new AABB((player.getX() + vec3d.x) - 2.5D, (player.getY() + vec3d.y) - 2D, (player.getZ() + vec3d.z) - 2.5D, (player.getX() + vec3d.x) + 2.5D, (player.getY() + vec3d.y) + 2D, (player.getZ() + vec3d.z) + 2.5D);
        List<Mob> list = world.getLoadedEntitiesOfClass(Bee.class, axisalignedbb);
        list.stream().filter(mobEntity -> mobEntity instanceof Bee && ((Bee) mobEntity).isAngry()).forEach(mobEntity -> {
            ((Bee) mobEntity).setRemainingPersistentAngerTime(0);
            mobEntity.setLastHurtByMob(null);
        });
        ServerLevel worldServer = (ServerLevel) world;
        worldServer.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y + 1.3D, z, 50, 0, 0, 0, 0.01F);
    }
    return super.use(world, player, hand);
}
Also used : Config(com.teamresourceful.resourcefulbees.config.Config) AABB(net.minecraft.world.phys.AABB) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) InteractionResultHolder(net.minecraft.world.InteractionResultHolder) Item(net.minecraft.world.item.Item) ServerLevel(net.minecraft.server.level.ServerLevel) Dist(net.minecraftforge.api.distmarker.Dist) TieredBeehiveTileEntity(com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity) I18n(net.minecraft.client.resources.language.I18n) ChatFormatting(net.minecraft.ChatFormatting) UseOnContext(net.minecraft.world.item.context.UseOnContext) Component(net.minecraft.network.chat.Component) Screen(net.minecraft.client.gui.screens.Screen) InteractionResult(net.minecraft.world.InteractionResult) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Player(net.minecraft.world.entity.player.Player) Nullable(org.jetbrains.annotations.Nullable) TextComponent(net.minecraft.network.chat.TextComponent) List(java.util.List) BlockPos(net.minecraft.core.BlockPos) Vec3(net.minecraft.world.phys.Vec3) Bee(net.minecraft.world.entity.animal.Bee) TooltipFlag(net.minecraft.world.item.TooltipFlag) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) Mob(net.minecraft.world.entity.Mob) Level(net.minecraft.world.level.Level) NotNull(org.jetbrains.annotations.NotNull) ParticleTypes(net.minecraft.core.particles.ParticleTypes) Mob(net.minecraft.world.entity.Mob) ServerLevel(net.minecraft.server.level.ServerLevel) Bee(net.minecraft.world.entity.animal.Bee) Vec3(net.minecraft.world.phys.Vec3) AABB(net.minecraft.world.phys.AABB) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Bee

use of net.minecraft.world.entity.animal.Bee in project ResourcefulBees by Resourceful-Bees.

the class BeeBox method interactLivingEntity.

@NotNull
@Override
public InteractionResult interactLivingEntity(@NotNull ItemStack stack, @NotNull Player player, LivingEntity targetIn, @NotNull InteractionHand hand) {
    if (targetIn.getCommandSenderWorld().isClientSide() || (!(targetIn instanceof Bee) || !targetIn.isAlive())) {
        return InteractionResult.FAIL;
    }
    if (isTemp)
        return InteractionResult.FAIL;
    Bee target = (Bee) targetIn;
    CompoundTag tag = stack.getTag() == null ? new CompoundTag() : stack.getTag();
    ListTag bees = tag.contains(NBTConstants.NBT_BEES) ? tag.getList(NBTConstants.NBT_BEES, 10) : new ListTag();
    if (bees.size() == BeeConstants.MAX_BEES_BEE_BOX)
        return InteractionResult.FAIL;
    CompoundTag entityData = new CompoundTag();
    entityData.put(NBTConstants.ENTITY_DATA, BeeInfoUtils.createJarBeeTag(target, NBTConstants.NBT_ID));
    bees.add(entityData);
    tag.put(NBTConstants.NBT_BEES, bees);
    stack.setTag(tag);
    player.setItemInHand(hand, stack);
    player.swing(hand);
    target.remove(true);
    return InteractionResult.PASS;
}
Also used : Bee(net.minecraft.world.entity.animal.Bee) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Bee

use of net.minecraft.world.entity.animal.Bee in project ResourcefulBees by Resourceful-Bees.

the class BeeJar method useOn.

@NotNull
@Override
public InteractionResult useOn(UseOnContext context) {
    Player player = context.getPlayer();
    if (player != null) {
        Level playerWorld = context.getPlayer().getCommandSenderWorld();
        ItemStack stack = context.getItemInHand();
        if (playerWorld.isClientSide() || !isFilled(stack))
            return InteractionResult.FAIL;
        Level worldIn = context.getLevel();
        BlockPos pos = context.getClickedPos();
        Entity entity = getEntityFromStack(stack, worldIn, true);
        if (entity != null) {
            if (entity instanceof Bee) {
                Bee beeEntity = (Bee) entity;
                resetBee(beeEntity);
                setBeeAngry(beeEntity, player);
            }
            BlockPos blockPos = pos.relative(context.getClickedFace());
            entity.absMoveTo(blockPos.getX() + 0.5, blockPos.getY(), blockPos.getZ() + 0.5, 0, 0);
            worldIn.addFreshEntity(entity);
        }
        stack.setTag(null);
        return InteractionResult.SUCCESS;
    }
    return InteractionResult.FAIL;
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) CustomBeeEntity(com.teamresourceful.resourcefulbees.entity.passive.CustomBeeEntity) Entity(net.minecraft.world.entity.Entity) Player(net.minecraft.world.entity.player.Player) ResourcefulBee(com.teamresourceful.resourcefulbees.entity.passive.ResourcefulBee) Bee(net.minecraft.world.entity.animal.Bee) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Bee

use of net.minecraft.world.entity.animal.Bee in project ResourcefulBees by Resourceful-Bees.

the class TieredBeehiveTileEntity method addOccupantWithPresetTicks.

@Override
public void addOccupantWithPresetTicks(@NotNull Entity bee, boolean hasNectar, int ticksInHive) {
    if (this.stored.size() < getMaxBees()) {
        bee.ejectPassengers();
        CompoundTag nbt = new CompoundTag();
        bee.save(nbt);
        if (this.level != null && bee instanceof Bee) {
            int maxTimeInHive = getMaxTimeInHive(bee instanceof ICustomBee ? ((ICustomBee) bee).getCoreData().getMaxTimeInHive() : BeeConstants.MAX_TIME_IN_HIVE);
            this.stored.add(new BeeData(nbt, ticksInHive, hasNectar ? maxTimeInHive : MIN_HIVE_TIME));
            BlockPos pos = this.getBlockPos();
            this.level.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BEEHIVE_ENTER, SoundSource.BLOCKS, 1.0F, 1.0F);
            bee.remove();
        }
    }
}
Also used : ICustomBee(com.teamresourceful.resourcefulbees.api.ICustomBee) Bee(net.minecraft.world.entity.animal.Bee) ICustomBee(com.teamresourceful.resourcefulbees.api.ICustomBee) BlockPos(net.minecraft.core.BlockPos) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

Bee (net.minecraft.world.entity.animal.Bee)31 BlockPos (net.minecraft.core.BlockPos)12 ItemStack (net.minecraft.world.item.ItemStack)9 Entity (net.minecraft.world.entity.Entity)8 CompoundTag (net.minecraft.nbt.CompoundTag)6 Level (net.minecraft.world.level.Level)6 NotNull (org.jetbrains.annotations.NotNull)6 ICustomBee (com.teamresourceful.resourcefulbees.api.ICustomBee)5 LivingEntity (net.minecraft.world.entity.LivingEntity)5 Player (net.minecraft.world.entity.player.Player)5 AABB (net.minecraft.world.phys.AABB)5 ResourcefulBee (com.teamresourceful.resourcefulbees.entity.passive.ResourcefulBee)4 Direction (net.minecraft.core.Direction)4 BeehiveBlockEntity (net.minecraft.world.level.block.entity.BeehiveBlockEntity)4 BlockState (net.minecraft.world.level.block.state.BlockState)4 CustomBeeEntity (com.teamresourceful.resourcefulbees.entity.passive.CustomBeeEntity)3 List (java.util.List)3 MobEffectInstance (net.minecraft.world.effect.MobEffectInstance)3 Mob (net.minecraft.world.entity.Mob)3 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)3