Compare commits

...

17 Commits

Author SHA1 Message Date
Guy Liner 3f886f3882 Removed lines about look at Minecraft source code 2022-01-16 14:42:55 -05:00
Guy Liner cc18b2ecc5 These are minecraft like gravity and jump physics, especially with the patch for mountain flying that was on minetest pull requests 2022-01-08 20:12:43 -05:00
Guy Liner 99c8e818dd Changed variable back to a local one 2022-01-07 07:47:27 -05:00
Guy Liner 702c954cf0 Corrected coding style 2022-01-07 07:46:53 -05:00
Guy Liner 9630817f0e If the player is jump and hitting a wall, do not allow them to walk 2022-01-07 07:46:15 -05:00
Guy Liner 531b17c5bd Slab detection 2022-01-07 00:09:56 -05:00
Guy Liner 48f6699a6a Added comments and clean up code logic 2022-01-07 00:09:56 -05:00
GuyLiner 3f625be8e2 Merge branch 'master' into mc_physics 2022-01-07 03:16:51 +00:00
Guy Liner 6801e6556d Rearranged some conditionals 2022-01-06 22:00:15 -05:00
Guy Liner 838e09105e Removed some comments and added some comments 2022-01-06 21:59:59 -05:00
Guy Liner ea76517591 The function that was created did not work, so I created a new one that calculates nodes around the player based on degrees 2022-01-06 17:29:23 -05:00
Guy Liner d51f7344ae Testing out some math 2022-01-06 15:52:32 -05:00
Guy Liner 4a8f323192 TEMP 2022-01-06 13:58:18 -05:00
Guy Liner fa248bf7da Player must stop sprinting if they hit a block in front of them or if the player's sides are touching a wall 2022-01-06 12:20:59 -05:00
bigboi_ d38662475c testing values 2022-01-03 13:16:39 -05:00
bigboi_ 771a15b99e Modified Jump speed again 2022-01-03 08:45:36 -05:00
Guy Liner b4db8257a0 Modified jump movement_speed_jump and gravity 2022-01-03 08:38:53 -05:00
6 changed files with 159 additions and 72 deletions

View File

