Jump to content

1.7.10 entity.IsInWater question


Frag

Recommended Posts

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.

Link to comment
Share on other sites

    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.

Link to comment
Share on other sites

    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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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

Announcements



×
×
  • Create New...

Important Information

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