the whole game

This commit is contained in:
2026-03-02 22:04:18 +03:00
parent 816e9060b4
commit f0617a5d22
2069 changed files with 581500 additions and 0 deletions

View File

@@ -0,0 +1,117 @@
#include "FallingTile.h"
#include "../../level/Level.h"
#include "../../../util/Random.h"
#include "../../../nbt/CompoundTag.h"
FallingTile::FallingTile( Level* level )
: Entity(level),
tile(0),
data(0)
{
init();
}
FallingTile::FallingTile( Level* level, float x, float y, float z, int tile, int data)
: Entity(level),
tile(tile),
data(data)
{
init();
setPos(x, y, z);
xo = xOld = x;
yo = yOld = y;
zo = zOld = z;
}
void FallingTile::init() {
entityRendererId = ER_FALLINGTILE_RENDERER;
time = 0;
blocksBuilding = true;
setSize(0.98f, 0.98f);
heightOffset = bbHeight / 2.0f;
makeStepSound = false;
xd = 0;
yd = 0;
zd = 0;
}
bool FallingTile::isPickable() {
return !removed;
}
void FallingTile::tick() {
if (tile == 0) {
remove();
return;
}
xo = x;
yo = y;
zo = z;
time++;
yd -= 0.04f;
move(xd, yd, zd);
xd *= 0.98f;
yd *= 0.98f;
zd *= 0.98f;
if (!level->isClientSide) {
int xt = Mth::floor(x);
int yt = Mth::floor(y);
int zt = Mth::floor(z);
if (time == 1) {
if (level->getTile(xt, yt, zt) == tile) {
level->setTile(xt, yt, zt, 0);
} else {
remove();
return;
}
}
if (onGround) {
xd *= 0.7f;
zd *= 0.7f;
yd *= -0.5f;
remove();
if (level->mayPlace(tile, xt, yt, zt, true, 1) && level->setTileAndData(xt, yt, zt, tile, data)) {
} else if (!level->isClientSide) {
//spawnAtLocation(tile, 1);
}
} else if (time > SharedConstants::TicksPerSecond * 5 && !level->isClientSide) {
//spawnAtLocation(tile, 1);
remove();
}
}
}
float FallingTile::getShadowHeightOffs() {
return 0;
}
Level* FallingTile::getLevel() {
return level;
}
void FallingTile::addAdditonalSaveData( CompoundTag* tag ) {
tag->putByte("Tile", (char) tile);
tag->putByte("Data", (char) data);
tag->putByte("Time", (char) time);
}
void FallingTile::readAdditionalSaveData( CompoundTag* tag ) {
tile = tag->getByte("Tile");
data = tag->getByte("Data");
time = tag->getByte("Time");
}
int FallingTile::getEntityTypeId() const {
return EntityTypes::IdFallingTile;
}

View File

@@ -0,0 +1,40 @@
#ifndef NET_MINECRAFT_WORLD_ENTITY_ITEM__FallingTile_H__
#define NET_MINECRAFT_WORLD_ENTITY_ITEM__FallingTile_H__
//package net.minecraft.world.entity.item;
#include "../Entity.h"
class Level;
class CompoundTag;
class FallingTile: public Entity
{
public:
FallingTile(Level* level);
FallingTile(Level* level, float x, float y, float z, int tile, int data = 0);
void init();
bool isPickable();
void tick();
int getEntityTypeId() const;
float getShadowHeightOffs();
Level* getLevel();
protected:
void addAdditonalSaveData(CompoundTag* tag);
void readAdditionalSaveData(CompoundTag* tag);
public:
int tile;
int data;
int time;
};
#endif /*NET_MINECRAFT_WORLD_ENTITY_ITEM__FallingTile_H__*/

View File

