KubeJS

KubeJS

69M Downloads

Player speed cannot be changed.

The-Arcanian opened this issue ยท 7 comments

commented

Using the script:

var blockSpeeds = [
    {
        blocks: [
            'minecraft:sand',
            'minecraft:red_sand'
        ],
        speed: 0.000000001
    },
    {
        blocks: [
            'minecraft:gravel',
            'minecraft:cobblestone',
            'minecraft:mossy_cobblestone',
            'minecraft:stone_bricks',
            'minecraft:mossy_stone_bricks',
            'minecraft:cracked_stone_bricks'
        ],
        speed: 0.2
    }
]

var speedObject = {};

blockSpeeds.forEach(set => {
    set.blocks.forEach(block => {
        speedObject[block] = set.speed
    })
})

onEvent('player.tick', event => {
    if (speedObject[event.player.block.down.id]) {
        console.log(event.player.getMovementSpeed())
        console.log(`${event.player} is standing on ${event.player.block.down.id}, setting speed to ${speedObject[event.player.block.down.id]}.`)
        event.player.setMovementSpeed(speedObject[event.player.block.down.id])
        console.log(event.player.getMovementSpeed())
    } else {
        console.log(event.player.getMovementSpeed())
        console.log(`${event.player} not standing on specified block, setting speed to ${speedObject[event.player.block.down.id]}.`)
        event.player.setMovementSpeed(1.0)
        console.log(event.player.getMovementSpeed())
    }
})

gave the log:

[01:45:20] [Server thread/INFO] [KubeJS Server/]: server_scripts:arcETech/kubejs/base/entity/player.js:32: 0.10000000149011612
[01:45:20] [Server thread/INFO] [KubeJS Server/]: server_scripts:arcETech/kubejs/base/entity/player.js:33: The_Arcanian is standing on minecraft:gravel, setting speed to 0.2.
[01:45:20] [Server thread/INFO] [KubeJS Server/]: server_scripts:arcETech/kubejs/base/entity/player.js:35: 0.10000000149011612

Lines like event.player.movementSpeed = speedObject[event.player.block.down.id] did the same thing.

commented

Absolutely sure. It seemed like speedFactor was affecting the player's current speed, not their movement speed. speedFactor = 0.0 did slow the player, but did not stop them. Negative speedFactors under -2.0 (~0.0--2.0) would cause wabbling, at least for values that would not imminently throw you out of my testing zone at the slightest movement, probably from constantly inventing current movement direction while slowly decreasing speed.

commented

PR through for 1.18: #274

Some side note, if you just want to add a speed multiplier when touch a block, like soulsand does it. You can use block.modification event for startup_scripts and modify the speedFactor of a block.

This should work:

onEvent('block.modification', event => {
  event.modify('minecraft:gravel', block => {
    block.speedFactor= 0.5;
  })
})
commented

speedFactor was the first thing I tried. But it has some odd behavior like, 0.0 not completely stopping the player, values over 1.0 start to make the controls slippery, and values approaching 2.0 make even the slightest movement start to compound. I could not find enough documentation to figure out how it all worked. So someone on the discord segested changing movementSpeed instead.

Maybe I should also mention that I am using 1.16.5 so I would prefer it to be fixed on that version up.

commented

Are you sure you changed the speedFactor and not the friction of the block? Or maybe the speedFactor also controls the slippery together with friction. But not quite sure.

I will PR 1.16.5 changes later too then!

commented

Ignore what I said. It makes sense, that speedFactor works like this, because it handles the motion of the player. So yeah 0.0 would not stop the player immediately.

Code where the speedFactor is used
image

commented

Ya, delta, change over time.

commented

Lat has since merged the relevant PR, so this should hopefully no longer be an issue