Jump to content

Recommended Posts

Posted (edited)

I would like to change a blocks slipperiness and bounciness in my mod but I don't know how.

I am very new to modding so please keep the explanation simple.

Help.

Edited by 1BowTiesAreCool1
Forgot to put version on title
Posted
2 hours ago, 1BowTiesAreCool1 said:

I would like to change a blocks slipperiness and bounciness in my mod but I don't know how.

I am very new to modding so please keep the explanation simple.

Help.

You need to create a block. Then create a event and then register it. In the event.

 + You must check whether the entity is null.

 + You have to check if we have just jumped out from the block

 + And do the method, get the block, state (from the entity) and check if the block is the CustomBounceBlock.

For example: https://pastebin.com/SCEPCZVZ

 

Posted (edited)

No event is necessary. Look at vanilla BlockSlime. Block#slipperiness is a float field which you can set in the constructor. The bouncing is controlled by the methods onFallenUpon, onLanded, and onEntityWalk.

Edited by Jay Avery
Posted
    public void onLanded(World worldIn, Entity entityIn)
    {
        if (entityIn.isSneaking())
        {
            super.onLanded(worldIn, entityIn);
        }
        else if (entityIn.motionY < 0.0D)
        {
            entityIn.motionY = -entityIn.motionY;

            if (!(entityIn instanceof EntityLivingBase))
            {
                entityIn.motionY *= 0.9D;
            }
        }
    }

The last value

Posted

That value is a multiplier for the speed the entity was falling when they hit the block. At 0, the entity would stop (land like normal). At 1.0, it would bounce at the same speed it was falling (reaching its original height). At greater than 1, it would bounce higher than its original height. How do you want your bouncing to work?

Posted

does that value actually affect players?

because it says:

if (!(entityIn instanceof EntityLivingBase))

doesn't that say if the entityIn is NOT an instance of EntityLivingBase?

Posted
1 minute ago, Kriptikz said:

does that value actually affect players?

because it says:


if (!(entityIn instanceof EntityLivingBase))

doesn't that say if the entityIn is NOT an instance of EntityLivingBase?

Oh good point. :$ I guess mobs always bounce to their start height then? I just assumed it was less.

Posted
    public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance)
    {
        if (entityIn.isSneaking())
        {
            super.onFallenUpon(worldIn, pos, entityIn, fallDistance);
        }
        else
        {
            entityIn.fall(fallDistance, 0.0F);
        }
    }
	
    public void onLanded(World worldIn, Entity entityIn)
    {
        if (entityIn.isSneaking())
        {
            super.onLanded(worldIn, entityIn);
        }
        else if (entityIn.motionY < 0.0D)
        {
        	entityIn.motionY = -entityIn.motionY * 1;

            if (!(entityIn instanceof EntityLivingBase))
            {
            	entityIn.motionY *= 0.0D;
            }
        }
    }
    
    public void onEntityWalk(World worldIn, BlockPos pos, Entity entityIn)
    {
        if (Math.abs(entityIn.motionY) < 0.1D && !entityIn.isSneaking())
        {
            double d0 = 0.4D + Math.abs(entityIn.motionY) * 0.2D;
            entityIn.motionX *= d0;
            entityIn.motionZ *= d0;
        }

        super.onEntityWalk(worldIn, pos, entityIn);
    }

 

Posted

Do you have a method OnEntityWalk? That could be your problem

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

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.