1BowTiesAreCool1 Posted April 15, 2017 Posted April 15, 2017 (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 April 15, 2017 by 1BowTiesAreCool1 Forgot to put version on title Quote
lethinh Posted April 15, 2017 Posted April 15, 2017 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 Quote
Jay Avery Posted April 15, 2017 Posted April 15, 2017 (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 April 15, 2017 by Jay Avery Quote
1BowTiesAreCool1 Posted April 15, 2017 Author Posted April 15, 2017 Ok, I succesfully made the block bouncy and slippery, but I can't change how high I'm going to bounce. I've tried changing the values but nothing has helped so far Quote
Jay Avery Posted April 15, 2017 Posted April 15, 2017 What values have you changed? Post your code. Quote
1BowTiesAreCool1 Posted April 15, 2017 Author Posted April 15, 2017 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 Quote
Jay Avery Posted April 15, 2017 Posted April 15, 2017 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? Quote
1BowTiesAreCool1 Posted April 15, 2017 Author Posted April 15, 2017 Yeah, but here's the problem, I've tried changing the value but it doesn't seem to affect the bouncing at all Quote
Jay Avery Posted April 15, 2017 Posted April 15, 2017 Is the method actually being called? Use the debugger or a print statement to check. Quote
Kriptikz Posted April 15, 2017 Posted April 15, 2017 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? Quote
Jay Avery Posted April 15, 2017 Posted April 15, 2017 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. Quote
Kriptikz Posted April 15, 2017 Posted April 15, 2017 Yea I think that part is for particles: try doing this: entityIn.motionY = -entityIn.motionY * HEIGHT_MULTIPLIER; Quote
1BowTiesAreCool1 Posted April 15, 2017 Author Posted April 15, 2017 Wait, where in the code should I insert it? Quote
Kriptikz Posted April 15, 2017 Posted April 15, 2017 Replace the line where you reverse the motionY. Basically the line that is almost identical except I added the * HEIGHT_MULTIPLIER Quote
1BowTiesAreCool1 Posted April 15, 2017 Author Posted April 15, 2017 I did that but nothing special happened.. Quote
1BowTiesAreCool1 Posted April 15, 2017 Author Posted April 15, 2017 Oh wait, I think it works now!! Thanks alot! Quote
1BowTiesAreCool1 Posted April 15, 2017 Author Posted April 15, 2017 But I have one more problem, I bounce when I'm standing still atop the block, is there anyway I can prevent this? Quote
Leomelonseeds Posted April 15, 2017 Posted April 15, 2017 Post your code. Quote 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.
1BowTiesAreCool1 Posted April 15, 2017 Author Posted April 15, 2017 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); } Quote
Leomelonseeds Posted April 15, 2017 Posted April 15, 2017 Do you have a method OnEntityWalk? That could be your problem Quote 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.
Recommended Posts
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.