Skip to content

Commit

Permalink
Bugfixes & Cleanup
Browse files Browse the repository at this point in the history
* Cleaned up GameMods.hpp & fixed all macro toggles
* Made world border unpickable/unhighlightable
* Lowered mob reach range for creative mode from 32 blocks to 7 (as in 0.12.1)
* Fixed uninitialized variables (bugs could appear depending on the compiler)
    * "PathfinderMob::m_pAttackTarget" (caused a crash)
    * "Entity::field_C4" (caused entities to suffocate always)
* Fixed Random.cpp for compilation with C++03 by using "std::numeric_limits" instead of "INFINITY"
* Documented Texture::field_C as m_hasAlpha
* Deleted unused "GLTexture" struct
* Removed ModelPart::renderHorrible
* Added other mob textures to .gitignore
  • Loading branch information
BrentDaMage committed Apr 17, 2024
1 parent 0da5a03 commit 0dc6bc1
Show file tree
Hide file tree
Showing 25 changed files with 78 additions and 85 deletions.
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ xcuserdata/
/game/assets/misc/foliagecolor.png
/game/assets/misc/grasscolor.png
/game/assets/mob/char.png
/game/assets/mob/chicken.png
/game/assets/mob/cow.png
/game/assets/mob/creeper.png
/game/assets/mob/pig.png
/game/assets/mob/pigzombie.png
/game/assets/mob/sheep.png
/game/assets/mob/sheep_fur.png
/game/assets/mob/skeleton.png
/game/assets/mob/spider.png
/game/assets/mob/zombie.png
/game/assets/particles.png
/game/assets/terrain.png
/game/assets/gui/buynow.png
Expand Down Expand Up @@ -204,4 +214,3 @@ xcuserdata/
/game/assets/gui/feedback_fill.png
/game/assets/gui/feedback_outer.png
/game/assets/snow.png
/game/assets/mob/pig.png
16 changes: 4 additions & 12 deletions GameMods.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
// Here is a list of options that you can enable when building the project:

// ORIGINAL_CODE - Unpatches all bugs and allows building for Xperia Play only. (TODO)
// #define ORIGINAL_CODE
//#define ORIGINAL_CODE

#ifdef ORIGINAL_CODE
#define DEMO
#else

#if defined ANDROID || defined TARGET_OS_IPHONE
#define MOBILE
#endif

// TODO: Since this is the modded version, we don't need these anymore. Remove them

// Mods
Expand All @@ -22,9 +18,7 @@
//#define MOD_POPOUT_CONSOLE // Open a separate console aside from the game window. By default only the debugger can see our logs. Win32 Debug only.

// Tests
//#define TEST_DROPPED_ITEMS // Allow dropped items to be dropped and collected.
//#define TEST_SURVIVAL_MODE // Test survival mode.
#define TEST_TOUCH_SCREEN // Test touch screen controls. The mouse will simulate one touch finger.

// Enhancements
//#define ENH_ENTITY_SHADING // Allows shading of entities -- Currently we are abandoning this. Want to add normal support
Expand All @@ -36,19 +30,17 @@
#define ENH_USE_JAVA_LIGHT_RAMP // Use Java Beta 1.3 light ramp instead of flawed PE one
#define ENH_RUN_DAY_NIGHT_CYCLE // Allow the day/night cycle to run.
#define ENH_USE_OWN_AO // Use own ambient occlusion engine - looks pretty much the same except it fixes the corners
#define ENH_ADD_OPTIONS_PAUSE // Add an 'options' button in the pause menu
#define ENH_EXTRA_ITEMS_IN_INV // Add extra items in a new 5th row in the inventory.
#define ENH_ADD_OPTIONS_PAUSE // Add an 'options' button in the pause menu=
#define ENH_HIGHLIGHT_BY_HOVER // Highlight buttons by hovering them instead of the usual way.
#define ENH_ALLOW_SAND_GRAVITY // Allow sand to fall.
#define ENH_USE_GUI_SCALE_2 // Use a 2x GUI scale instead of 3x. Looks better on PC
#define ENH_ALLOW_SCROLL_WHEEL // Allow use of the scroll wheel to change selected inventory slots
#define ENH_3D_INVENTORY_TILES // Uses 3D rendered inventory tiles, use with ENH_SHADE_HELD_TILES to render correctly.

