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

Hi guys,

 

I need to know when a player is in water, for some reason I noticed that while swimming around ... that the IsInWater method sometimes return false. I concluded that the player is kind of jumping while swimming around, maybe the false is returned when he is more outside of the water than inside.

 

Any hints? Any ways to know if the player is swimming? What I could do is to check if the player is in water or he is swimming.

 

Also, I noticed that there is a IsWet method for the entity. What is the difference between IsWet and IsInWater? The IsWet method returns the same thing ...a false here and there while swimming around.

    public boolean isWet()
    {
        return this.inWater || this.worldObj.canLightningStrike(new BlockPos(this.posX, this.posY, this.posZ)) || this.worldObj.canLightningStrike(new BlockPos(this.posX, this.posY + (double)this.height, this.posZ));
    }

    public boolean isInWater()
    {
        return this.inWater;
    }

 

Apparently isWet also check for rain - #canLightningStrike checks if it's raining and if you are not covered from sky. (Those claims are not 100% true, a only glimpsed at code).

 

As to "why" - is you are fully underwater it should always be true. When jumping out of water the "inWater" WILL hange, it refers to "about" center of entity.

1.7.10 is no longer supported by forge, you are on your own.

  • Author

    public boolean isWet()
    {
        return this.inWater || this.worldObj.canLightningStrike(new BlockPos(this.posX, this.posY, this.posZ)) || this.worldObj.canLightningStrike(new BlockPos(this.posX, this.posY + (double)this.height, this.posZ));
    }

    public boolean isInWater()
    {
        return this.inWater;
    }

 

Apparently isWet also check for rain - #canLightningStrike checks if it's raining and if you are not covered from sky. (Those claims are not 100% true, a only glimpsed at code).

 

As to "why" - is you are fully underwater it should always be true. When jumping out of water the "inWater" WILL hange, it refers to "about" center of entity.

 

Yeah this is what I concluded while playing around with it. Any idea how I could know when the player is swimming around in an ocean?

Only ocean?

Well, 1st you need to check biome - look how F3 debug checks player's biome (GuiIngame).

Then obviously check if isWet.

 

Now only cases left is when "jumping out of water" - I don't see how is that bad for you, I mean - isWet was designed to know if your head is underwater (you know - no air).

 

If you need to know even when you are just touching water - will have to somehow check blocks around (under or at feet) - but this will again produce next problems and will need extra checks for special cases.

 

Is "just touching water" worth it?

Can't help more, but it's basically catching all "wet cases".

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Only ocean?

Well, 1st you need to check biome - look how F3 debug checks player's biome (GuiIngame).

Then obviously check if isWet.

 

Now only cases left is when "jumping out of water" - I don't see how is that bad for you, I mean - isWet was designed to know if your head is underwater (you know - no air).

 

If you need to know even when you are just touching water - will have to somehow check blocks around (under or at feet) - but this will again produce next problems and will need extra checks for special cases.

 

Is "just touching water" worth it?

Can't help more, but it's basically catching all "wet cases".

 

Wonder if there is a way to know if the player is swimming. This would fix my issue. I did not find a way.

 

If the player is underwater, IsInWater would return true (which is what I want) ... and at the surface, the "IsSwimming" would also return true. I would cover both cases.

You can grab player's pos and simply check if it's water - this will give you pretty good idea if you are in water - but as said - need to count fact that depth of water might be 1 (standing) - that can also be catched by checking one block below - if block you are in and below you is water you have 100% (unless you count situation where you head is inside wall and legs in water, lol) that you are AT LEAST swimming or more - diving. This will also catch "dolphin-jumping" out of water.

 

Pretty simple solution.

1.7.10 is no longer supported by forge, you are on your own.

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.