#CustomBee - Pathfinders

1 messages · Page 1 of 1 (latest)

stray thunder
#

I basically need to override the default pathfinders for bees since they will randomly wander and find new hives.

stuck raven
#

I mean

#

you could just change the goals

stray thunder
#

It also blacklists old hives it looks like

stray thunder
stuck raven
#

like

#

extend that goal or something

stray thunder
#

theres so many though, like idk which ones to override

stuck raven
#

uhh

#

it always pathfinds to Bee#hivePos

stray thunder
#
        public void tick() {
            if (Bee.this.hivePos != null) {
                ++this.travellingTicks;
                if (this.travellingTicks > this.adjustedTickDelay(600)) {
                    this.dropAndBlacklistHive();
                } else if (!Bee.this.navigation.isInProgress()) {
                    if (!Bee.this.closerThan(Bee.this.hivePos, 16)) {
                        if (Bee.this.isTooFarAway(Bee.this.hivePos)) {
                            this.dropHive();
                        } else {
                            Bee.this.pathfindRandomlyTowards(Bee.this.hivePos);
                        }
                    } else {
                        boolean flag = this.pathfindDirectlyTowards(Bee.this.hivePos);
                        if (!flag) {
                            this.dropAndBlacklistHive();
                        } else if (this.lastPath != null && Bee.this.navigation.getPath().sameAs(this.lastPath)) {
                            ++this.ticksStuck;
                            if (this.ticksStuck > 60) {
                                this.dropHive();
                                this.ticksStuck = 0;
                            }
                        } else {
                            this.lastPath = Bee.this.navigation.getPath();
                        }
                    }
                }
            }

        }

#

if I understand this right... if its flying for too long it drops the hive

stuck raven
#

override the goal

#

kill that check

#

and move on

stray thunder
#

How can I override the goal though without breaking the vanilla one?

#

I tried overriding one already and it broke it

stuck raven
#

just copypaste most of the code

#

make it into your own custom class

#

and apply it only to your custom bee

stray thunder
#

alright this was an issue I was hitting last time

#
    @Override
    public class BeeGoToHiveGoal extends Bee.BaseBeeGoal
#

net.minecraft.world.entity.animal.Bee.BaseBeeGoal' has private access in 'net.minecraft.world.entity.animal.Bee

#

and..

        BeeGoToHiveGoal() {
            super();
            this.travellingTicks = Bee.this.level.random.nextInt(10);
            this.blacklistedTargets = Lists.newArrayList();
            this.setFlags(EnumSet.of(Flag.MOVE));
        }

on Bee.this: 'net.minecraft.world.entity.animal.Bee' is not an enclosing class

stuck raven
#

funny stuff

#

just copypaste the entire class

#

like

#

code is code

stray thunder
#

legit just copy the entire Bee class

stuck raven
#

copy the pathfinder and all

stray thunder
#

Once I change the package name to my own everything goes red

stuck raven
#

well

#

you gotta like copypaste the classes and rename stuff to have the same behavior

stray thunder
#
    public Bee getBreedOffspring(ServerLevel worldserver, AgeableMob entityageable) {
        return (Bee)EntityType.BEE.create(worldserver);
    }

Inconvertible types; cannot cast 'net.minecraft.world.entity.animal.@javax.annotation.Nullable Bee' to 'com.squallz.cadiabees.objects.Bee'

#

I used the imports it wanted 🤷‍♂️

#

so weird.

stuck raven
#

keep changing stuff

stray thunder
#

I give up

#

this is stupid

#

a direct copy of the base one is erroring

next sky
#

@stray thunder If you're just trying to prevent them from going into their Hive, just remove the BeeGoToHiveGoal from your custom entity.

stray thunder
#

thats not what I want

#

I need to stop them from switching hives.

#

they need to always use the same one

next sky
#

Perhaps override canBeeUse() and just add an extra check to the hivePos they want to use. You'd have to also track the one they're always supposed to be in in another field for your custom entity.

#

If hivePos and defaultHive for example, aren't the same, then return false for canBeeUse.

stray thunder
#

and that would be checked...on tick...?

next sky
#

It'd be checked whenever Minecraft deemed it necessary I suppose. No idea when it actually checks it.

#

I imagine it checks it when the bee is looking for a hive to go into.

#

Even if it checks it every tick, a simple BlockPos comparison won't make hardly any difference I'm guessing.

stray thunder
#

