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.

Gabuly

Members
  • Joined

  • Last visited

  1. I am trying to add the goal to animals which let them constantly search for water block and approach it. I have tried using the iterator, which however not always returns the closest water block. The following code can function properly but I think this may very performance consuming? I want to know how people usually deal with this kind of tasks and if there is any good project I can learn from? public void start() { // LOGGER.info("Start!!"); BlockPos entityPos = mob.blockPosition(); // Define the search range double nearestDistanceSq = Double.MAX_VALUE; // Start with the highest distance possible for (int dx = -chunkRange; dx <= chunkRange; dx++) { for (int dy = -10; dy <= 10; dy++) { // Assuming you want to search 4 blocks up and down for (int dz = -chunkRange; dz <= chunkRange; dz++) { BlockPos searchPos = entityPos.offset(dx, dy, dz); if (this.mob.level().getFluidState(searchPos).is(FluidTags.WATER)) { double distanceSq = entityPos.distSqr(searchPos); if (distanceSq < nearestDistanceSq) { nearestDistanceSq = distanceSq; movePos = searchPos; } } } } } Here is the complete file: https://github.com/gabuly/Livebywater/blob/master/src/main/java/com/github/gabuly/livebyrivermod/RandomTryFindWaterGoal.java

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.