Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.4] How to put custom entities on a lead?


vassdeniss
 Share

Recommended Posts

28 minutes ago, diesieben07 said:

Show your code.

public class NimbatEntity extends BatEntity {
    public NimbatEntity(EntityType<? extends BatEntity> type, World worldIn) { super(type, worldIn); }

    public static AttributeModifierMap.MutableAttribute setCustomAttributes() {
        return MobEntity.func_233666_p_()
                .createMutableAttribute(Attributes.MAX_HEALTH, 1.0f);
    }

    @Override
    public boolean canBeLeashedTo(PlayerEntity player) { return true; }

    @Override
    public boolean canDespawn(double distanceToClosestPlayer) { return false; }
}

 

Link to comment
Share on other sites

7 minutes ago, diesieben07 said:

Bats do not use the normal AI system. The leashing code (updateLeashedState) is designed to work with the normal goal-based AI system. You'll have to override it and adapt it to the Bat's movement code.

Any guidence on how i can adapt the code?

Link to comment
Share on other sites

5 minutes ago, diesieben07 said:

Looking at the bat's movement code (updateAITasks) it seems it just picks a random position and fly straight there. You might get a reasonable result by making that pick the target of the leash if it is leashed instead of a random position.

Ill try and ask if anything goes wrong thank you!

Link to comment
Share on other sites

Do i override the updateAiTasks or still stay on the leasedstate? Also i suppose i have to add an if statement checking if the bat is leased in the else?

else {
         if (this.spawnPosition != null && (!this.world.isAirBlock(this.spawnPosition) || this.spawnPosition.getY() < 1)) {
            this.spawnPosition = null;
         }

         if (this.spawnPosition == null || this.rand.nextInt(30) == 0 || this.spawnPosition.withinDistance(this.getPositionVec(), 2.0D)) {
            this.spawnPosition = new BlockPos(this.getPosX() + (double)this.rand.nextInt(7) - (double)this.rand.nextInt(7), this.getPosY() + (double)this.rand.nextInt(6) - 2.0D, this.getPosZ() + (double)this.rand.nextInt(7) - (double)this.rand.nextInt(7));
         }

         double d2 = (double)this.spawnPosition.getX() + 0.5D - this.getPosX();
         double d0 = (double)this.spawnPosition.getY() + 0.1D - this.getPosY();
         double d1 = (double)this.spawnPosition.getZ() + 0.5D - this.getPosZ();
         Vector3d vector3d = this.getMotion();
         Vector3d vector3d1 = vector3d.add((Math.signum(d2) * 0.5D - vector3d.x) * (double)0.1F, (Math.signum(d0) * (double)0.7F - vector3d.y) * (double)0.1F, (Math.signum(d1) * 0.5D - vector3d.z) * (double)0.1F);
         this.setMotion(vector3d1);
         float f = (float)(MathHelper.atan2(vector3d1.z, vector3d1.x) * (double)(180F / (float)Math.PI)) - 90.0F;
         float f1 = MathHelper.wrapDegrees(f - this.rotationYaw);
         this.moveForward = 0.5F;
         this.rotationYaw += f1;
         if (this.rand.nextInt(100) == 0 && this.world.getBlockState(blockpos1).isNormalCube(this.world, blockpos1)) {
            this.setIsBatHanging(true);
         }
      }

Here i mean. But also how do I take the lead position in the world?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.