fix: input.add_callback and blocks placing when shift pressed
This commit is contained in:
@@ -31,16 +31,17 @@ static int l_mousecode(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_add_callback(lua_State* L) {
|
static int l_add_callback(lua_State*) {
|
||||||
auto bindname = state->requireString(1);
|
auto bindname = state->requireString(1);
|
||||||
const auto& bind = Events::bindings.find(bindname);
|
const auto& bind = Events::bindings.find(bindname);
|
||||||
if (bind == Events::bindings.end()) {
|
if (bind == Events::bindings.end()) {
|
||||||
throw std::runtime_error("unknown binding "+util::quote(bindname));
|
throw std::runtime_error("unknown binding "+util::quote(bindname));
|
||||||
}
|
}
|
||||||
state->pushvalue(2);
|
state->pushvalue(2);
|
||||||
|
runnable actual_callback = state->createRunnable();
|
||||||
runnable callback = [=]() {
|
runnable callback = [=]() {
|
||||||
if (!scripting::engine->getGUI()->isFocusCaught()) {
|
if (!scripting::engine->getGUI()->isFocusCaught()) {
|
||||||
state->createRunnable();
|
actual_callback();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (hud) {
|
if (hud) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ void PhysicsSolver::step(
|
|||||||
hitbox->grounded = false;
|
hitbox->grounded = false;
|
||||||
for (uint i = 0; i < substeps; i++) {
|
for (uint i = 0; i < substeps; i++) {
|
||||||
float px = pos.x;
|
float px = pos.x;
|
||||||
|
float py = pos.y;
|
||||||
float pz = pos.z;
|
float pz = pos.z;
|
||||||
|
|
||||||
vel += gravity * dt * gravityScale;
|
vel += gravity * dt * gravityScale;
|
||||||
@@ -44,6 +45,9 @@ void PhysicsSolver::step(
|
|||||||
vel.z *= glm::max(0.0f, 1.0f - dt * linear_damping);
|
vel.z *= glm::max(0.0f, 1.0f - dt * linear_damping);
|
||||||
|
|
||||||
pos += vel * dt + gravity * gravityScale * dt * dt * 0.5f;
|
pos += vel * dt + gravity * gravityScale * dt * dt * 0.5f;
|
||||||
|
if (hitbox->grounded) {
|
||||||
|
pos.y = py;
|
||||||
|
}
|
||||||
|
|
||||||
if (shifting && hitbox->grounded){
|
if (shifting && hitbox->grounded){
|
||||||
float y = (pos.y-half.y-E);
|
float y = (pos.y-half.y-E);
|
||||||
@@ -220,6 +224,7 @@ bool PhysicsSolver::isBlockInside(int x, int y, int z, Hitbox* hitbox) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicsSolver::isBlockInside(int x, int y, int z, Block* def, blockstate state, Hitbox* hitbox) {
|
bool PhysicsSolver::isBlockInside(int x, int y, int z, Block* def, blockstate state, Hitbox* hitbox) {
|
||||||
|
const float E = 0.001f; // inaccuracy
|
||||||
const glm::vec3& pos = hitbox->position;
|
const glm::vec3& pos = hitbox->position;
|
||||||
const glm::vec3& half = hitbox->halfsize;
|
const glm::vec3& half = hitbox->halfsize;
|
||||||
const auto& boxes = def->rotatable
|
const auto& boxes = def->rotatable
|
||||||
@@ -228,10 +233,9 @@ bool PhysicsSolver::isBlockInside(int x, int y, int z, Block* def, blockstate st
|
|||||||
for (const auto& block_hitbox : boxes) {
|
for (const auto& block_hitbox : boxes) {
|
||||||
glm::vec3 min = block_hitbox.min();
|
glm::vec3 min = block_hitbox.min();
|
||||||
glm::vec3 max = block_hitbox.max();
|
glm::vec3 max = block_hitbox.max();
|
||||||
// 0.00001 - inaccuracy
|
if (min.x < pos.x+half.x-x-E && max.x > pos.x-half.x-x+E &&
|
||||||
if (min.x < pos.x+half.x-x-0.00001f && max.x > pos.x-half.x-x+0.00001f &&
|
min.z < pos.z+half.z-z-E && max.z > pos.z-half.z-z+E &&
|
||||||
min.z < pos.z+half.z-z-0.00001f && max.z > pos.z-half.z-z+0.00001f &&
|
min.y < pos.y+half.y-y-E && max.y > pos.y-half.y-y+E)
|
||||||
min.y < pos.y+half.y-y-0.00001f && max.y > pos.y-half.y-y+0.00001f)
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user