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.
4.2 kB · 195 lines
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195#include "stdafx.h"#include "net.minecraft.world.entity.ai.goal.h"#include "net.minecraft.world.entity.h"#include "net.minecraft.world.level.h"#include "SynchedEntityData.h"#include "ParticleTypes.h"#include "TamableAnimal.h"
TamableAnimal::TamableAnimal(Level *level) : Animal(level){ sitGoal = new SitGoal(this);}
TamableAnimal::~TamableAnimal(){ if(sitGoal != NULL) delete sitGoal;}
void TamableAnimal::defineSynchedData(){ Animal::defineSynchedData(); entityData->define(DATA_FLAGS_ID, (byte) 0); entityData->define(DATA_OWNERUUID_ID, L"");}
void TamableAnimal::addAdditonalSaveData(CompoundTag *tag){ Animal::addAdditonalSaveData(tag);#ifdef _XBOX_ONE // 4J Stu Added from later Java version to remove owners from save transfer saves. We will probably want this on other platforms in the future if (getOwnerUUID().empty()) { tag->putString(L"OwnerUUID", L""); } else { tag->putString(L"OwnerUUID", getOwnerUUID()); }#else if (getOwnerUUID().empty()) { tag->putString(L"Owner", L""); } else { tag->putString(L"Owner", getOwnerUUID()); }#endif tag->putBoolean(L"Sitting", isSitting());}
void TamableAnimal::readAdditionalSaveData(CompoundTag *tag){ Animal::readAdditionalSaveData(tag);#ifdef _XBOX_ONE // 4J Stu Added from later Java version to remove owners from save transfer saves. We will probably want this on other platforms in the future wstring owner = L""; if(tag->contains(L"OwnerUUID") ) { owner = tag->getString(L"OwnerUUID"); }#else wstring owner = tag->getString(L"Owner");#endif if (owner.length() > 0) { setOwnerUUID(owner); setTame(true); } sitGoal->wantToSit(tag->getBoolean(L"Sitting")); setSitting(tag->getBoolean(L"Sitting"));}
void TamableAnimal::spawnTamingParticles(bool success){ ePARTICLE_TYPE particle = eParticleType_heart; if (!success) { particle = eParticleType_smoke; } for (int i = 0; i < 7; i++) { double xa = random->nextGaussian() * 0.02; double ya = random->nextGaussian() * 0.02; double za = random->nextGaussian() * 0.02; level->addParticle(particle, x + random->nextFloat() * bbWidth * 2 - bbWidth, y + .5f + random->nextFloat() * bbHeight, z + random->nextFloat() * bbWidth * 2 - bbWidth, xa, ya, za); }}
void TamableAnimal::handleEntityEvent(byte id){ if (id == EntityEvent::TAMING_SUCCEEDED) { spawnTamingParticles(true); } else if (id == EntityEvent::TAMING_FAILED) { spawnTamingParticles(false); } else { Animal::handleEntityEvent(id); }}
bool TamableAnimal::isTame(){ return (entityData->getByte(DATA_FLAGS_ID) & 0x04) != 0;}
void TamableAnimal::setTame(bool value){ byte current = entityData->getByte(DATA_FLAGS_ID); if (value) { entityData->set(DATA_FLAGS_ID, (byte) (current | 0x04)); } else { entityData->set(DATA_FLAGS_ID, (byte) (current & ~0x04)); }}
bool TamableAnimal::isSitting(){ return (entityData->getByte(DATA_FLAGS_ID) & 0x01) != 0;}
void TamableAnimal::setSitting(bool value){ byte current = entityData->getByte(DATA_FLAGS_ID); if (value) { entityData->set(DATA_FLAGS_ID, (byte) (current | 0x01)); } else { entityData->set(DATA_FLAGS_ID, (byte) (current & ~0x01)); }}
wstring TamableAnimal::getOwnerUUID(){ return entityData->getString(DATA_OWNERUUID_ID);}
void TamableAnimal::setOwnerUUID(const wstring &name){ entityData->set(DATA_OWNERUUID_ID, name);}
shared_ptr<Entity> TamableAnimal::getOwner(){ return level->getPlayerByUUID(getOwnerUUID());}
SitGoal *TamableAnimal::getSitGoal(){ return sitGoal;}
bool TamableAnimal::wantsToAttack(shared_ptr<LivingEntity> target, shared_ptr<LivingEntity> owner){ return true;}
Team *TamableAnimal::getTeam(){ if (isTame()) { shared_ptr<LivingEntity> owner = dynamic_pointer_cast<LivingEntity>(getOwner()); if (owner != NULL) { return owner->getTeam(); } } return Animal::getTeam();}
bool TamableAnimal::isAlliedTo(shared_ptr<LivingEntity> other){ if (isTame()) { shared_ptr<LivingEntity> owner = dynamic_pointer_cast<LivingEntity>(getOwner()); if (other == owner) { return true; } if (owner != NULL) { return owner->isAlliedTo(other); } } return Animal::isAlliedTo(other);}