Merge remote-tracking branch 'origin/issue/51-phase-1-portable-win32-cleanup' into issue/51-phase-1-portable-win32-cleanup

This commit is contained in:
notmatthewbeshay 2026-03-13 15:12:53 +11:00
commit e3d910c6a1
20 changed files with 272 additions and 179 deletions

View file

@ -32,7 +32,7 @@ jobs:
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential python3 ninja-build meson libsdl2-dev libgl-dev libglu1-mesa-dev libpthread-stubs0-dev
sudo apt-get install -y build-essential ccache python3 ninja-build meson libsdl2-dev libgl-dev libglu1-mesa-dev libpthread-stubs0-dev
# Set a reasonable ccache size
ccache -M 5G || true
@ -86,7 +86,7 @@ jobs:
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential python3 ninja-build meson libsdl2-dev libgl-dev libglu1-mesa-dev libpthread-stubs0-dev
sudo apt-get install -y build-essential ccache python3 ninja-build meson libsdl2-dev libgl-dev libglu1-mesa-dev libpthread-stubs0-dev
# Set a reasonable ccache size
ccache -M 5G || true

3
.gitignore vendored
View file

@ -6,6 +6,9 @@ builddir/
build_meson/
cmake-build-debug/
# Nix flake output
result
# Final binaries and platform output
/Linux/
/x64/

View file

