Jump to content

[1.7.10] Forcing the player to sink in water.


KnightDemon

Recommended Posts

Hello there, first post, so sorry if anything's against the rules.

I have an item set up that works fine, I would however like it to do something special. I would like it to make the player sink in water so that it will act like an Iron Golem or a slime (these are bad examples as they don't have the AI to swim which makes them "sink").

I was thinking of a way to have it trigger, however I can't seem to make the player sink in the water. I've got the if statements set up in an "onUpdate" method for the item to have that trigger. I've tested to make sure that it triggers correctly by adding some print statements which it does. I have tried to make the player's motionY be changed but it isn't affected or just not working. Any help on this would be appreciated.

 

So can anyone help me? If you're confused as to what I mean I'll try to make my explanation better.

Link to comment
Share on other sites

Already mentioned that part, (might have missed specifics) I've ran an if to check the player is in water. It outputs a message (for now) saying it is and such, it's just either turning off the swimming stuff the player can use or forcing the player's movement to be down so it can't swim up.


public void onUpdate(ItemStack itemstack, World world, Entity entity, int par4, boolean inHand)
{
        if (!world.isRemote)
        {
            if (entity instanceof EntityPlayer)
            {
            if (inHand)
            {
            	((EntityPlayer) entity).addChatComponentMessage(new ChatComponentTranslation("Is in hand!"));

            	if(entity.isInWater())
		{
            		((EntityPlayer) entity).addChatComponentMessage(new ChatComponentTranslation("Is in water"));
            		this.sinkInWater((EntityPlayer) entity, itemstack, world);
		}
        }
           }
        }
         super.onUpdate(itemstack, world, entity, par4, inHand);
}

 

that's what I have. Where it says this.sinkInWater is just a reference to a method i was using to allow me to change just stuff in there instead of the onUpdate method.

Link to comment
Share on other sites

Hi

 

I think the "swim upwards" is handled in

EntityLivingBase.onLivingUpdate():

 

       if (this.isJumping)
        {
            if (!this.isInWater() && !this.handleLavaMovement())
            {
                if (this.onGround && this.jumpTicks == 0)
                {
                    this.jump();
                    this.jumpTicks = 10;
                }
            }
            else
            {
                this.motionY += 0.03999999910593033D;   // swim up here
            }
        }
        else
        {
            this.jumpTicks = 0;
        }

 

This tricky bit will be to disable this without affecting all other entities as well.  You can probably use ASM+reflection to intercept this call (don't know exactly how to be honest)  and check for whether the player is holding your 'sink' item, or alternatively you might be able to cancel it out by copying the "am I swimming?" code above into your item onUpdate and using it to subtract 0.04 from motionY, or possibly into the player update tick event (eg PlayerTickEvent pre or post) if the item onUpdate doesn't work.  You could also try disabling the jump key or overwriting isJumping or similar, if you can find a hook in the right place (i.e. between when the field is set and when it is used by  the swim code)

 

-TGG

 

 

 

Link to comment
Share on other sites

Well thank you for getting back to this TheGreyGhost, although your suggestions were quite informal, it didn't seem to work for me. I possibly didn't do it right, but it just didn't seem to affect the player.

I'm thinking that a custom enchantment might work, but then again, I don't have any clue how to make a custom enchantment either. If anyone in future can figure out a way to cause the player to sink in water. (regardless of how) then I would appreciate knowing about it. I can trigger it in onUpdate for the item, if it triggers for the player I'm not sure... but it does through the item so it could work. Thank you to you both for helping.

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.