Fix pressing set spawn outside map always causing you to get moved 1/8th of a block up and fix setting spawn not behaving properly when a large model, inside a block, and standing on one of the borders of the map. (Thanks tornato)

This commit is contained in:
UnknownShadow200 2019-10-22 22:00:27 +11:00
parent 40bdedd2d9
commit b11f5a7e61
9 changed files with 23 additions and 20 deletions

View File

@ -939,13 +939,13 @@ static void LocalPlayer_DoRespawn(void) {
/* Spawn player at highest solid position to match vanilla Minecraft classic */
/* Only when player can noclip, since this can let you 'clip' to above solid blocks */
if (p->Hacks.CanNoclip && World_Contains(pos.X, pos.Y, pos.Z)) {
if (p->Hacks.CanNoclip) {
AABB_Make(&bb, &spawn, &p->Base.Size);
for (y = pos.Y; y <= World.Height; y++) {
spawnY = Respawn_HighestSolidY(&bb);
if (spawnY == RESPAWN_NOT_FOUND) {
block = World_GetPhysicsBlock(pos.X, y, pos.Z);
block = World_SafeGetBlock(pos.X, y, pos.Z);
height = Blocks.Collide[block] == COLLIDE_SOLID ? Blocks.MaxBB[block].Y : 0.0f;
spawn.Y = y + height + ENTITY_ADJUSTMENT;
break;

View File

@ -1256,7 +1256,7 @@ static cc_bool Sounds_CheckSolid(BlockID b) {
static void SoundComp_GetSound(struct LocalPlayer* p) {
struct AABB bounds;
Vec3 pos;
IVec3 feetPos;
IVec3 coords;
BlockID blockUnder;
float maxY;
cc_uint8 typeUnder, collideUnder;
@ -1269,11 +1269,11 @@ static void SoundComp_GetSound(struct LocalPlayer* p) {
Entity_TouchesAny(&bounds, Sounds_CheckNonSolid);
if (sounds_type != SOUND_NONE) return;
/* then check block standing on */
/* then check block standing on (feet) */
pos = p->Interp.Next.Pos; pos.Y -= 0.01f;
IVec3_Floor(&feetPos, &pos);
blockUnder = World_SafeGetBlock_3I(feetPos);
maxY = feetPos.Y + Blocks.MaxBB[blockUnder].Y;
IVec3_Floor(&coords, &pos);
blockUnder = World_SafeGetBlock(coords.X, coords.Y, coords.Z);
maxY = coords.Y + Blocks.MaxBB[blockUnder].Y;
typeUnder = Blocks.StepSounds[blockUnder];
collideUnder = Blocks.Collide[blockUnder];

View File

@ -50,7 +50,7 @@ static void EnvRenderer_CalcFog(float* density, PackedCol* col) {
IVec3_Floor(&coords, &Camera.CurrentPos); /* coords = floor(camera_pos); */
IVec3_ToVec3(&pos, &coords); /* pos = coords; */
block = World_SafeGetBlock_3I(coords);
block = World_SafeGetBlock(coords.X, coords.Y, coords.Z);
Vec3_Add(&blockBB.Min, &pos, &Blocks.MinBB[block]);
Vec3_Add(&blockBB.Max, &pos, &Blocks.MaxBB[block]);

View File

@ -17,8 +17,8 @@ int Gui_Chatlines;
cc_bool Gui_ClickableChat, Gui_TabAutocomplete, Gui_ShowFPS;
GfxResourceID Gui_GuiTex, Gui_GuiClassicTex, Gui_IconsTex;
struct Screen* Gui_HUD;
struct Screen* Gui_Chat;
struct HUDScreen* Gui_HUD;
struct ChatScreen* Gui_Chat;
struct Screen* Gui_Screens[GUI_MAX_SCREENS];
int Gui_ScreensCount;
static cc_uint8 priorities[GUI_MAX_SCREENS];
@ -173,7 +173,7 @@ void Gui_RefreshAll(void) {
Gui_ContextRecreated(NULL);
}
void Gui_RefreshHud(void) { Gui_Refresh(Gui_Chat); }
void Gui_RefreshChat(void) { Gui_Refresh(Gui_Chat); }
void Gui_Refresh(struct Screen* s) {
s->VTABLE->ContextLost(s);
s->VTABLE->ContextRecreated(s);

View File

@ -106,8 +106,11 @@ enum GuiPriority {
GUI_PRIORITY_LOADING = 5,
};
extern struct Screen* Gui_HUD;
extern struct Screen* Gui_Chat;
struct HUDScreen;
struct ChatScreen;
extern struct HUDScreen* Gui_HUD;
extern struct ChatScreen* Gui_Chat;
#define GUI_MAX_SCREENS 10
extern struct Screen* Gui_Screens[GUI_MAX_SCREENS];
extern int Gui_ScreensCount;
@ -140,7 +143,7 @@ struct Screen* Gui_GetBlocksWorld(void);
struct Screen* Gui_GetClosable(void);
void Gui_RefreshAll(void);
void Gui_RefreshHud(void);
void Gui_RefreshChat(void);
void Gui_Refresh(struct Screen* s);
void Gui_RenderGui(double delta);

View File

@ -88,7 +88,7 @@ static void MapRenderer_CheckWeather(double delta) {
cc_bool outside;
IVec3_Floor(&pos, &Camera.CurrentPos);
block = World_SafeGetBlock_3I(pos);
block = World_SafeGetBlock(pos.X, pos.Y, pos.Z);
outside = pos.Y < 0 || !World_ContainsXZ(pos.X, pos.Z);
inTranslucent = Blocks.Draw[block] == DRAW_TRANSLUCENT || (pos.Y < Env.EdgeHeight && outside);

View File

@ -2483,7 +2483,7 @@ static void GuiOptionsScreen_SetShowFPS(const String* v) { Gui_ShowFPS = Menu_Se
static void GuiOptionsScreen_SetScale(const String* v, float* target, const char* optKey) {
*target = Menu_Float(v);
Options_Set(optKey, v);
Gui_RefreshHud();
Gui_RefreshChat();
}
static void GuiOptionsScreen_GetHotbar(String* v) { String_AppendFloat(v, Game_RawHotbarScale, 1); }

View File

@ -109,8 +109,8 @@ BlockID World_GetPhysicsBlock(int x, int y, int z) {
return World_GetBlock(x, y, z);
}
BlockID World_SafeGetBlock_3I(IVec3 p) {
return World_Contains(p.X, p.Y, p.Z) ? World_GetBlock(p.X, p.Y, p.Z) : BLOCK_AIR;
BlockID World_SafeGetBlock(int x, int y, int z) {
return World_Contains(x, y, z) ? World_GetBlock(x, y, z) : BLOCK_AIR;
}
@ -250,7 +250,7 @@ float Respawn_HighestSolidY(struct AABB* bb) {
for (z = minZ; z <= maxZ; z++) { v.Z = (float)z;
for (x = minX; x <= maxX; x++) { v.X = (float)x;
block = World_GetPhysicsBlock(x, y, z);
block = World_SafeGetBlock(x, y, z);
Vec3_Add(&blockBB.Min, &v, &Blocks.MinBB[block]);
Vec3_Add(&blockBB.Max, &v, &Blocks.MaxBB[block]);

View File

@ -74,7 +74,7 @@ BlockID World_GetPhysicsBlock(int x, int y, int z);
void World_SetBlock(int x, int y, int z, BlockID block);
/* If coordinates are outside the map, returns BLOCK_AIR. */
/* Otherwise returns the block at the given coordinates. */
BlockID World_SafeGetBlock_3I(IVec3 p);
BlockID World_SafeGetBlock(int x, int y, int z);
/* Whether the given coordinates lie inside the map. */
static CC_INLINE cc_bool World_Contains(int x, int y, int z) {