@ -245,11 +245,6 @@ need to state their sources. These PRs also need Fleckenstein's approval
before they are merged.
You can use these sources:
* Minecraft code (Name the source file and line, however DONT post any
proprietary code). You can use
[MCP](https://minecraft.fandom.com/wiki/Programs_and_editors/Mod_Coder_Pack)
to decompile Minecraft or look at
[Minestorm](https://github.com/Minestom/Minestom) code.
* Testing things inside of Minecraft (Attach screenshots / video footage
of the results)
* [Official Minecraft Wiki](https://minecraft.fandom.com/wiki/Minecraft_Wiki)

View File

@ -15,7 +15,8 @@ movement_speed_walk = 4.317
movement_speed_crouch = 1.295
movement_speed_fast = 25.0
movement_speed_jump = 6.6
#movement_speed_jump = 6.6
movement_speed_jump = 8.5
movement_speed_climb = 2.35
# TODO: Add descend speed (3.0) when available
@ -23,7 +24,8 @@ movement_liquid_fluidity = 1.13
movement_liquid_fluidity_smooth = 0.5
movement_liquid_sink = 23
movement_gravity = 10.4
#movement_gravity = 10.4
movement_gravity = 14.4
# Mapgen stuff

View File

@ -41,6 +41,7 @@ minetest.register_node("mcl_crafting_table:crafting_table", {
tiles = {"crafting_workbench_top.png", "default_wood.png", "crafting_workbench_side.png",
"crafting_workbench_side.png", "crafting_workbench_front.png", "crafting_workbench_front.png"},
paramtype2 = "facedir",
collision_box = { type = "fixed", fixed = {-0.40, 0.0, -0.40, 0.40, 0.5, 0.40}},
groups = {handy=1,axey=1, deco_block=1, material_wood=1,flammable=-1},
on_rightclick = function(pos, node, player, itemstack)
if not player:get_player_control().sneak then

View File

@ -179,7 +179,7 @@ minetest.register_globalstep(function(dtime)
local animation_speed_mod = model.animation_speed or 30
-- Determine if the player is walking
if controls.up or controls.down or controls.left or controls.right then
if controls.up or controls.down or controls.left or controls.right and mcl_playerinfo:collision_detect(player:get_pos(),player) then
walking = true
end

View File

@ -1,4 +1,5 @@
local table = table
--require "math"
-- Player state for public API
mcl_playerinfo = {}
@ -23,6 +24,85 @@ end
local time = 0
--[[
Function that allows for detecting if a player is touching
a wall at the moment. Useful for determining things like
if the player should be sprinting.
--]]
function mcl_playerinfo:collision_detect(pos,player)
--[[
If the player loads in and these variables aren't
set the game crashes
--]]
local around_player = {
["left_ofplayer"] = pos,
["right_ofplayer"] = pos,
["front_ofplayer"] = pos,
["front_ofplayerplus"] = pos
}
--Your distance from a block is < 1.1 if you're touching it.
local too_close = 1.1
local slab_too_close = 1.42
--[[
Takes the current degree angle that the player is facing
Degrees in minetest are determined counter clock wise
from +Z North
--]]
local deg = math.deg(player:get_look_horizontal())
--will help determine blocks near the player
local nearme = vector.new(pos)
--[[
Basically turns the X and Z axises into a 2D plane
The 4 quadrants tell us what block on what axis
should currently be on the left,right,front, or "frontplus"
of the player. front plus is just if there is a block
on top of the block in front of the player
]]
if deg > 0 and deg < 90 then
around_player["left_ofplayer"] = vector.add(nearme, vector.new(-1,0,0))
around_player["right_ofplayer"] = vector.add(nearme, vector.new(1,0,0))
around_player["front_ofplayer"] = vector.add(nearme, vector.new(0,0,1))
around_player["front_ofplayerplus"] = vector.add(nearme, vector.new(0,1,1))
elseif deg > 90 and deg < 180 then
around_player["left_ofplayer"] = vector.add(nearme, vector.new(0,0,-1))
around_player["right_ofplayer"] = vector.add(nearme, vector.new(0,0,1))
around_player["front_ofplayer"] = vector.add(nearme, vector.new(-1,0,0))
around_player["front_ofplayerplus"] = vector.add(nearme, vector.new(-1,1,0))
elseif deg > 180 and deg < 270 then
around_player["left_ofplayer"] = vector.add(nearme, vector.new(1,0,0))
around_player["right_ofplayer"] = vector.add(nearme, vector.new(-1,0,0))
around_player["front_ofplayer"] = vector.add(nearme, vector.new(0,0,-1))
around_player["front_ofplayerplus"] = vector.add(nearme, vector.new(0,1,-1))
elseif deg > 270 and deg < 360 then
around_player["left_ofplayer"] = vector.add(nearme, vector.new(0,0,1))
around_player["right_ofplayer"] = vector.add(nearme, vector.new(0,0,-1))
around_player["front_ofplayer"] = vector.add(nearme, vector.new(1,0,0))
around_player["front_ofplayerplus"] = vector.add(nearme, vector.new(1,0,0))
end
for placement,coord in pairs(around_player) do
local node = minetest.get_node(coord)
local distance = vector.distance(pos, coord)
-- How far is the player from the block in the given direction and
-- if the block is not air the player is colliding with it
--print(node.name)
--print(distance)
if vector.distance(pos, coord) < too_close and node.name ~= "air" then
return false
--Should be able to detect when your head is touching a slab
elseif distance < slab_too_close and distance > too_close and placement == "front_ofplayerplus" and node.name ~= "air" then
return false
end
end
return true
end
local function get_player_nodes(player_pos)
local work_pos = table.copy(player_pos)
@ -75,7 +155,6 @@ end)
-- set to blank on join (for 3rd party mods)
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
mcl_playerinfo[name] = {
node_head = "",
node_feet = "",

View File

@ -40,8 +40,13 @@ function mcl_sprint.is_sprinting(playername)
end
end
-- Determines if a block is in front of a player
--function mcl_sprint.touching_node(pos)
-- local touch
minetest.register_on_joinplayer(function(player)
local playerName = player:get_player_name()
playerName = player:get_player_name()
players[playerName] = {
sprinting = false,
@ -159,70 +164,75 @@ minetest.register_globalstep(function(dtime)
for playerName, playerInfo in pairs(players) do
local player = get_player_by_name(playerName)
if player then
local ctrl = player:get_player_control()
--Check if the player should be sprinting
if players[playerName]["clientSprint"] or ctrl.aux1 and ctrl.up and not ctrl.sneak then
players[playerName]["shouldSprint"] = true
if mcl_playerinfo:collision_detect(player:get_pos(),player) then
local ctrl = player:get_player_control()
--Check if the player should be sprinting
if players[playerName]["clientSprint"] or ctrl.aux1 and ctrl.up and not ctrl.sneak then
players[playerName]["shouldSprint"] = true
else
players[playerName]["shouldSprint"] = false
end
local playerPos = player:get_pos()
--If the player is sprinting, create particles behind and cause exhaustion
if playerInfo["sprinting"] == true and players[playerName]["shouldSprint"] and not player:get_attach() and gameTime % 0.1 == 0 then
-- Exhaust player for sprinting
local lastPos = players[playerName].lastPos
local dist = vector.distance({x=lastPos.x, y=0, z=lastPos.z}, {x=playerPos.x, y=0, z=playerPos.z})
players[playerName].sprintDistance = players[playerName].sprintDistance + dist
if players[playerName].sprintDistance >= 1 then
local superficial = math.floor(players[playerName].sprintDistance)
exhaust(playerName, mcl_hunger.EXHAUST_SPRINT * superficial)
players[playerName].sprintDistance = players[playerName].sprintDistance - superficial
end
-- Sprint node particles
local playerNode = get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]})
local def = registered_nodes[playerNode.name]
if def and def.walkable then
add_particlespawner({
amount = math.random(1, 2),
time = 1,
minpos = {x=-0.5, y=0.1, z=-0.5},
maxpos = {x=0.5, y=0.1, z=0.5},
minvel = {x=0, y=5, z=0},
maxvel = {x=0, y=5, z=0},
minacc = {x=0, y=-13, z=0},
maxacc = {x=0, y=-13, z=0},
minexptime = 0.1,
maxexptime = 1,
minsize = 0.5,
maxsize = 1.5,
collisiondetection = true,
attached = player,
vertical = false,
node = playerNode,
node_tile = get_top_node_tile(playerNode.param2, def.paramtype2),
})
end
end
--Adjust player states
players[playerName].lastPos = playerPos
if players[playerName]["shouldSprint"] == true then --Stopped
local sprinting
-- Prevent sprinting if hungry or sleeping
if (mcl_hunger.active and get_hunger(player) <= 6)
or (player:get_meta():get_string("mcl_beds:sleeping") == "true") then
sprinting = false
cancelClientSprinting(playerName)
else
sprinting = true
end
setSprinting(playerName, sprinting)
elseif players[playerName]["shouldSprint"] == false then
setSprinting(playerName, false)
end
else
players[playerName]["shouldSprint"] = false
setSprinting(playerName, 0)
end
local playerPos = player:get_pos()
--If the player is sprinting, create particles behind and cause exhaustion
if playerInfo["sprinting"] == true and not player:get_attach() and gameTime % 0.1 == 0 then
-- Exhaust player for sprinting
local lastPos = players[playerName].lastPos
local dist = vector.distance({x=lastPos.x, y=0, z=lastPos.z}, {x=playerPos.x, y=0, z=playerPos.z})
players[playerName].sprintDistance = players[playerName].sprintDistance + dist
if players[playerName].sprintDistance >= 1 then
local superficial = math.floor(players[playerName].sprintDistance)
exhaust(playerName, mcl_hunger.EXHAUST_SPRINT * superficial)
players[playerName].sprintDistance = players[playerName].sprintDistance - superficial
end
-- Sprint node particles
local playerNode = get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]})
local def = registered_nodes[playerNode.name]
if def and def.walkable then
add_particlespawner({
amount = math.random(1, 2),
time = 1,
minpos = {x=-0.5, y=0.1, z=-0.5},
maxpos = {x=0.5, y=0.1, z=0.5},
minvel = {x=0, y=5, z=0},
maxvel = {x=0, y=5, z=0},
minacc = {x=0, y=-13, z=0},
maxacc = {x=0, y=-13, z=0},
minexptime = 0.1,
maxexptime = 1,
minsize = 0.5,
maxsize = 1.5,
collisiondetection = true,
attached = player,
vertical = false,
node = playerNode,
node_tile = get_top_node_tile(playerNode.param2, def.paramtype2),
})
end
end
--Adjust player states
players[playerName].lastPos = playerPos
if players[playerName]["shouldSprint"] == true then --Stopped
local sprinting
-- Prevent sprinting if hungry or sleeping
if (mcl_hunger.active and get_hunger(player) <= 6)
or (player:get_meta():get_string("mcl_beds:sleeping") == "true") then
sprinting = false
cancelClientSprinting(playerName)
else
sprinting = true
end
setSprinting(playerName, sprinting)
elseif players[playerName]["shouldSprint"] == false then
setSprinting(playerName, false)
end
end
end
end)