@@ -0,0 +1,211 @@
#include "ItemEntity.h"
#include "../../entity/player/Player.h"
#include "../../item/ItemInstance.h"
#include "../../level/Level.h"
#include "../../level/material/Material.h"
#include "../../level/tile/Tile.h"
#include "../../../util/Mth.h"
#include "../../../nbt/CompoundTag.h"
const int ItemEntity::LIFETIME = 5 * 60 * SharedConstants::TicksPerSecond; // Five minutes, changed in 0.3.3!
ItemEntity::ItemEntity( Level* level, float x, float y, float z, const ItemInstance& item )
: super(level),
item(item),
health(5),
age(0),
tickCount(0),
throwTime(0),
lifeTime(LIFETIME),
bobOffs((float) (Mth::random() * Mth::PI * 2))
{
entityRendererId = ER_ITEM_RENDERER;
setSize(0.25f, 0.25f);
heightOffset = bbHeight / 2.0f;
setPos(x, y, z);
yRot = (float) (Mth::random() * 360);
xd = (float) (Mth::random() * 0.2f - 0.1f);
yd = +0.2f;
zd = (float) (Mth::random() * 0.2f - 0.1f);
makeStepSound = false;
}
ItemEntity::ItemEntity( Level* level )
: super(level),
health(5),
age(0),
tickCount(0),
throwTime(0),
lifeTime(LIFETIME),
bobOffs((float) (Mth::random() * Mth::PI * 2))
{
entityRendererId = ER_ITEM_RENDERER;
setSize(0.25f, 0.25f);
heightOffset = bbHeight / 2.0f;
}
ItemEntity::~ItemEntity()
{
}
void ItemEntity::tick()
{
super::tick();
if (throwTime > 0) throwTime--;
xo = x;
yo = y;
zo = z;
yd -= 0.04f;
if (level->getMaterial(Mth::floor(x), Mth::floor(y), Mth::floor(z)) == Material::lava) {
yd = 0.2f;
xd = (sharedRandom.nextFloat() - sharedRandom.nextFloat()) * 0.2f;
zd = (sharedRandom.nextFloat() - sharedRandom.nextFloat()) * 0.2f;
level->playSound(this, "random.fizz", 0.4f, 2.0f + sharedRandom.nextFloat() * 0.4f);
}
checkInTile(x, y, z);
move(xd, yd, zd);
float friction = 0.98f;
if (onGround) {
friction = 0.6f * 0.98f;
int t = level->getTile(Mth::floor(x), Mth::floor(bb.y0) - 1, Mth::floor(z));
if (t > 0) {
friction = Tile::tiles[t]->friction * 0.98f;
}
}
xd *= friction;
yd *= 0.98f;
zd *= friction;
if (onGround) {
yd *= -0.5f;
}
tickCount++;
age++;
if (age >= lifeTime) {
remove();
}
}
bool ItemEntity::isInWater()
{
return level->checkAndHandleWater(bb, Material::water, this);
}
bool ItemEntity::hurt( Entity* source, int damage )
{
markHurt();
health -= damage;
if (health <= 0) {
remove();
}
return false;
}
void ItemEntity::playerTouch( Player* player )
{
if (level->isClientSide) return;
int orgCount = item.count;
if (throwTime == 0 && player->isAlive() && player->inventory->add(&item)) {
level->playSound(this, "random.pop", 0.3f, ((sharedRandom.nextFloat() - sharedRandom.nextFloat()) * 0.7f + 1.0f) * 2.f);
player->take(this, orgCount);
//if (item.count <= 0) remove(); //@todo
remove();
}
}
void ItemEntity::burn( int dmg )
{
hurt(NULL, dmg);
}
bool ItemEntity::checkInTile( float x, float y, float z )
{
int xTile = Mth::floor(x);
int yTile = Mth::floor(y);
int zTile = Mth::floor(z);
float xd = x - xTile;
float yd = y - yTile;
float zd = z - zTile;
if (Tile::solid[level->getTile(xTile, yTile, zTile)]) {
bool west = !Tile::solid[level->getTile(xTile - 1, yTile, zTile)];
bool east = !Tile::solid[level->getTile(xTile + 1, yTile, zTile)];
bool up = !Tile::solid[level->getTile(xTile, yTile - 1, zTile)];
bool down = !Tile::solid[level->getTile(xTile, yTile + 1, zTile)];
bool north = !Tile::solid[level->getTile(xTile, yTile, zTile - 1)];
bool south = !Tile::solid[level->getTile(xTile, yTile, zTile + 1)];
int dir = -1;
float closest = 9999;
if (west && xd < closest) {
closest = xd;
dir = 0;
}
if (east && 1 - xd < closest) {
closest = 1 - xd;
dir = 1;
}
if (up && yd < closest) {
closest = yd;
dir = 2;
}
if (down && 1 - yd < closest) {
closest = 1 - yd;
dir = 3;
}
if (north && zd < closest) {
closest = zd;
dir = 4;
}
if (south && 1 - zd < closest) {
// closest = 1 - zd; //@note: not read
dir = 5;
}
float speed = sharedRandom.nextFloat() * 0.2f + 0.1f;
if (dir == 0) this->xd = -speed;
if (dir == 1) this->xd = +speed;
if (dir == 2) this->yd = -speed;
if (dir == 3) this->yd = +speed;
if (dir == 4) this->zd = -speed;
if (dir == 5) this->zd = +speed;
}
return false;
}
void ItemEntity::addAdditonalSaveData(CompoundTag* entityTag) {
entityTag->putShort("Health", (char) health);
entityTag->putShort("Age", (short) age);
entityTag->putCompound("Item", item.save(new CompoundTag()));
}
void ItemEntity::readAdditionalSaveData(CompoundTag* tag) {
health = tag->getShort("Health") & 0xff;
age = tag->getShort("Age");
CompoundTag* itemTag = tag->getCompound("Item");
item.load(itemTag);
}
bool ItemEntity::isItemEntity() {
return true;
}
int ItemEntity::getEntityTypeId() const {
return EntityTypes::IdItemEntity;
}
int ItemEntity::getLifeTime() const {
return lifeTime;
}

