Skip to content

Commit b3ded17

Browse files
committed
-Refactored code to use enums in different places and renamed methods
-Fixed doors not playing sounds on remote clients -Fixed levers and doors not updating on remote clients -Fixed using without an item bypassing the click interval -Fixed tile destroy sound always using the step sound -Fixed freezing when sneaking
1 parent 1890d04 commit b3ded17

43 files changed

Lines changed: 389 additions & 309 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

source/client/app/Minecraft.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ void Minecraft::handleBuildAction(const BuildActionIntention& action)
343343

344344
player->swing();
345345

346-
if (!pItem) return;
346+
if (!pItem) break;
347347

348348
else if (!pItem->m_count)
349349
{

source/client/gui/screens/InBedChatScreen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ void InBedChatScreen::sendWakeUp()
3939
if (m_pMinecraft->isOnlineClient())
4040
m_pMinecraft->m_pRakNetInstance->send(new PlayerCommandPacket(m_pMinecraft->m_pPlayer->m_EntityID, 3));
4141
else
42-
m_pMinecraft->m_pPlayer->wake(false, true, true);
42+
m_pMinecraft->m_pPlayer->stopSleepInBed(false, true, true);
4343
}

source/client/network/ClientSideNetworkHandler.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,34 +195,34 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, AddEntityP
195195
{
196196
Vec3 pos = PacketUtil::unpackPos(packet->m_pos);
197197
std::shared_ptr<Entity> ent = nullptr;
198-
if (packet->m_addId == ADD_MINECART)
198+
if (packet->m_addId == AddEntityPacket::MINECART)
199199
ent = std::make_shared<Minecart>(m_pLevel, pos, Minecart::Type::DEFAULT);
200-
else if (packet->m_addId == ADD_CHEST_MINECART)
200+
else if (packet->m_addId == AddEntityPacket::CHEST_MINECART)
201201
ent = std::make_shared<Minecart>(m_pLevel, pos, Minecart::Type::CHEST);
202-
else if (packet->m_addId == ADD_FURNACE_MINECART)
202+
else if (packet->m_addId == AddEntityPacket::FURNACE_MINECART)
203203
ent = std::make_shared<Minecart>(m_pLevel, pos, Minecart::Type::FURNACE);
204-
else if (packet->m_addId == ADD_FISHING_HOOK)
204+
else if (packet->m_addId == AddEntityPacket::FISHING_HOOK)
205205
ent = std::make_shared<FishingHook>(m_pLevel, pos);
206-
else if (packet->m_addId == ADD_ARROW)
206+
else if (packet->m_addId == AddEntityPacket::ARROW)
207207
ent = std::make_shared<Arrow>(m_pLevel, pos);
208-
else if (packet->m_addId == ADD_SNOWBALL)
208+
else if (packet->m_addId == AddEntityPacket::SNOWBALL)
209209
ent = std::make_shared<Snowball>(m_pLevel, pos);
210-
else if (packet->m_addId == ADD_FIREBALL)
210+
else if (packet->m_addId == AddEntityPacket::FIREBALL)
211211
{
212212
ent = std::make_shared<Fireball>(m_pLevel, pos, PacketUtil::unpackMotion(packet->m_vel));
213213
packet->m_data = 0;
214214
}
215-
else if (packet->m_addId == ADD_THROWN_EGG)
215+
else if (packet->m_addId == AddEntityPacket::THROWN_EGG)
216216
ent = std::make_shared<ThrownEgg>(m_pLevel, pos);
217-
else if (packet->m_addId == ADD_BOAT)
217+
else if (packet->m_addId == AddEntityPacket::BOAT)
218218
ent = std::make_shared<Boat>(m_pLevel, pos);
219-
else if (packet->m_addId == ADD_PRIMED_TNT)
219+
else if (packet->m_addId == AddEntityPacket::PRIMED_TNT)
220220
ent = std::make_shared<PrimedTnt>(m_pLevel, pos);
221-
else if (packet->m_addId == ADD_LIGHTNING_BOLT)
221+
else if (packet->m_addId == AddEntityPacket::LIGHTNING_BOLT)
222222
ent = std::make_shared<LightningBolt>(m_pLevel, pos);
223-
else if (packet->m_addId == ADD_FALLING_SAND)
223+
else if (packet->m_addId == AddEntityPacket::FALLING_SAND)
224224
ent = std::make_shared<FallingTile>(m_pLevel, pos, Tile::sand->m_ID);
225-
else if (packet->m_addId == ADD_FALLING_GRAVEL)
225+
else if (packet->m_addId == AddEntityPacket::FALLING_GRAVEL)
226226
ent = std::make_shared<FallingTile>(m_pLevel, pos, Tile::gravel->m_ID);
227227

228228
if (ent)
@@ -233,14 +233,14 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, AddEntityP
233233
m_pLevel->putEntity(packet->m_id, ent);
234234
if (packet->m_data > 0)
235235
{
236-
if (packet->m_addId == ADD_ARROW)
236+
if (packet->m_addId == AddEntityPacket::ARROW)
237237
{
238238
std::shared_ptr<Entity> owner = getEntity(packet->m_data);
239239
if (owner->getCategory().contains(EntityCategories::MOB))
240240
std::dynamic_pointer_cast<Arrow>(ent)->m_owner = std::dynamic_pointer_cast<Mob>(owner);
241241
}
242242

243-
if (packet->m_addId == ADD_FISHING_HOOK)
243+
if (packet->m_addId == AddEntityPacket::FISHING_HOOK)
244244
{
245245
std::shared_ptr<Entity> owner = getEntity(packet->m_data);
246246
if (owner->isPlayer())
@@ -347,7 +347,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID&, InteractionPack
347347
{
348348
std::shared_ptr<Entity> ent = getEntity(packet->m_id);
349349
if (ent && packet->m_type == 0)
350-
std::dynamic_pointer_cast<Player>(ent)->sleep(packet->m_pos);
350+
std::dynamic_pointer_cast<Player>(ent)->startSleepInBed(packet->m_pos);
351351
}
352352

353353
void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, AnimatePacket* packet)
@@ -360,7 +360,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, AnimatePac
360360
else if (packet->m_action == 2)
361361
ent->animateHurt();
362362
else if (packet->m_action == 3)
363-
std::dynamic_pointer_cast<Player>(ent)->wake(false, false, false);
363+
std::dynamic_pointer_cast<Player>(ent)->stopSleepInBed(false, false, false);
364364
else if (packet->m_action == 4)
365365
{
366366
//This method is only on client-side, and doesn't do anything for some reason, so we aren't going to implement it
@@ -388,17 +388,17 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, GameEventP
388388
if (!m_pLevel) return;
389389
switch (packet->m_event)
390390
{
391-
case 0:
391+
case GameEventPacket::NO_RESPAWN_TILE_AVAILABLE:
392392
{
393393
if (m_pMinecraft->m_pPlayer)
394394
m_pMinecraft->m_pPlayer->displayClientMessage("tile.bed.notValid");
395395
break;
396396
}
397-
case 1:
397+
case GameEventPacket::START_RAINING:
398398
m_pLevel->getLevelData().setRaining(true);
399399
m_pLevel->setRainLevel(1.0f);
400400
break;
401-
case 2:
401+
case GameEventPacket::STOP_RAINING:
402402
m_pLevel->getLevelData().setRaining(false);
403403
m_pLevel->setRainLevel(0.0f);
404404
break;

source/client/renderer/LevelRenderer.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -959,32 +959,33 @@ void LevelRenderer::playStreamingMusic(const std::string& record, const TilePos&
959959
m_pMinecraft->m_pSoundEngine->playStreaming(record, pos, 1.0F, 1.0F);
960960
}
961961

962-
void LevelRenderer::levelEvent(Player*, int event, const TilePos& pos, int info)
962+
void LevelRenderer::levelEvent(Player*, LevelEvent event, const TilePos& pos, int info)
963963
{
964964
Random& random = m_pLevel->m_random;
965-
switch (event) {
966-
case 1000:
965+
switch (event)
966+
{
967+
case LevelEvent::SOUND_DISPENSER_DISPENSE:
967968
m_pLevel->playSound(pos, "random.click", 1.0F, 1.0F);
968969
break;
969-
case 1001:
970+
case LevelEvent::SOUND_DISPENSER_FAIL:
970971
m_pLevel->playSound(pos, "random.click", 1.0F, 1.2F);
971972
break;
972-
case 1002:
973+
case LevelEvent::SOUND_DISPENSER_PROJECTILE_LAUNCH:
973974
m_pLevel->playSound(pos, "random.bow", 1.0F, 1.2F);
974975
break;
975-
case 1003:
976+
case LevelEvent::SOUND_OPEN_OR_CLOSE:
976977
if (Mth::random() < 0.5)
977978
m_pLevel->playSound(pos.center(), "random.door_open", 1.0F, random.nextFloat() * 0.1F + 0.9F);
978979
else
979980
m_pLevel->playSound(pos.center(), "random.door_close", 1.0F, random.nextFloat() * 0.1F + 0.9F);
980981
break;
981-
case 1004:
982+
case LevelEvent::SOUND_LAVA_FIZZ:
982983
m_pLevel->playSound(pos.center(), "random.fizz", 0.5F, 2.6F + (random.nextFloat() - random.nextFloat()) * 0.8F);
983984
break;
984-
case 1005:
985+
case LevelEvent::SOUND_PLAY_RECORD:
985986
m_pLevel->playStreamingMusic(info ? Item::items[info]->getStreamingMusic() : Util::EMPTY_STRING, pos);
986987
break;
987-
case 2000:
988+
case LevelEvent::PARTICLES_SHOOT_SMOKE:
988989
{
989990
int var8 = info % 3 - 1;
990991
int var9 = info / 3 % 3 - 1;
@@ -1003,13 +1004,13 @@ void LevelRenderer::levelEvent(Player*, int event, const TilePos& pos, int info)
10031004
addParticle("smoke", Vec3(var19, var21, var23), Vec3(var25, var27, var29));
10041005
}
10051006
}
1006-
break;
1007-
case 2001:
1007+
break;
1008+
case LevelEvent::PARTICLES_DESTROY_BLOCK:
10081009
TileID tileID = info & 255;
10091010
if (tileID > 0)
10101011
{
1011-
auto var17 = Tile::tiles[tileID]->m_pSound;
1012-
m_pMinecraft->m_pSoundEngine->play(var17->m_name, pos.center(), (var17->volume + 1.0F) / 2.0F, var17->pitch * 0.8F);
1012+
const Tile::SoundType* sound = Tile::tiles[tileID]->m_pSound;
1013+
m_pMinecraft->m_pSoundEngine->play(sound->m_destroy, pos.center(), (sound->volume + 1.0F) / 2.0F, sound->pitch * 0.8F);
10131014
}
10141015
m_pMinecraft->m_pParticleEngine->destroyEffect(pos, tileID, (info >> 8 & 255));
10151016
break;

source/client/renderer/LevelRenderer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class LevelRenderer : public LevelListener
7676
void entityAdded(const std::shared_ptr<Entity>&) override;
7777
void tileChanged(const TilePos& pos) override;
7878
void playStreamingMusic(const std::string&, const TilePos&) override;
79-
void levelEvent(Player*, int event, const TilePos&, int info) override;
79+
void levelEvent(Player*, LevelEvent event, const TilePos&, int info) override;
8080
void setTilesDirty(const TilePos& min, const TilePos& max) override;
8181
void takePicture(std::shared_ptr<TripodCamera>, Entity*) override;
8282
void addParticle(const std::string&, const Vec3& pos, const Vec3& dir) override;

source/client/renderer/TileRenderer.cpp

Lines changed: 79 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,113 +1297,129 @@ bool TileRenderer::tesselateFireInWorld(Tile* tile, const TilePos& pos)
12971297
bool TileRenderer::tesselateBedInWorld(Tile* tile, const TilePos& pos)
12981298
{
12991299
Tesselator& t = Tesselator::instance;
1300-
int var6 = m_pLevelSource->getData(pos);
1301-
int var7 = BedTile::getDirectionFromData(var6);
1302-
bool var8 = BedTile::isHead(var6);
1303-
float var9 = 0.5F;
1304-
float var10 = 1.0F;
1305-
float var11 = 0.8F;
1306-
float var12 = 0.6F;
1307-
float fLightHere = tile->getBrightness(m_pLevelSource, pos);
1308-
t.color(var9 * fLightHere, var9 * fLightHere, var9 * fLightHere);
1309-
int hiddenFace = Tile::wood->m_TextureFrame;
1310-
int var27 = (hiddenFace & 15) << 4;
1311-
int var28 = hiddenFace & 240;
1312-
float var29 = ((float)var27 / 256.0F);
1313-
float var31 = ((var27 + 16) - 0.01) / 256.0;
1314-
float var33 = ((float)var28 / 256.0F);
1315-
float var35 = ((var28 + 16) - 0.01) / 256.0;
1316-
real var37 = pos.x + tile->m_aabb.min.x;
1317-
real var39 = pos.x + tile->m_aabb.max.x;
1318-
real var41 = pos.y + tile->m_aabb.min.y + 0.1875;
1319-
real var43 = pos.z + tile->m_aabb.min.z;
1320-
real var45 = pos.z + tile->m_aabb.max.z;
1321-
bool z9 = m_textureOverride >= 0;
1322-
if (!z9) {
1323-
t.vertexUV(var37, var41, var45, var29, var35);
1324-
t.vertexUV(var37, var41, var43, var29, var33);
1325-
t.vertexUV(var39, var41, var43, var31, var33);
1326-
t.vertexUV(var39, var41, var45, var31, var35);
1327-
}
1328-
1329-
float var64 = tile->getBrightness(m_pLevelSource, pos.above());
1330-
t.color(var10 * var64, var10 * var64, var10 * var64);
1331-
var27 = tile->getTexture(m_pLevelSource, pos, Facing::UP);
1332-
var28 = (var27 & 15) << 4;
1333-
int var67 = var27 & 240;
1334-
hiddenFace = BedTile::hiddenFace[var7];
1335-
if (var8) {
1336-
hiddenFace = BedTile::hiddenFace[BedTile::hiddenFaceIndex[var7]];
1300+
1301+
int data = m_pLevelSource->getData(pos);
1302+
Facing::Name direction = BedTile::getDirectionFromData(data);
1303+
bool isHeadPart = BedTile::isHead(data);
1304+
1305+
const float topColor = 0.5F;
1306+
const float sideColor = 0.8F;
1307+
const float bottomColor = 0.6F;
1308+
1309+
float brightnessHere = tile->getBrightness(m_pLevelSource, pos);
1310+
1311+
t.color(topColor * brightnessHere, topColor * brightnessHere, topColor * brightnessHere);
1312+
1313+
int woodTexture = Tile::wood->m_TextureFrame;
1314+
int textureU = (woodTexture & 15) << 4;
1315+
int textureV = woodTexture & 240;
1316+
1317+
const float uMin = static_cast<float>(textureU) / 256.0F;
1318+
const float uMax = (textureU + 16 - 0.01F) / 256.0F;
1319+
const float vMin = static_cast<float>(textureV) / 256.0F;
1320+
const float vMax = (textureV + 16 - 0.01F) / 256.0F;
1321+
1322+
float xMin = pos.x + tile->m_aabb.min.x;
1323+
float xMax = pos.x + tile->m_aabb.max.x;
1324+
float yTop = pos.y + tile->m_aabb.min.y + 0.1875F;
1325+
float zMin = pos.z + tile->m_aabb.min.z;
1326+
float zMax = pos.z + tile->m_aabb.max.z;
1327+
1328+
bool hasTextureOverride = m_textureOverride >= 0;
1329+
1330+
if (!hasTextureOverride)
1331+
{
1332+
t.vertexUV(xMin, yTop, zMax, uMin, vMax);
1333+
t.vertexUV(xMin, yTop, zMin, uMin, vMin);
1334+
t.vertexUV(xMax, yTop, zMin, uMax, vMin);
1335+
t.vertexUV(xMax, yTop, zMax, uMax, vMax);
13371336
}
13381337

1338+
float brightnessAbove = tile->getBrightness(m_pLevelSource, pos.above());
1339+
t.color(brightnessAbove, brightnessAbove, brightnessAbove);
1340+
1341+
int topTexture = tile->getTexture(m_pLevelSource, pos, Facing::UP);
1342+
int topU = (topTexture & 15) << 4;
1343+
int topV = topTexture & 240;
1344+
1345+
int hiddenFace = BedTile::hiddenFace[direction];
1346+
if (isHeadPart)
1347+
hiddenFace = BedTile::hiddenFace[BedTile::hiddenFaceIndex[direction]];
1348+
13391349
Facing::Name flippedFace = Facing::WEST;
1340-
uint8_t upRot = 2;
1341-
switch (var7) {
1342-
case 0:
1350+
int upRotation = 2;
1351+
1352+
switch (direction)
1353+
{
1354+
case Facing::DOWN:
13431355
flippedFace = Facing::EAST;
1344-
upRot = 1;
1356+
upRotation = 1;
13451357
break;
1346-
case 1:
1358+
case Facing::UP:
13471359
flippedFace = Facing::SOUTH;
1348-
upRot = 3;
1349-
case 2:
1350-
default:
1360+
upRotation = 3;
13511361
break;
1352-
case 3:
1362+
case Facing::NORTH:
1363+
break;
1364+
case Facing::SOUTH:
13531365
flippedFace = Facing::NORTH;
1354-
upRot = 0;
1366+
upRotation = 0;
1367+
break;
13551368
}
13561369

1357-
bool bDrewAnything = false;
1370+
bool drewAnything = false;
13581371

13591372
for (Facing::Name face : Facing::ALL)
13601373
{
1361-
if (hiddenFace == face || face == Facing::DOWN) continue;
1374+
if (hiddenFace == face || face == Facing::DOWN)
1375+
continue;
13621376

13631377
TilePos neighborPos = pos.relative(face);
13641378

13651379
if (!m_bDisableCulling && !tile->shouldRenderFace(m_pLevelSource, neighborPos, face))
13661380
continue;
13671381

1368-
bDrewAnything = true;
1382+
drewAnything = true;
13691383

1370-
float light = tile->getBrightness(m_pLevelSource, neighborPos);
1384+
float faceBrightness = tile->getBrightness(m_pLevelSource, neighborPos);
13711385

1372-
switch (face) {
1386+
switch (face)
1387+
{
13731388
case Facing::UP:
13741389
if (tile->m_aabb.max.y != 1.0f && !tile->m_pMaterial->isLiquid())
1375-
light = fLightHere;
1390+
faceBrightness = brightnessHere;
13761391
break;
13771392
case Facing::NORTH:
13781393
if (tile->m_aabb.min.z > 0.0f)
1379-
light = fLightHere;
1394+
faceBrightness = brightnessHere;
13801395
break;
13811396
case Facing::SOUTH:
13821397
if (tile->m_aabb.max.z < 1.0f)
1383-
light = fLightHere;
1398+
faceBrightness = brightnessHere;
13841399
break;
13851400
case Facing::WEST:
13861401
if (tile->m_aabb.min.x > 0.0f)
1387-
light = fLightHere;
1402+
faceBrightness = brightnessHere;
13881403
break;
13891404
case Facing::EAST:
13901405
if (tile->m_aabb.max.x < 1.0f)
1391-
light = fLightHere;
1406+
faceBrightness = brightnessHere;
13921407
break;
13931408
default:
13941409
break;
13951410
}
13961411

1397-
int texture = tile->getTexture(m_pLevelSource, pos, face);
1412+
int faceTexture = tile->getTexture(m_pLevelSource, pos, face);
1413+
if (flippedFace == face)
1414+
faceTexture = -faceTexture;
13981415

1399-
if (flippedFace == face) texture = -texture;
1400-
float red, grn, blue;
1401-
computeColor(tile->getColor(m_pLevelSource, pos, face, texture), red, grn, blue, Facing::LIGHT[face] * light);
1416+
float red, green, blue;
1417+
computeColor(tile->getColor(m_pLevelSource, pos, face, faceTexture), red, green, blue, Facing::LIGHT[face] * faceBrightness);
14021418

1403-
renderFace(tile, pos, texture, face, red, grn, blue, face == Facing::UP ? upRot : 0);
1419+
renderFace(tile, pos, faceTexture, face, red, green, blue, face == Facing::UP ? upRotation : 0);
14041420
}
14051421

1406-
return bDrewAnything;
1422+
return drewAnything;
14071423
}
14081424

14091425
bool TileRenderer::tesselateDustInWorld(Tile* tile, const TilePos& pos)

source/client/sound/SoundEngine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ void SoundEngine::init(Options* options, AppPlatform* plat)
5050
addSound("step.gravel", "sound/step/gravel3.ogg");
5151
addSound("step.gravel", "sound/step/gravel4.ogg");
5252

53-
addSound("step.sand", "sound/step/sand1.ogg");
54-
addSound("step.sand", "sound/step/sand2.ogg");
55-
addSound("step.sand", "sound/step/sand3.ogg");
56-
addSound("step.sand", "sound/step/sand4.ogg");
53+
addSound("step.sand", "newsound/step/sand1.ogg");
54+
addSound("step.sand", "newsound/step/sand2.ogg");
55+
addSound("step.sand", "newsound/step/sand3.ogg");
56+
addSound("step.sand", "newsound/step/sand4.ogg");
5757

5858
addSound("step.cloth", "sound/step/cloth1.ogg");
5959
addSound("step.cloth", "sound/step/cloth2.ogg");

0 commit comments

Comments
 (0)