Something went wrong. Try again.
the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
Something went wrong. Try again.
6.2 kB · 309 lines
C++
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309#include "stdafx.h"#include "net.minecraft.world.phys.h"#include "net.minecraft.world.entity.h"#include "net.minecraft.world.level.h"#include "net.minecraft.world.level.tile.h"#include "com.mojang.nbt.h"#include "Throwable.h"
void Throwable::_throwableInit(){ xTile = -1; yTile = -1; zTile = -1; lastTile = 0; inGround = false; shakeTime = 0; owner = nullptr; life = 0; flightTime = 0; ownerName = L"";}
Throwable::Throwable(Level *level) : Entity(level){ _throwableInit(); setSize(0.25f, 0.25f);}
void Throwable::defineSynchedData(){}
bool Throwable::shouldRenderAtSqrDistance(double distance){ double size = bb->getSize() * 4; size *= 64.0f; return distance < size * size;}
Throwable::Throwable(Level *level, shared_ptr<LivingEntity> mob) : Entity(level){ _throwableInit(); owner = mob;
setSize(4 / 16.0f, 4 / 16.0f);
moveTo(mob->x, mob->y + mob->getHeadHeight(), mob->z, mob->yRot, mob->xRot);
x -= cos(yRot / 180 * PI) * 0.16f; y -= 0.1f; z -= sin(yRot / 180 * PI) * 0.16f; setPos(x, y, z); heightOffset = 0;
float speed = 0.4f; xd = (-sin(yRot / 180 * PI) * cos(xRot / 180 * PI)) * speed; zd = (cos(yRot / 180 * PI) * cos(xRot / 180 * PI)) * speed; yd = (-sin((xRot + getThrowUpAngleOffset()) / 180 * PI)) * speed;
shoot(xd, yd, zd, getThrowPower(), 1);}
Throwable::Throwable(Level *level, double x, double y, double z) : Entity(level){ _throwableInit(); life = 0;
setSize(4 / 16.0f, 4 / 16.0f);
setPos(x, y, z); heightOffset = 0;}
float Throwable::getThrowPower(){ return 1.5f;}
float Throwable::getThrowUpAngleOffset(){ return 0;}
void Throwable::shoot(double xd, double yd, double zd, float pow, float uncertainty){ float dist = sqrt(xd * xd + yd * yd + zd * zd);
xd /= dist; yd /= dist; zd /= dist;
xd += (random->nextGaussian()) * 0.0075f * uncertainty; yd += (random->nextGaussian()) * 0.0075f * uncertainty; zd += (random->nextGaussian()) * 0.0075f * uncertainty;
xd *= pow; yd *= pow; zd *= pow;
this->xd = xd; this->yd = yd; this->zd = zd;
float sd = (float) sqrt(xd * xd + zd * zd);
yRotO = yRot = (float) (atan2(xd, zd) * 180 / PI); xRotO = xRot = (float) (atan2(yd, (double)sd) * 180 / PI); life = 0;}
void Throwable::lerpMotion(double xd, double yd, double zd){ this->xd = xd; this->yd = yd; this->zd = zd; if (xRotO == 0 && yRotO == 0) { float sd = (float) sqrt(xd * xd + zd * zd); yRotO = yRot = (float) (atan2(xd, zd) * 180 / PI); xRotO = xRot = (float) (atan2(yd, (double)sd) * 180 / PI); }}
void Throwable::tick(){ xOld = x; yOld = y; zOld = z; Entity::tick();
if (shakeTime > 0) shakeTime--;
if (inGround) { int tile = level->getTile(xTile, yTile, zTile); if (tile == lastTile) { life++; if (life == 20 * 60) remove(); return; } else { inGround = false;
xd *= random->nextFloat() * 0.2f; yd *= random->nextFloat() * 0.2f; zd *= random->nextFloat() * 0.2f; life = 0; flightTime = 0; } } else { flightTime++; }
Vec3 *from = Vec3::newTemp(x, y, z); Vec3 *to = Vec3::newTemp(x + xd, y + yd, z + zd); HitResult *res = level->clip(from, to);
from = Vec3::newTemp(x, y, z); to = Vec3::newTemp(x + xd, y + yd, z + zd); if (res != NULL) { to = Vec3::newTemp(res->pos->x, res->pos->y, res->pos->z); }
if (!level->isClientSide) { shared_ptr<Entity> hitEntity = nullptr; vector<shared_ptr<Entity> > *objects = level->getEntities(shared_from_this(), bb->expand(xd, yd, zd)->grow(1, 1, 1)); double nearest = 0; shared_ptr<LivingEntity> owner = getOwner(); for (int i = 0; i < objects->size(); i++) { shared_ptr<Entity> e = objects->at(i); if (!e->isPickable() || (e == owner && flightTime < 5)) continue;
float rr = 0.3f; AABB *bb = e->bb->grow(rr, rr, rr); HitResult *p = bb->clip(from, to); if (p != NULL) { double dd = from->distanceTo(p->pos); delete p; if (dd < nearest || nearest == 0) { hitEntity = e; nearest = dd; } } }
if (hitEntity != NULL) { if(res != NULL) delete res; res = new HitResult(hitEntity); } }
if (res != NULL) { if ( (res->type == HitResult::TILE) && (level->getTile(res->x, res->y, res->z) == Tile::portalTile_Id) ) { handleInsidePortal(); } else { onHit(res); } delete res; } x += xd; y += yd; z += zd;
float sd = (float) sqrt(xd * xd + zd * zd); yRot = (float) (atan2(xd, zd) * 180 / PI); xRot = (float) (atan2(yd, (double)sd) * 180 / PI);
while (xRot - xRotO < -180) xRotO -= 360; while (xRot - xRotO >= 180) xRotO += 360;
while (yRot - yRotO < -180) yRotO -= 360; while (yRot - yRotO >= 180) yRotO += 360;
xRot = xRotO + (xRot - xRotO) * 0.2f; yRot = yRotO + (yRot - yRotO) * 0.2f;
float inertia = 0.99f; float gravity = getGravity();
if (isInWater()) { for (int i = 0; i < 4; i++) { float s = 1 / 4.0f; level->addParticle(eParticleType_bubble, x - xd * s, y - yd * s, z - zd * s, xd, yd, zd); } inertia = 0.80f; }
xd *= inertia; yd *= inertia; zd *= inertia; yd -= gravity;
setPos(x, y, z);}
float Throwable::getGravity(){ return 0.03f;}
void Throwable::addAdditonalSaveData(CompoundTag *tag){ tag->putShort(L"xTile", (short) xTile); tag->putShort(L"yTile", (short) yTile); tag->putShort(L"zTile", (short) zTile); tag->putByte(L"inTile", (byte) lastTile); tag->putByte(L"shake", (byte) shakeTime); tag->putByte(L"inGround", (byte) (inGround ? 1 : 0));
if (ownerName.empty() && (owner != NULL) && owner->instanceof(eTYPE_PLAYER) ) { ownerName = owner->getAName(); }
tag->putString(L"ownerName", ownerName.empty() ? L"" : ownerName);}
void Throwable::readAdditionalSaveData(CompoundTag *tag){ xTile = tag->getShort(L"xTile"); yTile = tag->getShort(L"yTile"); zTile = tag->getShort(L"zTile"); lastTile = tag->getByte(L"inTile") & 0xff; shakeTime = tag->getByte(L"shake") & 0xff; inGround = tag->getByte(L"inGround") == 1; ownerName = tag->getString(L"ownerName"); if (ownerName.empty() ) ownerName = L"";}
float Throwable::getShadowHeightOffs(){ return 0;}
shared_ptr<LivingEntity> Throwable::getOwner(){ if (owner == NULL && !ownerName.empty() ) { owner = level->getPlayerByName(ownerName); } return owner;}