// TODO: Implement this permanently?
#define ENH_IMPROVED_SAVING // Improve world saving. The original Minecraft doesn't always really save for some reason

// Toggle Demo Mode
//#define DEMO

// Enable Debug Mode
//#define MC_DEBUG

#endif
4 changes: 4 additions & 0 deletions source/client/app/AppPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ Texture AppPlatform::loadTexture(const std::string&, bool bIsRequired)
return Texture(0, 0, nullptr, 1, 0);
}

#ifndef ORIGINAL_CODE

bool AppPlatform::isTouchscreen()
{
return true;
Expand Down Expand Up @@ -222,6 +224,8 @@ SoundSystem* const AppPlatform::getSoundSystem() const
return nullptr;
}

#endif

std::string AppPlatform::getAssetPath(const std::string &path) const
{
std::string realPath = path;
Expand Down
6 changes: 3 additions & 3 deletions source/client/gui/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ void Screen::keyPressed(int key)
if (m_buttonTabList.size())
{
#ifndef ENH_HIGHLIGHT_BY_HOVER
if (m_pMinecraft->getOptions()->isKey(MENU_NEXT, key))
if (m_pMinecraft->getOptions()->isKey(KM_MENU_NEXT, key))
{
m_tabButtonIndex++;
if (m_tabButtonIndex == int(m_buttonTabList.size()))
m_tabButtonIndex = 0;
}
if (m_pMinecraft->getOptions()->isKey(MENU_PREVIOUS, key))
if (m_pMinecraft->getOptions()->isKey(KM_MENU_PREVIOUS, key))
{
m_tabButtonIndex--;
if (m_tabButtonIndex == -1)
m_tabButtonIndex = int(m_buttonTabList.size() - 1);
}
if (m_pMinecraft->getOptions()->isKey(MENU_OK, key))
if (m_pMinecraft->getOptions()->isKey(KM_MENU_OK, key))
{
if (m_buttonTabList[m_tabButtonIndex]->m_bEnabled)
{
Expand Down
2 changes: 2 additions & 0 deletions source/client/gui/screens/PauseScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ void PauseScreen::init()
#endif
}

#ifdef ENH_ADD_OPTIONS_PAUSE
//swap the options and quit buttons around (??)
std::swap(m_btnOptions.m_yPos, m_btnQuit.m_yPos);
#endif

for (int i = 0; i < int(m_buttons.size()); i++)
m_buttonTabList.push_back(m_buttons[i]);
Expand Down
12 changes: 12 additions & 0 deletions source/client/model/Cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ Cube::Cube(ModelPart* a2, int a3, int a4, float x, float y, float z, int d, int
m_faces[4] = PolygonQuad(&m_verts[1], &m_verts[0], &m_verts[3], &m_verts[2], m + f, n + f, m + f + d, n + f + e); // z1 face
m_faces[5] = PolygonQuad(&m_verts[4], &m_verts[5], &m_verts[6], &m_verts[7], m + f + d + f, n + f, m + f + d + f + d, n + f + e); // z2 face

#ifdef ENH_ENTITY_SHADING && 0
// Applies shading that is identical to that of the in-hand block. This doesn't look any different.
// - Brent
#define SHADE_FACE(face, shade) m_faces[face].setColor(shade, shade, shade)
SHADE_FACE(0, 0.8f); // south
SHADE_FACE(1, 0.8f); // north
SHADE_FACE(2, 0.5f); // up
//SHADE_FACE(3, 1.0f); // down
SHADE_FACE(4, 0.6f); // east
SHADE_FACE(5, 0.6f); // west
#endif

// *N.B. The original game specifies the vertex ordering as 2, 3, 7, 6, but that renders the back side of the cow upside down.
// This might not be proper form for the face, but we're disabling culling anyway so who cares.

Expand Down
32 changes: 0 additions & 32 deletions source/client/model/ModelPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,38 +173,6 @@ void ModelPart::render(float scale)
}
}

void ModelPart::renderHorrible(float scale)
{
if (field_49)
return;

if (!field_48)
return;

if (!m_bCompiled)
compile(scale);

if (!hasDefaultRot())
{
glPushMatrix();

translateRotTo(scale);
drawSlow(scale);

glPopMatrix();
}
else if (!hasDefaultPos())
{
translatePosTo(scale);
drawSlow(scale);
translatePosTo(-scale);
}
else
{
drawSlow(scale);
}
}

void ModelPart::renderRollable(float scale)
{
if (field_49)
Expand Down
1 change: 0 additions & 1 deletion source/client/model/ModelPart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class ModelPart
void drawSlow(float scale);
void mimic(ModelPart* pPart);
void render(float scale);
void renderHorrible(float scale);
void renderRollable(float scale);
void setModel(Model* pModel);
void setPos(float x, float y, float z);
Expand Down
2 changes: 1 addition & 1 deletion source/client/renderer/GameRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ void GameRenderer::pick(float f)
dist = mchr.m_hitPos.distanceTo(mobPos);

if (m_pMinecraft->m_pGameMode->isCreativeType())
dist = 32.0f;
dist = 7.0f;
else if (dist > 3.0f)
dist = 3.0f;

Expand Down
12 changes: 3 additions & 9 deletions source/client/renderer/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,16 @@ struct Texture
int m_width;
int m_height;
uint32_t* m_pixels;
uint8_t field_C;
bool m_hasAlpha;
uint8_t field_D;

Texture()
{
m_width = 0;
m_height = 0;
m_pixels = nullptr;
field_C = false;
m_hasAlpha = false;
field_D = false;
}
Texture(int width, int height, void* pixels, uint8_t a1, uint8_t a2) : m_width(width), m_height(height), m_pixels((uint32_t*)pixels), field_C(a1), field_D(a2) {}
};

struct GLTexture
{
unsigned m_textureID; // GL texture ID
Texture m_textureData;
Texture(int width, int height, void* pixels, bool hasAlpha, uint8_t a2) : m_width(width), m_height(height), m_pixels((uint32_t*)pixels), m_hasAlpha(hasAlpha), field_D(a2) {}
};
2 changes: 1 addition & 1 deletion source/client/renderer/Textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int Textures::assignTexture(const std::string& name, Texture& texture)

GLuint internalFormat = GL_RGB;

if (texture.field_C)
if (texture.m_hasAlpha)
internalFormat = GL_RGBA;

glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, texture.m_width, texture.m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.m_pixels);
Expand Down
11 changes: 6 additions & 5 deletions source/client/renderer/TileRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2388,19 +2388,20 @@ bool TileRenderer::tesselateBlockInWorldWithAmbienceOcclusion(Tile* a2, int a3,
#define SHADE_PREPARE 0
#define SHADE_IF_NEEDED(col) 0
#define SHADE_FIXUP_GRASS(col) 0
#define SHADE_FIXUP_GRASS 0

#endif

void TileRenderer::renderTile(Tile* tile, int data RENDER_TILE_ARG_PATCH)
void TileRenderer::renderTile(Tile* tile, int data, float bright)
{
Tesselator& t = Tesselator::instance;

#ifdef ENH_SHADE_HELD_TILES
t.color(bright, bright, bright);
#else
t.color(255, 255, 255);
#ifndef ENH_SHADE_HELD_TILES
bright = 1.0f; // 255
#endif

t.color(bright, bright, bright);

int shape = tile->getRenderShape();
switch (shape)
{
Expand Down
8 changes: 1 addition & 7 deletions source/client/renderer/TileRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
#include "client/renderer/Chunk.hpp"
#include "client/renderer/Tesselator.hpp"

#ifndef ENH_SHADE_HELD_TILES
#define RENDER_TILE_ARG_PATCH
#else
#define RENDER_TILE_ARG_PATCH , float bright
#endif

class TileRenderer
{
private:
Expand All @@ -26,7 +20,7 @@ class TileRenderer
TileRenderer();
TileRenderer(LevelSource*);
float getWaterHeight(int x, int y, int z, const Material*);
void renderTile(Tile*, int data RENDER_TILE_ARG_PATCH);
void renderTile(Tile*, int data, float bright = 1.0f);

// TODO

Expand Down
4 changes: 4 additions & 0 deletions source/client/renderer/entity/EntityRenderDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ EntityRenderDispatcher::EntityRenderDispatcher() :
m_CameraRenderer.init(this);
m_ItemRenderer.init(this);
m_RocketRenderer.init(this);
#ifdef ENH_ALLOW_SAND_GRAVITY
m_FallingTileRenderer.init(this);
#endif
}

float EntityRenderDispatcher::distanceToSqr(float x, float y, float z)
Expand Down Expand Up @@ -94,9 +96,11 @@ EntityRenderer* EntityRenderDispatcher::getRenderer(int renderType)
return &m_CreeperRenderer;
case RENDER_ROCKET:
return &m_RocketRenderer;
#ifdef ENH_ALLOW_SAND_GRAVITY
// TODO
case RENDER_FALLING_TILE:
return &m_FallingTileRenderer;
#endif
}

return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion source/client/renderer/entity/EntityRenderDispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class EntityRenderDispatcher
Vec3 m_pos;
Font* m_pFont;

#if defined(ENH_ALLOW_SAND_GRAVITY)
#ifdef ENH_ALLOW_SAND_GRAVITY
FallingTileRenderer m_FallingTileRenderer;
#endif

Expand Down
8 changes: 1 addition & 7 deletions source/client/renderer/entity/ItemRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,7 @@ void ItemRenderer::render(Entity* pEntity, float x, float y, float z, float a, f
0.2f * (m_random.nextFloat() * 2.0f - 1.0f) / scale);
}

#ifdef ENH_SHADE_HELD_TILES
# define PARM_HACK , pItemEntity->getBrightness(1.0f)
#else
# define PARM_HACK
#endif
tileRenderer->renderTile(Tile::tiles[itemID], pItemInstance->m_auxValue PARM_HACK);
#undef PARM_HACK
tileRenderer->renderTile(Tile::tiles[itemID], pItemInstance->m_auxValue, pItemEntity->getBrightness(1.0f));
glPopMatrix();
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/client/renderer/entity/TripodCameraRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void TripodCameraRenderer::render(Entity* entity, float x, float y, float z, flo
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// @TODO FIX: With ENH_ENTITY_SHADING on, the cube is fully opaque.
glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
m_modelPart.renderHorrible(0.0625f);
m_modelPart.render(0.0625f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
Expand Down
6 changes: 3 additions & 3 deletions source/common/Random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Random::Random(TLong seed)
{
setSeed(seed);
nextNextGaussian = INFINITY;
nextNextGaussian = std::numeric_limits<double>::max();;
}

void Random::setSeed(TLong seed)
Expand Down Expand Up @@ -109,10 +109,10 @@ int Random::nextInt()

float Random::nextGaussian()
{
if (!isinf(nextNextGaussian))
if (nextNextGaussian < std::numeric_limits<double>::max())
{
double backup = nextNextGaussian;
nextNextGaussian = INFINITY;
nextNextGaussian = std::numeric_limits<double>::max();
return backup;
}
// See Knuth, ACP, Section 3.4.1 Algorithm C.
Expand Down
1 change: 1 addition & 0 deletions source/world/entity/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void Entity::_init()
field_B8 = 0;
field_BC = 300;
field_C0 = 0;
field_C4 = 0;
field_C8 = 0; // @NOTE: Render type? (eEntityRenderType)
m_distanceFallen = 0.0f;
field_D0 = 300;
Expand Down
4 changes: 4 additions & 0 deletions source/world/entity/ItemEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ void ItemEntity::_init(ItemInstance* itemInstance)
field_E8 = 2 * float(M_PI) * Mth::random();
setSize(0.25f, 0.25f);
field_84 = field_8C * 0.5f;
#ifdef ORIGINAL_CODE
m_pItemInstance = itemInstance != nullptr ? itemInstance : new ItemInstance();
#else
m__itemInstance = itemInstance ? *itemInstance : ItemInstance();
m_pItemInstance = &m__itemInstance;
#endif
}

void ItemEntity::_init(ItemInstance* itemInstance, float x, float y, float z)
Expand Down
1 change: 1 addition & 0 deletions source/world/entity/PathfinderMob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

PathfinderMob::PathfinderMob(Level* pLevel) : Mob(pLevel)
{
m_pAttackTarget = nullptr;
field_BA0 = false;
field_BA4 = 0;
}
Expand Down
Loading

0 comments on commit 0dc6bc1

Please sign in to comment.