Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

The bool canBeLeasedTo works to put it on but the entity doesnt get pulled back by the lead. Please help

  • Author
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; }
}

ย 

  • Author
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?

  • Author
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!

  • Author

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?

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.