@ -215,7 +215,8 @@ bool C_4JInput::ButtonDown(int iPad, unsigned char ucAction) {
switch (ucAction) {
case MINECRAFT_ACTION_ACTION: return MouseLDown() || KDown(SDL_SCANCODE_RETURN);
case MINECRAFT_ACTION_USE: return MouseRDown() || KDown(SDL_SCANCODE_F);
case MINECRAFT_ACTION_SNEAK_TOGGLE: return KDown(SDL_SCANCODE_LSHIFT) || KDown(SDL_SCANCODE_RSHIFT) || KDown(SDL_SCANCODE_LCTRL) || KDown(SDL_SCANCODE_RCTRL);
case MINECRAFT_ACTION_SNEAK_TOGGLE: return KDown(SDL_SCANCODE_LSHIFT) || KDown(SDL_SCANCODE_RSHIFT);
case MINECRAFT_ACTION_SPRINT: return KDown(SDL_SCANCODE_LCTRL) || KDown(SDL_SCANCODE_RCTRL);
case MINECRAFT_ACTION_LEFT_SCROLL:
case ACTION_MENU_LEFT_SCROLL: return ScrollSnap() > 0;
case MINECRAFT_ACTION_RIGHT_SCROLL:
@ -229,7 +230,8 @@ bool C_4JInput::ButtonPressed(int iPad, unsigned char ucAction) {
switch (ucAction) {
case MINECRAFT_ACTION_ACTION: return MouseLPressed() || KPressed(SDL_SCANCODE_RETURN);
case MINECRAFT_ACTION_USE: return MouseRPressed() || KPressed(SDL_SCANCODE_F);
case MINECRAFT_ACTION_SNEAK_TOGGLE: return KPressed(SDL_SCANCODE_LSHIFT) || KPressed(SDL_SCANCODE_RSHIFT) || KPressed(SDL_SCANCODE_LCTRL) || KPressed(SDL_SCANCODE_RCTRL);
case MINECRAFT_ACTION_SNEAK_TOGGLE: return KPressed(SDL_SCANCODE_LSHIFT) || KPressed(SDL_SCANCODE_RSHIFT);
case MINECRAFT_ACTION_SPRINT: return KPressed(SDL_SCANCODE_LCTRL) || KPressed(SDL_SCANCODE_RCTRL);
case MINECRAFT_ACTION_LEFT_SCROLL:
case ACTION_MENU_LEFT_SCROLL: return ScrollSnap() > 0;
case MINECRAFT_ACTION_RIGHT_SCROLL:
@ -243,7 +245,8 @@ bool C_4JInput::ButtonReleased(int iPad, unsigned char ucAction) {
switch (ucAction) {
case MINECRAFT_ACTION_ACTION: return MouseLReleased() || KReleased(SDL_SCANCODE_RETURN);
case MINECRAFT_ACTION_USE: return MouseRReleased() || KReleased(SDL_SCANCODE_F);
case MINECRAFT_ACTION_SNEAK_TOGGLE: return KReleased(SDL_SCANCODE_LSHIFT) || KReleased(SDL_SCANCODE_RSHIFT) || KReleased(SDL_SCANCODE_LCTRL) || KReleased(SDL_SCANCODE_RCTRL);
case MINECRAFT_ACTION_SNEAK_TOGGLE: return KReleased(SDL_SCANCODE_LSHIFT) || KReleased(SDL_SCANCODE_RSHIFT);
case MINECRAFT_ACTION_SPRINT: KReleased(SDL_SCANCODE_LCTRL) || KReleased(SDL_SCANCODE_RCTRL);
case MINECRAFT_ACTION_LEFT_SCROLL:
case ACTION_MENU_LEFT_SCROLL:
case MINECRAFT_ACTION_RIGHT_SCROLL:

View file

@ -15,6 +15,7 @@ Input::Input()
wasJumping = false;
jumping = false;
sneaking = false;
sprintKey = false;
lReset = false;
rReset = false;
@ -103,12 +104,8 @@ void Input::tick(LocalPlayer *player)
//jumping = controller.isButtonPressed(0);
unsigned int jump = InputManager.GetValue(iPad, MINECRAFT_ACTION_JUMP);
if( jump > 0 && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP) )
jumping = true;
else
jumping = false;
sprintKey = InputManager.GetValue(iPad, MINECRAFT_ACTION_SPRINT) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_SPRINT);
jumping = InputManager.GetValue(iPad, MINECRAFT_ACTION_JUMP) && pMinecraft->localgameModes[iPad]->isInputAllowed(MINECRAFT_ACTION_JUMP);
#ifndef _CONTENT_PACKAGE
if (app.GetFreezePlayers()) jumping = false;

View file

@ -10,6 +10,7 @@ public:
bool wasJumping;
bool jumping;
bool sneaking;
bool sprintKey;
Input(); // 4J - added
virtual ~Input(){}

View file

@ -828,6 +828,7 @@ enum EControllerActions
MINECRAFT_ACTION_PAUSEMENU,
MINECRAFT_ACTION_DROP,
MINECRAFT_ACTION_SNEAK_TOGGLE,
MINECRAFT_ACTION_SPRINT,
MINECRAFT_ACTION_CRAFTING,
MINECRAFT_ACTION_RENDER_THIRD_PERSON,
MINECRAFT_ACTION_GAME_INFO,

View file

@ -305,7 +305,7 @@ void LocalPlayer::aiStep()
// 4J - altered this slightly to make sure that the joypad returns to below returnTreshold in between registering two movements up to runThreshold
if (onGround && !isSprinting() && enoughFoodToSprint && !isUsingItem() && !hasEffect(MobEffect::blindness))
{
if( !wasRunning && input->ya >= runTreshold )
if( !wasRunning && (input->ya >= runTreshold) )
{
if (sprintTriggerTime == 0)
{
@ -326,14 +326,18 @@ void LocalPlayer::aiStep()
{
sprintTriggerRegisteredReturn = true;
}
else if (input->sprintKey)
{
setSprinting(true);
}
}
if (isSneaking()) sprintTriggerTime = 0;
// 4J-PB - try not stopping sprint on collision
//if (isSprinting() && (input->ya < runTreshold || horizontalCollision || !enoughFoodToSprint))
if (isSprinting() && (input->ya < runTreshold || !enoughFoodToSprint))
if (isSprinting() && ((input->ya < runTreshold && !input->sprintKey) || !enoughFoodToSprint))
{
setSprinting(false);
}
}
// 4J Stu - Fix for #52705 - Customer Encountered: Player can fly in bed while being in Creative mode.
if (!isSleeping() && (abilities.mayfly || isAllowedToFly() ))

View file

@ -1756,7 +1756,8 @@ void GameRenderer::renderSnowAndRain(float a)
t->color(br, br, br, ((1 - dd * dd) * 0.5f + 0.5f) * rainLevel);
t->vertexUV(x - xa + 0.5, yy0, z - za + 0.5, 0 * s, yy0 * s / 4.0f + ra * s);
t->vertexUV(x + xa + 0.5, yy0, z + za + 0.5, 1 * s, yy0 * s / 4.0f + ra * s);
t->color(br, br, br, 0.0f); // 4J - added to soften the top visible edge of the rain
// 4jcraft: this color call made rain invisible
// t->color(br, br, br, 0.0f); // 4J - added to soften the top visible edge of the rain
t->vertexUV(x + xa + 0.5, yy1, z + za + 0.5, 1 * s, yy1 * s / 4.0f + ra * s);
t->vertexUV(x - xa + 0.5, yy1, z - za + 0.5, 0 * s, yy1 * s / 4.0f + ra * s);
#endif

View file

@ -743,7 +743,7 @@ int LevelRenderer::renderChunks(int from, int to, int layer, double alpha)
#if 1
// 4J - cut down version, we're not using offsetted render lists, or a sorted chunk list, anymore
mc->gameRenderer->turnOnLightLayer(alpha); // 4J - brought forward from 1.8.2
shared_ptr<Mob> player = mc->cameraTargetPlayer;
std::shared_ptr<Mob> player = mc->cameraTargetPlayer;
double xOff = player->xOld + (player->x - player->xOld) * alpha;
double yOff = player->yOld + (player->y - player->yOld) * alpha;
double zOff = player->zOld + (player->z - player->zOld) * alpha;
@ -1559,15 +1559,16 @@ void LevelRenderer::renderAdvancedClouds(float alpha)
// This is because the complex sort of rendering is really there so that the clouds seem more solid when you might be in them, but it has more risk of artifacts so
// we don't want to do it when not necessary
bool noBFCMode = ( (yy > -h - 1) && (yy <= h + 1) );
if( noBFCMode )
{
glDisable(GL_CULL_FACE);
}
else
{
glEnable(GL_CULL_FACE);
}
// 4jcraft: not needed for the tesselator-based implementation
// bool noBFCMode = ( (yy > -h - 1) && (yy <= h + 1) );
// if( noBFCMode )
// {
// glDisable(GL_CULL_FACE);
// }
// else
// {
// glEnable(GL_CULL_FACE);
// }
MemSect(31);
textures->bindTexture(TN_ENVIRONMENT_CLOUDS); // 4J was L"/environment/clouds.png"
@ -1632,7 +1633,9 @@ void LevelRenderer::renderAdvancedClouds(float alpha)
{
// 4J - reimplemented the clouds with full cube-per-texel geometry to get rid of seams. This is a huge amount more quads to render, so
// now using command buffers to render each section to cut CPU hit.
#if 1
// 4jcraft: switch back to the tesselator-based implementation of cloud renders
#if 0
float xx = (float)(xPos * D);
float zz = (float)(zPos * D);
float xp = xx - xoffs;
@ -1707,7 +1710,7 @@ void LevelRenderer::renderAdvancedClouds(float alpha)
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
#else
glDisable(GL_CULL_FACE);
t->begin();
float xx = (float)(xPos * D);
float zz = (float)(zPos * D);

View file

@ -79,7 +79,7 @@ void Minimap::reloadColours()
int b = ((color) & 0xff) * br / 255;
// 4J - changed byte order to save having to reorder later
#if ( defined _DURANGO || defined _WIN64 || __PSVITA__ )
#if ( defined _DURANGO || defined _WIN64 || __PSVITA__ || __linux__ )
LUT[i] = 255 << 24 | b << 16 | g << 8 | r;
#elif defined _XBOX
LUT[i] = 255 << 24 | r << 16 | g << 8 | b;

View file

@ -4,7 +4,7 @@
#include "PacketListener.h"
#include "MoveEntityPacket.h"
MoveEntityPacket::MoveEntityPacket()
MoveEntityPacket::MoveEntityPacket()
{
hasRot = false;
@ -28,7 +28,7 @@ MoveEntityPacket::MoveEntityPacket(int id)
xRot = 0;
}
void MoveEntityPacket::read(DataInputStream *dis) //throws IOException
void MoveEntityPacket::read(DataInputStream *dis) //throws IOException
{
id = dis->readShort();
}
@ -48,7 +48,7 @@ void MoveEntityPacket::handle(PacketListener *listener)
listener->handleMoveEntity(shared_from_this());
}
int MoveEntityPacket::getEstimatedSize()
int MoveEntityPacket::getEstimatedSize()
{
return 2;
}
@ -69,66 +69,66 @@ MoveEntityPacket::PosRot::PosRot()
hasRot = true;
}
MoveEntityPacket::PosRot::PosRot(int id, int8_t xa, int8_t ya, int8_t za, int8_t yRot, int8_t xRot) : MoveEntityPacket( id )
MoveEntityPacket::PosRot::PosRot(int id, char xa, char ya, char za, char yRot, char xRot) : MoveEntityPacket( id )
{
this->xa = xa;
this->ya = ya;
this->za = za;
this->yRot = yRot;
this->xRot = xRot;
this->xa = xa;
this->ya = ya;
this->za = za;
this->yRot = yRot;
this->xRot = xRot;
hasRot = true;
}
void MoveEntityPacket::PosRot::read(DataInputStream *dis) //throws IOException
void MoveEntityPacket::PosRot::read(DataInputStream *dis) //throws IOException
{
MoveEntityPacket::read(dis);
xa = (int8_t)dis->readByte();
ya = (int8_t)dis->readByte();
za = (int8_t)dis->readByte();
yRot = (int8_t)dis->readByte();
xRot = (int8_t)dis->readByte();
xa = (int)dis->readByte();
ya = (int)dis->readByte();
za = (int)dis->readByte();
yRot = (int)dis->readByte();
xRot = (int)dis->readByte();
}
void MoveEntityPacket::PosRot::write(DataOutputStream *dos) //throws IOException
void MoveEntityPacket::PosRot::write(DataOutputStream *dos) //throws IOException
{
MoveEntityPacket::write(dos);
dos->writeByte((uint8_t)(xa & 0xFF));
dos->writeByte((uint8_t)(ya & 0xFF));
dos->writeByte((uint8_t)(za & 0xFF));
dos->writeByte((uint8_t)(yRot & 0xFF));
dos->writeByte((uint8_t)(xRot & 0xFF));
dos->writeByte((uint8_t)xa);
dos->writeByte((uint8_t)ya);
dos->writeByte((uint8_t)za);
dos->writeByte((uint8_t)yRot);
dos->writeByte((uint8_t)xRot);
}
int MoveEntityPacket::PosRot::getEstimatedSize()
int MoveEntityPacket::PosRot::getEstimatedSize()
{
return 2+5;
}
MoveEntityPacket::Pos::Pos()
MoveEntityPacket::Pos::Pos()
{
}
MoveEntityPacket::Pos::Pos(int id, int8_t xa, int8_t ya, int8_t za) : MoveEntityPacket(id)
MoveEntityPacket::Pos::Pos(int id, char xa, char ya, char za) : MoveEntityPacket(id)
{
this->xa = xa;
this->ya = ya;
this->za = za;
}
void MoveEntityPacket::Pos::read(DataInputStream *dis) //throws IOException
void MoveEntityPacket::Pos::read(DataInputStream *dis) //throws IOException
{
MoveEntityPacket::read(dis);
xa = (int8_t)dis->readByte();
ya = (int8_t)dis->readByte();
za = (int8_t)dis->readByte();
xa = (int)dis->readByte();
ya = (int)dis->readByte();
za = (int)dis->readByte();
}
void MoveEntityPacket::Pos::write(DataOutputStream *dos) //throws IOException
{
MoveEntityPacket::write(dos);
dos->writeByte((uint8_t)(xa & 0xFF));
dos->writeByte((uint8_t)(ya & 0xFF));
dos->writeByte((uint8_t)(za & 0xFF));
dos->writeByte((uint8_t)xa);
dos->writeByte((uint8_t)ya);
dos->writeByte((uint8_t)za);
}
int MoveEntityPacket::Pos::getEstimatedSize()
@ -136,30 +136,30 @@ int MoveEntityPacket::Pos::getEstimatedSize()
return 2+3;
}
MoveEntityPacket::Rot::Rot()
MoveEntityPacket::Rot::Rot()
{
hasRot = true;
}
MoveEntityPacket::Rot::Rot(int id, int8_t yRot, int8_t xRot) : MoveEntityPacket(id)
MoveEntityPacket::Rot::Rot(int id, char yRot, char xRot) : MoveEntityPacket(id)
{
this->yRot = yRot;
this->xRot = xRot;
hasRot = true;
}
void MoveEntityPacket::Rot::read(DataInputStream *dis) //throws IOException
void MoveEntityPacket::Rot::read(DataInputStream *dis) //throws IOException
{
MoveEntityPacket::read(dis);
yRot = (int8_t)dis->readByte();
xRot = (int8_t)dis->readByte();
yRot = (int)dis->readByte();
xRot = (int)dis->readByte();
}
void MoveEntityPacket::Rot::write(DataOutputStream *dos) //throws IOException
void MoveEntityPacket::Rot::write(DataOutputStream *dos) //throws IOException
{
MoveEntityPacket::write(dos);
dos->writeByte((uint8_t)(yRot & 0xFF));
dos->writeByte((uint8_t)(xRot & 0xFF));
dos->writeByte((uint8_t)yRot);
dos->writeByte((uint8_t)xRot);
}
int MoveEntityPacket::Rot::getEstimatedSize()

View file

@ -13,7 +13,7 @@ public:
class Rot;
int id;
int8_t xa, ya, za, yRot, xRot;
char xa, ya, za, yRot, xRot;
bool hasRot;
MoveEntityPacket();
@ -35,7 +35,7 @@ class MoveEntityPacket::PosRot : public MoveEntityPacket
{
public:
PosRot();
PosRot(int id, int8_t xa, int8_t ya, int8_t za, int8_t yRot, int8_t xRot);
PosRot(int id, char xa, char ya, char za, char yRot, char xRot);
virtual void read(DataInputStream *dis);
virtual void write(DataOutputStream *dos);
@ -50,7 +50,7 @@ class MoveEntityPacket::Pos : public MoveEntityPacket
{
public:
Pos();
Pos(int id, int8_t xa, int8_t ya, int8_t za);
Pos(int id, char xa, char ya, char za);
virtual void read(DataInputStream *dis);
virtual void write(DataOutputStream *dos);
@ -65,7 +65,7 @@ class MoveEntityPacket::Rot : public MoveEntityPacket
{
public:
Rot();
Rot(int id, int8_t yRot, int8_t xRot);
Rot(int id, char yRot, char xRot);
virtual void read(DataInputStream *dis);
virtual void write(DataOutputStream *dos);

View file

@ -1,6 +1,5 @@
#include "../../Platform/stdafx.h"
#include <iostream>
#include <limits>
#include "../../IO/Streams/InputOutputStream.h"
#include "PacketListener.h"
#include "MoveEntityPacketSmall.h"
@ -20,19 +19,30 @@ MoveEntityPacketSmall::MoveEntityPacketSmall()
MoveEntityPacketSmall::MoveEntityPacketSmall(int id)
{
if( (id < 0 ) || (id >= 2048 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();
}
this->id = id;
hasRot = false;
xa = ya = za = yRot = xRot = 0;
xa = 0;
ya = 0;
za = 0;
yRot = 0;
xRot = 0;
}
void MoveEntityPacketSmall::read(DataInputStream *dis) //throws IOException
void MoveEntityPacketSmall::read(DataInputStream *dis) //throws IOException
{
id = dis->readShort();
}
void MoveEntityPacketSmall::write(DataOutputStream *dos) //throws IOException
{
if(id < 0 || id > std::numeric_limits<int16_t>::max() )
if( (id < 0 ) || (id >= 2048 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();
@ -45,7 +55,7 @@ void MoveEntityPacketSmall::handle(PacketListener *listener)
listener->handleMoveEntitySmall(shared_from_this());
}
int MoveEntityPacketSmall::getEstimatedSize()
int MoveEntityPacketSmall::getEstimatedSize()
{
return 2;
}
@ -66,7 +76,7 @@ MoveEntityPacketSmall::PosRot::PosRot()
hasRot = true;
}
MoveEntityPacketSmall::PosRot::PosRot(int id, int8_t xa, int8_t ya, int8_t za, int8_t yRot, int8_t xRot) : MoveEntityPacketSmall( id )
MoveEntityPacketSmall::PosRot::PosRot(int id, char xa, char ya, char za, char yRot, char xRot) : MoveEntityPacketSmall( id )
{
this->xa = xa;
this->ya = ya;
@ -76,69 +86,80 @@ MoveEntityPacketSmall::PosRot::PosRot(int id, int8_t xa, int8_t ya, int8_t za, i
hasRot = true;
}
void MoveEntityPacketSmall::PosRot::read(DataInputStream *dis) //throws IOException
void MoveEntityPacketSmall::PosRot::read(DataInputStream *dis) //throws IOException
{
MoveEntityPacketSmall::read(dis);
xa = (int8_t)dis->readByte();
ya = (int8_t)dis->readByte();
za = (int8_t)dis->readByte();
yRot = (int8_t)dis->readByte();
xRot = (int8_t)dis->readByte();
int idAndRot = dis->readShort();
this->id = idAndRot & 0x07ff;
this->yRot = idAndRot >> 11;
int xAndYAndZ = (int)dis->readShort();
this->xa = xAndYAndZ >> 11;
this->ya = (xAndYAndZ << 21 ) >> 26;
this->za = (xAndYAndZ << 27 ) >> 27;
}
void MoveEntityPacketSmall::PosRot::write(DataOutputStream *dos) //throws IOException
void MoveEntityPacketSmall::PosRot::write(DataOutputStream *dos) //throws IOException
{
MoveEntityPacketSmall::write(dos);
dos->writeByte((uint8_t)(xa & 0xFF));
dos->writeByte((uint8_t)(ya & 0xFF));
dos->writeByte((uint8_t)(za & 0xFF));
dos->writeByte((uint8_t)(yRot & 0xFF));
dos->writeByte((uint8_t)(xRot & 0xFF));
if( (id < 0 ) || (id >= 2048 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();
}
short idAndRot = id | yRot << 11;
dos->writeShort(idAndRot);
short xAndYAndZ = ( xa << 11 ) | ( ( ya & 0x3f ) << 5 ) | ( za & 0x1f );
dos->writeShort(xAndYAndZ);
}
int MoveEntityPacketSmall::PosRot::getEstimatedSize()
int MoveEntityPacketSmall::PosRot::getEstimatedSize()
{
return 2+5;
return 4;
}
MoveEntityPacketSmall::Pos::Pos()
MoveEntityPacketSmall::Pos::Pos()
{
}
MoveEntityPacketSmall::Pos::Pos(int id, int8_t xa, int8_t ya, int8_t za) : MoveEntityPacketSmall(id)
MoveEntityPacketSmall::Pos::Pos(int id, char xa, char ya, char za) : MoveEntityPacketSmall(id)
{
this->xa = xa;
this->ya = ya;
this->za = za;
}
void MoveEntityPacketSmall::Pos::read(DataInputStream *dis) //throws IOException
void MoveEntityPacketSmall::Pos::read(DataInputStream *dis) //throws IOException
{
MoveEntityPacketSmall::read(dis);
xa = (int8_t)dis->readByte();
ya = (int8_t)dis->readByte();
za = (int8_t)dis->readByte();
int idAndY = dis->readShort();
this->id = idAndY & 0x07ff;
this->ya = idAndY >> 11;
int XandZ = (int)((signed char)(dis->readByte()));
xa = XandZ >> 4;
za = ( XandZ << 28 ) >> 28;
}
void MoveEntityPacketSmall::Pos::write(DataOutputStream *dos) //throws IOException
{
MoveEntityPacketSmall::write(dos);
dos->writeByte((uint8_t)(xa & 0xFF));
dos->writeByte((uint8_t)(ya & 0xFF));
dos->writeByte((uint8_t)(za & 0xFF));
if( (id < 0 ) || (id >= 2048 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();
}
short idAndY = id | ya << 11;
dos->writeShort(idAndY);
char XandZ = ( xa << 4 ) | ( za & 0x0f );
dos->writeByte((uint8_t)XandZ);
}
int MoveEntityPacketSmall::Pos::getEstimatedSize()
{
return 2+3;
return 3;
}
MoveEntityPacketSmall::Rot::Rot()
MoveEntityPacketSmall::Rot::Rot()
{
hasRot = true;
}
MoveEntityPacketSmall::Rot::Rot(int id, int8_t yRot, int8_t xRot) : MoveEntityPacketSmall(id)
MoveEntityPacketSmall::Rot::Rot(int id, char yRot, char xRot) : MoveEntityPacketSmall(id)
{
this->yRot = yRot;
@ -146,19 +167,25 @@ MoveEntityPacketSmall::Rot::Rot(int id, int8_t yRot, int8_t xRot) : MoveEntityPa
hasRot = true;
}
void MoveEntityPacketSmall::Rot::read(DataInputStream *dis) //throws IOException
void MoveEntityPacketSmall::Rot::read(DataInputStream *dis) //throws IOException
{
MoveEntityPacketSmall::read(dis);
yRot = (int8_t)dis->readByte();
int idAndRot = (int)dis->readShort();
this->id = idAndRot & 0x07ff;
this->yRot = idAndRot >> 11;
}
void MoveEntityPacketSmall::Rot::write(DataOutputStream *dos) //throws IOException
void MoveEntityPacketSmall::Rot::write(DataOutputStream *dos) //throws IOException
{
MoveEntityPacketSmall::write(dos);
dos->writeByte((uint8_t)(yRot & 0xFF));
if( (id < 0 ) || (id >= 2048 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();
}
short idAndRot = id | yRot << 11;
dos->writeShort(idAndRot);
}
int MoveEntityPacketSmall::Rot::getEstimatedSize()
{
return 2+1;
return 2;
}

View file

@ -13,8 +13,8 @@ public:
class Rot;
int id;
int8_t xa, ya, za, yRot, xRot;
bool hasRot;
char xa, ya, za, yRot, xRot;
bool hasRot;
MoveEntityPacketSmall();
MoveEntityPacketSmall(int id);
@ -34,8 +34,8 @@ public:
class MoveEntityPacketSmall::PosRot : public MoveEntityPacketSmall
{
public:
PosRot();
PosRot(int id, int8_t xa, int8_t ya, int8_t za, int8_t yRot, int8_t xRot);
PosRot();
PosRot(int id, char xa, char ya, char za, char yRot, char xRot);
virtual void read(DataInputStream *dis);
virtual void write(DataOutputStream *dos);
@ -50,7 +50,7 @@ class MoveEntityPacketSmall::Pos : public MoveEntityPacketSmall
{
public:
Pos();
Pos(int id, int8_t xa, int8_t ya, int8_t za);
Pos(int id, char xa, char ya, char za);
virtual void read(DataInputStream *dis);
virtual void write(DataOutputStream *dos);
@ -66,7 +66,7 @@ class MoveEntityPacketSmall::Rot : public MoveEntityPacketSmall
{
public:
Rot();
Rot(int id, int8_t yRot, int8_t xRot);
Rot(int id, char yRot, char xRot);
virtual void read(DataInputStream *dis);
virtual void write(DataOutputStream *dos);

View file

@ -17,14 +17,22 @@ void SetEntityMotionPacket::_init(int id, double xd, double yd, double zd)
if (xd > m) xd = m;
if (yd > m) yd = m;
if (zd > m) zd = m;
xa = (int16_t) (xd * 8000.0);
ya = (int16_t) (yd * 8000.0);
za = (int16_t) (zd * 8000.0);
useBytes = false;
xa = (int) (xd * 8000.0);
ya = (int) (yd * 8000.0);
za = (int) (zd * 8000.0);
// 4J - if we could transmit this as bytes (in 1/16 accuracy) then flag to do so
if( ( xa >= (-128 * 16 ) ) && ( ya >= (-128 * 16 ) ) && ( za >= (-128 * 16 ) ) &&
( xa < (128 * 16 ) ) && ( ya < (128 * 16 ) ) && ( za < (128 * 16 ) ) )
{
useBytes = true;
}
else
{
useBytes = false;
}
}
SetEntityMotionPacket::SetEntityMotionPacket()
SetEntityMotionPacket::SetEntityMotionPacket()
{
_init(0, 0.0f, 0.0f, 0.0f);
}
@ -36,27 +44,51 @@ SetEntityMotionPacket::SetEntityMotionPacket(std::shared_ptr<Entity> e)
SetEntityMotionPacket::SetEntityMotionPacket(int id, double xd, double yd, double zd)
{
_init(id, xd, yd, zd);
_init(id, xd, yd, zd);
}
void SetEntityMotionPacket::read(DataInputStream *dis) //throws IOException
void SetEntityMotionPacket::read(DataInputStream *dis) //throws IOException
{
id = dis->readShort();
xa = dis->readShort();
ya = dis->readShort();
za = dis->readShort();
useBytes = false;
short idAndFlag = dis->readShort();
id = idAndFlag & 0x07ff;
if( idAndFlag & 0x0800 )
{
xa = (int)dis->readByte();
ya = (int)dis->readByte();
za = (int)dis->readByte();
xa = ( xa << 24 ) >> 24;
ya = ( ya << 24 ) >> 24;
za = ( za << 24 ) >> 24;
xa *= 16;
ya *= 16;
za *= 16;
useBytes = true;
}
else
{
xa = dis->readShort();
ya = dis->readShort();
za = dis->readShort();
useBytes = false;
}
}
void SetEntityMotionPacket::write(DataOutputStream *dos) //throws IOException
void SetEntityMotionPacket::write(DataOutputStream *dos) //throws IOException
{
dos->writeShort(id);
dos->writeShort(xa);
dos->writeShort(ya);
dos->writeShort(za);
if( useBytes )
{
dos->writeShort(id | 0x800);
dos->writeByte(xa/16);
dos->writeByte(ya/16);
dos->writeByte(za/16);
}
else
{
dos->writeShort(id);
dos->writeShort(xa);
dos->writeShort(ya);
dos->writeShort(za);
}
}
void SetEntityMotionPacket::handle(PacketListener *listener)
@ -66,7 +98,7 @@ void SetEntityMotionPacket::handle(PacketListener *listener)
int SetEntityMotionPacket::getEstimatedSize()
{
return 8;
return useBytes ? 5 : 8;
}
bool SetEntityMotionPacket::canBeInvalidated()

View file

@ -7,7 +7,7 @@ class SetEntityMotionPacket : public Packet, public std::enable_shared_from_this
{
public:
int id;
int16_t xa, ya, za;
int xa, ya, za;
bool useBytes; // 4J added
private:

View file

@ -17,7 +17,7 @@ TeleportEntityPacket::TeleportEntityPacket()
xRot = 0;
}
TeleportEntityPacket::TeleportEntityPacket(std::shared_ptr<Entity> e)
TeleportEntityPacket::TeleportEntityPacket(std::shared_ptr<Entity> e)
{
id = e->entityId;
x = Mth::floor(e->x * 32);
@ -27,7 +27,7 @@ TeleportEntityPacket::TeleportEntityPacket(std::shared_ptr<Entity> e)
xRot = (uint8_t) (e->xRot * 256 / 360);
}
TeleportEntityPacket::TeleportEntityPacket(int id, int32_t x, int32_t y, int32_t z, uint8_t yRot, uint8_t xRot)
TeleportEntityPacket::TeleportEntityPacket(int id, int x, int y, int z, uint8_t yRot, uint8_t xRot)
{
this->id = id;
this->x = x;
@ -53,22 +53,28 @@ void TeleportEntityPacket::read(DataInputStream *dis) //throws IOException
xRot = (uint8_t) dis->read();
}
void TeleportEntityPacket::write(DataOutputStream *dos) //throws IOException
void TeleportEntityPacket::write(DataOutputStream *dos) //throws IOException
{
dos->writeShort((short)id);
dos->writeShort(id);
#ifdef _LARGE_WORLDS
dos->writeInt(x);
dos->writeInt(y);
dos->writeInt(z);
#else
dos->writeShort(x);
dos->writeShort(y);
dos->writeShort(z);
#endif
dos->write(yRot);
dos->write(xRot);
}
void TeleportEntityPacket::handle(PacketListener *listener)
void TeleportEntityPacket::handle(PacketListener *listener)
{
listener->handleTeleportEntity(shared_from_this());
}
int TeleportEntityPacket::getEstimatedSize()
int TeleportEntityPacket::getEstimatedSize()
{
return 2 + 2 + 2 + 2 + 1 + 1;
}

View file

@ -7,19 +7,19 @@ class TeleportEntityPacket : public Packet, public std::enable_shared_from_this<
{
public:
int id;
int32_t x, y, z;
uint8_t yRot, xRot;
int x, y, z;
uint8_t yRot, xRot;
TeleportEntityPacket();
TeleportEntityPacket(std::shared_ptr<Entity> e);
TeleportEntityPacket(int id, int32_t x, int32_t y, int32_t z, uint8_t yRot, uint8_t xRot);
TeleportEntityPacket(int id, int x, int y, int z, uint8_t yRot, uint8_t xRot);
virtual void read(DataInputStream *dis);
virtual void write(DataOutputStream *dos);
virtual void handle(PacketListener *listener);
virtual int getEstimatedSize();
virtual bool canBeInvalidated();
virtual bool isInvalidatedBy(std::shared_ptr<Packet> packet);
virtual bool isInvalidatedBy(std::shared_ptr<Packet> packet);
public:
static std::shared_ptr<Packet> create() { return std::shared_ptr<Packet>(new TeleportEntityPacket()); }

View file

@ -122,7 +122,7 @@ meson setup build --reconfigure
...or to hard reset the build directory:
```bash
rm -rf ./build
rm -r ./build
meson setup build
```

View file

@ -1,11 +1,11 @@
{
description = "4jcraft-nix dev shell";
description = "4jcraft-nix package and dev shell";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
outputs = { nixpkgs, ... }:
outputs = { self, nixpkgs, ... }:
let
allSystems = [
"x86_64-linux"
@ -19,30 +19,45 @@
});
in
{
devShells = forAllSystems ({ pkgs }:
let
libs = with pkgs; [
openssl.dev
libGL
libGLU
sdl2
zlib
];
packages = with pkgs; [
clang
lld
cmake
gnumake
meson
ninja
pkg-config
];
in
packages = forAllSystems ({ pkgs }:
{
default = pkgs.mkShell {
LD_LIBRARY_PATH = "/run/opengl-driver/lib";
buildInputs = libs;
nativeBuildInputs = packages;
default = pkgs.clangStdenv.mkDerivation {
pname = "4jcraft";
version = "0.1.0";
src = ./.;
buildInputs = with pkgs; [
openssl.dev
libGL
libGLU
SDL2
zlib
];
nativeBuildInputs = with pkgs; [
lld
meson
ninja
pkg-config
python3
makeWrapper
];
installPhase = ''
mkdir -p $out/share/4jcraft
cp -r Minecraft.Client/. $out/share/4jcraft/
mkdir -p $out/bin
makeWrapper $out/share/4jcraft/Minecraft.Client \
$out/bin/4jcraft \
--run "cd $out/share/4jcraft"
'';
meta = {
description = "4JCraft";
platforms = pkgs.lib.platforms.linux;
};
};
}
);