View File

@@ -0,0 +1,49 @@
#ifndef NET_MINECRAFT_WORLD_ENTITY_ITEM__ItemEntity_H__
#define NET_MINECRAFT_WORLD_ENTITY_ITEM__ItemEntity_H__
//package net.minecraft.world.entity.item;
#include "../../item/ItemInstance.h"
#include "../../entity/Entity.h"
#include "../../../SharedConstants.h"
class Level;
class ItemInstance;
class ItemEntity: public Entity
{
typedef Entity super;
static const int LIFETIME;
public:
ItemEntity(Level* level);
ItemEntity(Level* level, float x, float y, float z, const ItemInstance& item);
~ItemEntity();
void tick();
bool isInWater();
bool hurt(Entity* source, int damage);
void playerTouch(Player* player);
bool isItemEntity();
int getEntityTypeId() const;
int getLifeTime() const;
protected:
void burn(int dmg);
void addAdditonalSaveData(CompoundTag* entityTag);
void readAdditionalSaveData(CompoundTag* tag);
private:
bool checkInTile(float x, float y, float z);
public:
ItemInstance item;
int age;
int throwTime;
float bobOffs;
private:
int tickCount;
int health;
int lifeTime;
};
#endif /*NET_MINECRAFT_WORLD_ENTITY_ITEM__ItemEntity_H__*/

View File

@@ -0,0 +1,91 @@
#include "PrimedTnt.h"
#include "../../../nbt/CompoundTag.h"
PrimedTnt::PrimedTnt( Level* level )
: super(level),
life(80)
{
entityRendererId = ER_TNT_RENDERER ;
blocksBuilding = true;
setSize(0.98f, 0.98f);
heightOffset = bbHeight / 2.0f;
}
PrimedTnt::PrimedTnt( Level* level, float x, float y, float z )
: super(level),
life(80)
{
entityRendererId = ER_TNT_RENDERER ;
blocksBuilding = true;
setSize(0.98f, 0.98f);
heightOffset = bbHeight / 2.0f;
setPos(x, y, z);
float rot = Mth::random() * Mth::PI * 2.0f;
xd = Mth::sin(rot * Mth::DEGRAD) * -0.02f;
yd = +0.2f;
zd = Mth::cos(rot * Mth::DEGRAD) * -0.02f;
makeStepSound = false;
xo = x;
yo = y;
zo = z;
}
bool PrimedTnt::isPickable()
{
return !removed;
}
void PrimedTnt::tick()
{
xo = x;
yo = y;
zo = z;
yd -= 0.04f;
move(xd, yd, zd);
xd *= 0.98f;
yd *= 0.98f;
zd *= 0.98f;
if (onGround) {
xd *= 0.7f;
zd *= 0.7f;
yd *= -0.5f;
}
life--;
if (!level->isClientSide && life <= 0) {
remove();
explode();
} else {
level->addParticle(PARTICLETYPE(smoke), x, y + 0.5f, z, 0, 0, 0);
}
}
float PrimedTnt::getShadowHeightOffs()
{
return 0;
}
void PrimedTnt::explode()
{
float r = 3.1f;
level->explode(NULL, x, y, z, r);
}
void PrimedTnt::addAdditonalSaveData(CompoundTag* entityTag) {
entityTag->putByte("Fuse", life);
}
void PrimedTnt::readAdditionalSaveData(CompoundTag* tag) {
life = tag->getByte("Fuse");
}
int PrimedTnt::getEntityTypeId() const {
return EntityTypes::IdPrimedTnt;
}