so override this..?

    private class BeeEnterHiveGoal extends Bee.BaseBeeGoal {
        BeeEnterHiveGoal() {
            super();
        }

        public boolean canBeeUse() {
            if (Bee.this.hasHive() && Bee.this.wantsToEnterHive() && Bee.this.hivePos.closerToCenterThan(Bee.this.position(), 2.0D)) {
                BlockEntity tileentity = Bee.this.level.getBlockEntity(Bee.this.hivePos);
                if (tileentity instanceof BeehiveBlockEntity) {
                    BeehiveBlockEntity tileentitybeehive = (BeehiveBlockEntity)tileentity;
                    if (!tileentitybeehive.isFull()) {
                        return true;
                    }

                    Bee.this.hivePos = null;
                }
            }

            return false;
        }

        public boolean canBeeContinueToUse() {
            return false;
        }

        public void start() {
            BlockEntity tileentity = Bee.this.level.getBlockEntity(Bee.this.hivePos);
            if (tileentity instanceof BeehiveBlockEntity) {
                BeehiveBlockEntity tileentitybeehive = (BeehiveBlockEntity)tileentity;
                tileentitybeehive.addOccupant(Bee.this, Bee.this.hasNectar());
            }

        }
    }
next sky
#

Well, just the canBeeUse method.

#

Extend the Goal and change it

#

And then remove the default goal from the bee and add the custom one you modified.

stray thunder
#

is extending the goal a thing?

#

the canBeeUse is inside the BeeEnterHiveGoal

#

well, its inside multiple goals

next sky
#

Does it let you extend BeeEnterHiveGoal?

stray thunder
#

no

next sky
#

Honestly not sure what the difference between BeeGoToHiveGoal is and BeeEnterHiveGoal lol

#

BeeGoToHiveGoal is public so that may be easier to deal with

#

Its canBeeUse is simpler too

stray thunder
#
    public class BeeGoToHiveGoal extends BeeGoToHiveGoal {
        
    }
#

Cyclic inheritance involving 'com.squallz.cadiabees.objects.CustomBee.BeeGoToHiveGoal'

next sky
#

Name yours something different

#

BeeGoToSameHiveGoal or something

stray thunder
#

There is no default constructor available in 'net.minecraft.world.entity.animal.Bee.BeeGoToHiveGoal'

next sky
#

It wants you to define the constructor for BeeGoToHiveGoal, this is getting into Java now.

stray thunder
#

yeah but there isnt one in the base bee class

next sky
#

There is

stray thunder
#

?

next sky
#

Wait what do you mean base bee class?

stray thunder
#

its not defined outside of the other methods

next sky
#

The only thing you need to change about the Bee entity is which goals it has.

stray thunder
#

right...

#

but like...

next sky
#

But like what?

stray thunder
#

how

#

💀

#

ive never done pathfinders

#

and theres no tutorials for mojang mappings

next sky
#

You don't have to do anything with pathfinders, all your custom goal should do is basically the exact same thing as the default goal, except you're adding 1 extra condition to it.

stray thunder
#

Yeah but how do I override it

next sky
#

Let Minecraft do all the heavy lifting for you and you just extend and modify as you need.

stray thunder
#

do I need to override

    protected void registerGoals() {
        this.goalSelector.addGoal(0, new Bee.BeeAttackGoal(this, 1.399999976158142D, true));
        this.goalSelector.addGoal(1, new Bee.BeeEnterHiveGoal());
        this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D));
        this.goalSelector.addGoal(3, new TemptGoal(this, 1.25D, Ingredient.of(ItemTags.FLOWERS), false));
        this.beePollinateGoal = new Bee.BeePollinateGoal();
        this.goalSelector.addGoal(4, this.beePollinateGoal);
        this.goalSelector.addGoal(5, new FollowParentGoal(this, 1.25D));
        this.goalSelector.addGoal(5, new Bee.BeeLocateHiveGoal());
        this.goToHiveGoal = new Bee.BeeGoToHiveGoal();
        this.goalSelector.addGoal(5, this.goToHiveGoal);
        this.goToKnownFlowerGoal = new Bee.BeeGoToKnownFlowerGoal();
        this.goalSelector.addGoal(6, this.goToKnownFlowerGoal);
        this.goalSelector.addGoal(7, new Bee.BeeGrowCropGoal());
        this.goalSelector.addGoal(8, new Bee.BeeWanderGoal());
        this.goalSelector.addGoal(9, new FloatGoal(this));
        this.targetSelector.addGoal(1, (new Bee.BeeHurtByOtherGoal(this)).setAlertOthers(new Class[0]));
        this.targetSelector.addGoal(2, new Bee.BeeBecomeAngryTargetGoal(this));
        this.targetSelector.addGoal(3, new ResetUniversalAngerTargetGoal(this, true));
    }
#

@cunning imp pls

cunning imp
#

Will help in a bit

#

Making dinner atm

stray thunder
#

