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

Hey guys,

I am struggling a long time to figure out how to create a formula for my mod.

 

Overview:

I created a brake rail which should brake down a minecart when it's on it.

I found this formula in the internet and applied it:

Spoiler
this.currentBrakeForce = (Math.pow(targetVelocity, 2) - Math.pow(entryVelocity, 2)) / (2 * brakerunLength)

 

The minecart has an entry speed of 12m/s, the target velocity is 8m/s and the break run is 1m because it's one block.

 

I slow down the cart by multiplying the result of this formula with the current motion of the cart:

Spoiler
train.setMotion(train.getMotion().multiply(this.currentBrakeForce, 0, this.currentBrakeForce));

 

 

I figured out another thing: The wiki says that that 8m/s are 1.2 in motion.

So I changed the formula depending on the motion (I don't know if this is right but it made sense to me):

Spoiler
(0.15 * entryVelocity) / Math.abs(((Math.pow(targetVelocity, 2) - Math.pow(entryVelocity, 2)) / (2 * brakerunLength)));

 

Why 0.15?

As mentioned before 8m/s are 1.2.

So, 1m/s = 0.15 -> (8/1.2).

And then I multiplied it with the entry speed because it has to be changed to the "motion internal unit"?!

 

I am really frustrated right know, because I tried a lot of different changes within the formula. The problem is maybe the multiplication with the motion? I don't know.

Maybe someone can help me  :)

Thanks in advance!

3 hours ago, J3ramy said:

The wiki says that that 8m/s are 1.2 in motion.

Not sure where you're seeing this. BTW, minecarts already have a maximum speed of 8m/s per axis.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Maybe I should mention it. I changed the max speed and max speed on rail to 16m/s.

But my question is more, how do I convert the calculated force to the Minecraft motion?

Not sure, I haven't dug into the minecart code that much.

The only problem I see is that this:
Math.pow(targetVelocity, 2) - Math.pow(entryVelocity, 2)
Is guaranteed to return a negative value, which when multiplied against entity motion would cause the entity to reverse direction.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

I might have understood it wrong, but if you are simply multiplying the x and z component of the velocity vector, then don't you just need the ratio between the target and entry velocity? So shouldn't your brake"force" be targetVelocity/entryVelocity?

  • Author

Hey Thorius,

I will try it tonight when I’m at home again but it seems like it could work. I’ll keep you up to date 

You should know that this formula will also accelerate the carts to the specified speed. If you want to avoid that, use Math.min(brakeforce, 1).

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.