View File

@@ -0,0 +1,36 @@
#ifndef NET_MINECRAFT_WORLD_ENTITY_ITEM__PrimedTnt_H__
#define NET_MINECRAFT_WORLD_ENTITY_ITEM__PrimedTnt_H__
//package net.minecraft.world.entity.item;
#include "../Entity.h"
#include "../../level/Level.h"
class CompoundTag;
class PrimedTnt: public Entity
{
typedef Entity super;
public:
PrimedTnt(Level* level);
PrimedTnt(Level* level, float x, float y, float z);
void tick();
bool isPickable();
int getEntityTypeId() const;
float getShadowHeightOffs();
protected:
void addAdditonalSaveData(CompoundTag* entityTag);
void readAdditionalSaveData(CompoundTag* tag);
private:
void explode();
public:
int life;
};
#endif /*NET_MINECRAFT_WORLD_ENTITY_ITEM__PrimedTnt_H__*/

View File

@@ -0,0 +1,88 @@
#include "TripodCamera.h"
#include "../player/Player.h"
#include "../../level/Level.h"
TripodCamera::TripodCamera( Level* level, Player* owner, float x, float y, float z )
: super(level),
owner(owner),
life(80),
activated(false)
{
entityRendererId = ER_TRIPODCAMERA_RENDERER;
// Copy rotation from the entity placing the camera
xRot = xRotO = owner->xRot;
yRot = yRotO = owner->yRot;
blocksBuilding = true;
setSize(1.0f, 1.5f);
heightOffset = bbHeight / 2.0f - 0.25f;
setPos(x, y, z);
xo = x;
yo = y;
zo = z;
}
bool TripodCamera::isPickable()
{
return !removed;
}
bool TripodCamera::interactPreventDefault()
{
return true;
}
bool TripodCamera::interact( Player* player )
{
activated = true;
return true;
}
void TripodCamera::tick()
{
xo = x;
yo = y;
zo = z;
yd -= 0.04f;
move(xd, yd, zd);
xd *= 0.98f;
yd *= 0.98f;
zd *= 0.98f;
if (onGround) {
xd *= 0.7f;
zd *= 0.7f;
yd *= -0.5f;
}
if (activated) {
--life;
if (life == 0) {
remove();
} else if (life == 8) {
level->takePicture(this, owner);
level->addParticle(PARTICLETYPE(explode), x, y + 0.6f, z, 0, 0, 0);
level->addParticle(PARTICLETYPE(explode), x, y + 0.8f, z, 0, 0, 0);
level->addParticle(PARTICLETYPE(explode), x, y + 1.0f, z, 0, 0, 0);
} else if (life > 8) {
level->addParticle(PARTICLETYPE(smoke), x, y + 1.0f, z, 0, 0, 0);
}
}
}
float TripodCamera::getShadowHeightOffs()
{
return 0;
}
bool TripodCamera::isPushable()
{
return false;
}

View File

@@ -0,0 +1,32 @@
#ifndef NET_MINECRAFT_WORLD_ENTITY_ITEM__TripodCamera_H__
#define NET_MINECRAFT_WORLD_ENTITY_ITEM__TripodCamera_H__
#include "../Mob.h"
class TripodCamera: public Mob
{
typedef Mob super;
public:
TripodCamera(Level* level, Player* owner_, float x, float y, float z);
void tick();
bool isPickable();
bool isPushable();
// id == 0 -> not possible to create via serialization (yet)
int getEntityTypeId() const { return 0; }
bool interact(Player* player);
bool interactPreventDefault();
float getShadowHeightOffs();
public:
int life;
protected:
Player* owner;
bool activated;
};
#endif /*NET_MINECRAFT_WORLD_ENTITY_ITEM__TripodCamera_H__*/