alright

next sky
#

Well, Mojang hates you I guess.

#

The constructor for BeeGoToHive is package private lol

stray thunder
#

theres gotta be other ones

next sky
#

The only way I can think to do it is either some convoluted way to somehow call the superclass constructor, which I have no idea how to do, nor do I even know that its possible, or you can literally just copy paste all of Mojang's code into your own class, change what you need, and use that.

#

Copying Mojang's code probably isn't a great idea if its a public plugin but it's a private then meh PeepoShrug

stray thunder
#

its not public rn

#

would be cool to make it eventually..

next sky
#

Honestly I'm not really sure why they made those constructors package private

stray thunder
#

to fuck us

#

this current behavior is a HUGE issue

#

my bees will just wander away and lose the hive that they need to keep

#

my bees need to have the same hive until its either broken (which despawns them) or they die

next sky
#

Honestly if you can somehow manage to keep hivePos as the hive you want, you wouldn't even have to make any AI changes.

stray thunder
#

set it every couple seconds... 😓

next sky
#

That is certainly one way

stray thunder
#

not exactly the best way

#

but it might be the only way 😦

next sky
#

Well, maybe not.

#

It seems like the only time the hive is ever dropped is in the tick method of Bee

#

When dropHive and dropAndBlacklistHive are called

#

If those are the only places it's dropped, then you can override tick, copy the code, and remove the drop calls.

stray thunder
#

if only i could just override drophive and dropandblacklisthive to be empty functions

stuck raven
#

^ I was too fucked up mentally to say that

next sky
stuck raven
#

was like 7am

next sky
stray thunder
#

So I cant override it?

next sky
#

Not those, thats why you should override tick.

#

Oh wait no you can override those

#

God wait Mojang's code is so weird catthonk

stray thunder
#

I was trying to do this before

    @Override
    protected PathNavigation createNavigation(Level world) {
        final PathNavigation vanillaNav = super.createNavigation(world);
        FlyingPathNavigation navigationflying = new FlyingPathNavigation(this, world) {
            public boolean isStableDestination(BlockPos blockposition) {
                return vanillaNav.isStableDestination(blockposition) && blockposition.closerThan(blockposition, 32);
            }

            public void tick() {
                vanillaNav.tick();
                getBukkitEntity().setHive(getHivePos());
            }
        };

        navigationflying.setCanOpenDoors(false);
        navigationflying.setCanFloat(false);
        navigationflying.setCanPassDoors(true);
        return navigationflying;
    }
#

but it just broke the ai entirely

stuck raven
#

that's a horrible alternative to fixing the pathfinder

next sky
#

Oh yeah I wouldn't deal with Navigation that's overcomplicating it

stray thunder
#

thats what i was given lmao

#

to stop them from flying over 32 blocks away

next sky
#

The fuckin tick() method I was talking about is in the goal

#

awesome

stray thunder
#

heh

cunning imp
#

So I did some testing trying to override the moveTo method

#

It works fine except when the bee tried to fly to flowers

#

No idea why though

stray thunder
#

hmmmm...

#

this is such a pain in the ass

#

might just have to go to ol faithful and set its hive back every 5 sec

stray thunder
#

alright boys

#

ive run into a new issue

#

once a bee enters the hive 7 times, or 7 separate bees enter once, it sets the hive's stored bee amount to max hive.getEntityCount()

#

which makes it so bees can no longer enter

#

because it thinks its full

#

but theres not a way to set the amount, only get

cunning imp
#

Time for reflection

stray thunder
#

😭

cunning imp
#

It's not that bad

stray thunder
#

well, there is hive.setMaxEntities, but thats not whast I want. I need to set the current amount

#

i dont understand reflection so its bad for me

cunning imp
#

I can help after I get some sleep

#

It's almost 1am

stray thunder
#

alright bb

#
        //Stop the bee from randomly switching hives (fuck you mojang)
        new BukkitRunnable() {
            public void run() {
                if(customBee.getBukkitEntity() == null || customBee.getBukkitEntity().isDead()) cancel();
                customBee.getBukkitEntity().setHive(customHive.getHiveLocation());
            }
        }.runTaskTimer(cadiaBees, 0, 100L);
#

This is the only reliable way ive found to make it so they dont switch hives..

#
This word is considered offensive. 
Incorrect:  
Piss off! 
cunning imp
#

I have no idea why mojang made everything package private

#

Bee is the worst entity class to work with that I've seen

stray thunder
#

of course it is

#

because its the first one I decided to mess with

#

just my luck REEEE

#

i dont understand reflection

cunning imp
#

Look it up and do some testing. I will get some sleep

stray thunder
#

ok ily