fix: input.add_callback and blocks placing when shift pressed

This commit is contained in:
MihailRis 2024-06-05 18:32:43 +03:00
parent 9dadae6e34
commit 9211e835db
2 changed files with 11 additions and 6 deletions

View File

@ -31,16 +31,17 @@ static int l_mousecode(lua_State* L) {
return 1;
}
static int l_add_callback(lua_State* L) {
static int l_add_callback(lua_State*) {
auto bindname = state->requireString(1);
const auto& bind = Events::bindings.find(bindname);
if (bind == Events::bindings.end()) {
throw std::runtime_error("unknown binding "+util::quote(bindname));
}
state->pushvalue(2);
runnable actual_callback = state->createRunnable();
runnable callback = [=]() {
if (!scripting::engine->getGUI()->isFocusCaught()) {
state->createRunnable();
actual_callback();
}
};
if (hud) {

View File

@ -33,6 +33,7 @@ void PhysicsSolver::step(
hitbox->grounded = false;
for (uint i = 0; i < substeps; i++) {
float px = pos.x;
float py = pos.y;
float pz = pos.z;
vel += gravity * dt * gravityScale;
@ -44,6 +45,9 @@ void PhysicsSolver::step(
vel.z *= glm::max(0.0f, 1.0f - dt * linear_damping);
pos += vel * dt + gravity * gravityScale * dt * dt * 0.5f;
if (hitbox->grounded) {
pos.y = py;
}
if (shifting && hitbox->grounded){
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) {
const float E = 0.001f; // inaccuracy
const glm::vec3& pos = hitbox->position;
const glm::vec3& half = hitbox->halfsize;
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) {
glm::vec3 min = block_hitbox.min();
glm::vec3 max = block_hitbox.max();
// 0.00001 - inaccuracy
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-0.00001f && max.z > pos.z-half.z-z+0.00001f &&
min.y < pos.y+half.y-y-0.00001f && max.y > pos.y-half.y-y+0.00001f)
if (min.x < pos.x+half.x-x-E && max.x > pos.x-half.x-x+E &&
min.z < pos.z+half.z-z-E && max.z > pos.z-half.z-z+E &&
min.y < pos.y+half.y-y-E && max.y > pos.y-half.y-y+E)
return true;
}
return false;