TU19: merge Minecraft.Client/Player

This commit is contained in:
Tropical 2026-03-21 22:03:18 -05:00
parent 3f143811e3
commit a493e42532
16 changed files with 1364 additions and 948 deletions

View file

@ -18,6 +18,7 @@
#include "../../Minecraft.World/Headers/net.minecraft.network.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.level.dimension.h"
#include "../../Minecraft.World/Util/BasicTypeContainers.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.level.chunk.h"
#include "../Network/PlayerConnection.h"
EntityTracker::EntityTracker(ServerLevel* level) {
@ -26,7 +27,7 @@ EntityTracker::EntityTracker(ServerLevel* level) {
}
void EntityTracker::addEntity(std::shared_ptr<Entity> e) {
if (e->GetType() == eTYPE_SERVERPLAYER) {
if (e->instanceof(eTYPE_SERVERPLAYER)) {
addEntity(e, 32 * 16, 2);
std::shared_ptr<ServerPlayer> player =
std::dynamic_pointer_cast<ServerPlayer>(e);
@ -35,51 +36,57 @@ void EntityTracker::addEntity(std::shared_ptr<Entity> e) {
(*it)->updatePlayer(this, player);
}
}
} else if (e->GetType() == eTYPE_FISHINGHOOK)
} else if (e->instanceof(eTYPE_FISHINGHOOK))
addEntity(e, 16 * 4, 5, true);
else if (e->GetType() == eTYPE_SMALL_FIREBALL)
else if (e->instanceof(eTYPE_SMALL_FIREBALL))
addEntity(e, 16 * 4, 10, false);
else if (e->GetType() == eTYPE_DRAGON_FIREBALL)
else if (e->instanceof(eTYPE_DRAGON_FIREBALL))
addEntity(e, 16 * 4, 10, false); // 4J Added TU9
else if (e->GetType() == eTYPE_ARROW)
else if (e->instanceof(eTYPE_ARROW))
addEntity(e, 16 * 4, 20, false);
else if (e->GetType() == eTYPE_FIREBALL)
else if (e->instanceof(eTYPE_FIREBALL))
addEntity(e, 16 * 4, 10, false);
else if (e->GetType() == eTYPE_SNOWBALL)
else if (e->instanceof(eTYPE_SNOWBALL))
addEntity(e, 16 * 4, 10, true);
else if (e->GetType() == eTYPE_THROWNENDERPEARL)
else if (e->instanceof(eTYPE_THROWNENDERPEARL))
addEntity(e, 16 * 4, 10, true);
else if (e->GetType() == eTYPE_EYEOFENDERSIGNAL)
else if (e->instanceof(eTYPE_EYEOFENDERSIGNAL))
addEntity(e, 16 * 4, 4, true);
else if (e->GetType() == eTYPE_THROWNEGG)
else if (e->instanceof(eTYPE_THROWNEGG))
addEntity(e, 16 * 4, 10, true);
else if (e->GetType() == eTYPE_THROWNPOTION)
else if (e->instanceof(eTYPE_THROWNPOTION))
addEntity(e, 16 * 4, 10, true);
else if (e->GetType() == eTYPE_THROWNEXPBOTTLE)
else if (e->instanceof(eTYPE_THROWNEXPBOTTLE))
addEntity(e, 16 * 4, 10, true);
else if (e->GetType() == eTYPE_ITEMENTITY)
else if (e->instanceof(eTYPE_FIREWORKS_ROCKET))
addEntity(e, 16 * 4, 10, true);
else if (e->instanceof(eTYPE_ITEMENTITY))
addEntity(e, 16 * 4, 20, true);
else if (e->GetType() == eTYPE_MINECART)
else if (e->instanceof(eTYPE_MINECART))
addEntity(e, 16 * 5, 3, true);
else if (e->GetType() == eTYPE_BOAT)
else if (e->instanceof(eTYPE_BOAT))
addEntity(e, 16 * 5, 3, true);
else if (e->GetType() == eTYPE_SQUID)
else if (e->instanceof(eTYPE_SQUID))
addEntity(e, 16 * 4, 3, true);
else if (e->instanceof(eTYPE_WITHERBOSS))
addEntity(e, 16 * 5, 3, false);
else if (e->instanceof(eTYPE_BAT))
addEntity(e, 16 * 5, 3, false);
else if (std::dynamic_pointer_cast<Creature>(e) != NULL)
addEntity(e, 16 * 5, 3, true);
else if (e->GetType() == eTYPE_ENDERDRAGON)
else if (e->instanceof(eTYPE_ENDERDRAGON))
addEntity(e, 16 * 10, 3, true);
else if (e->GetType() == eTYPE_PRIMEDTNT)
else if (e->instanceof(eTYPE_PRIMEDTNT))
addEntity(e, 16 * 10, 10, true);
else if (e->GetType() == eTYPE_FALLINGTILE)
else if (e->instanceof(eTYPE_FALLINGTILE))
addEntity(e, 16 * 10, 20, true);
else if (e->GetType() == eTYPE_PAINTING)
else if (e->instanceof(eTYPE_HANGING_ENTITY))
addEntity(e, 16 * 10, INT_MAX, false);
else if (e->GetType() == eTYPE_EXPERIENCEORB)
else if (e->instanceof(eTYPE_EXPERIENCEORB))
addEntity(e, 16 * 10, 20, true);
else if (e->GetType() == eTYPE_ENDER_CRYSTAL)
else if (e->instanceof(eTYPE_ENDER_CRYSTAL))
addEntity(e, 16 * 16, INT_MAX, false);
else if (e->GetType() == eTYPE_ITEM_FRAME)
else if (e->instanceof(eTYPE_ITEM_FRAME))
addEntity(e, 16 * 10, INT_MAX, false);
}
@ -125,6 +132,10 @@ void EntityTracker::removePlayer(std::shared_ptr<Entity> e) {
for (AUTO_VAR(it, entities.begin()); it != entities.end(); it++) {
(*it)->removePlayer(player);
}
// 4J: Flush now to ensure remove packets are sent before player
// respawns and add entity packets are sent
player->flushEntitiesToRemove();
}
}
@ -216,6 +227,17 @@ void EntityTracker::clear(std::shared_ptr<ServerPlayer> serverPlayer) {
}
}
void EntityTracker::playerLoadedChunk(std::shared_ptr<ServerPlayer> player,
LevelChunk* chunk) {
for (AUTO_VAR(it, entities.begin()); it != entities.end(); ++it) {
std::shared_ptr<TrackedEntity> te = *it;
if (te->e != player && te->e->xChunk == chunk->x &&
te->e->zChunk == chunk->z) {
te->updatePlayer(this, player);
}
}
}
// AP added for Vita so the range can be increased once the level starts
void EntityTracker::updateMaxRange() {
maxRange = level->getServer()->getPlayers()->getMaxRange();

View file

@ -29,6 +29,8 @@ public:
void broadcastAndSend(std::shared_ptr<Entity> e,
std::shared_ptr<Packet> packet);
void clear(std::shared_ptr<ServerPlayer> serverPlayer);
void playerLoadedChunk(std::shared_ptr<ServerPlayer> player,
LevelChunk* chunk);
void updateMaxRange(); // AP added for Vita
// 4J-JEV: Added, needed access to tracked entity of a riders mount.

View file

@ -16,18 +16,22 @@
#include "../GameState/CreativeMode.h"
#include "../Rendering/GameRenderer.h"
#include "../Rendering/EntityRenderers/ItemInHandRenderer.h"
#include "../../Minecraft.World/AI/Attributes/AttributeInstance.h"
#include "../../Minecraft.World/Level/LevelData.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.damagesource.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.item.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.food.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.effect.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.entity.player.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.entity.monster.h"
#include "../../Minecraft.World/Entities/ItemEntity.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.level.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.level.tile.entity.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.phys.h"
#include "../../Minecraft.World/Headers/net.minecraft.stats.h"
#include "../../Minecraft.World/Headers/com.mojang.nbt.h"
#include "../../Minecraft.World/Util/Random.h"
#include "../../Minecraft.World/Blocks/TileEntities/TileEntity.h"
#include "../../Minecraft.World/Util/Mth.h"
#include "../UI/Screens/AchievementPopup.h"
#include "../Rendering/Particles/CritParticle.h"
@ -55,7 +59,7 @@
LocalPlayer::LocalPlayer(Minecraft* minecraft, Level* level, User* user,
int dimension)
: Player(level) {
: Player(level, user->name) {
flyX = flyY = flyZ = 0.0f; // 4J added
m_awardedThisSession = 0;
@ -64,6 +68,10 @@ LocalPlayer::LocalPlayer(Minecraft* minecraft, Level* level, User* user,
twoJumpsRegistered = false;
sprintTime = 0;
m_uiInactiveTicks = 0;
portalTime = 0.0f;
oPortalTime = 0.0f;
jumpRidingTicks = 0;
jumpRidingScale = 0.0f;
yBob = xBob = yBobO = xBobO = 0.0f;
@ -76,7 +84,6 @@ LocalPlayer::LocalPlayer(Minecraft* minecraft, Level* level, User* user,
}
if (user != NULL) {
this->name = user->name;
m_UUID = name;
// wprintf(L"Created LocalPlayer with name %ls\n", name.c_str() );
// check to see if this player's xuid is in the list of special players
MOJANG_DATA* pMojangData = app.GetMojangDataForXuid(getOnlineXuid());
@ -116,28 +123,6 @@ LocalPlayer::~LocalPlayer() {
if (this->input != NULL) delete input;
}
// 4J - added noEntityCubes parameter
void LocalPlayer::move(double xa, double ya, double za, bool noEntityCubes) {
if (ClientConstants::DEADMAU5_CAMERA_CHEATS) {
if (shared_from_this() == minecraft->player &&
minecraft->options->isFlying) {
noPhysics = true;
float tmp = walkDist; // update
calculateFlight((float)xa, (float)ya, (float)za);
fallDistance = 0.0f;
yd = 0.0f;
Player::move(flyX, flyY, flyZ, noEntityCubes);
onGround = true;
walkDist = tmp;
} else {
noPhysics = false;
Player::move(xa, ya, za, noEntityCubes);
}
} else {
Player::move(xa, ya, za, noEntityCubes);
}
}
void LocalPlayer::calculateFlight(float xa, float ya, float za) {
xa = xa * minecraft->options->flySpeed;
ya = 0;
@ -193,7 +178,7 @@ void LocalPlayer::serverAiStep() {
// mapPlayerChunk(8);
}
bool LocalPlayer::isEffectiveAI() { return true; }
bool LocalPlayer::isEffectiveAi() { return true; }
void LocalPlayer::aiStep() {
if (sprintTime > 0) {
@ -248,7 +233,7 @@ void LocalPlayer::aiStep() {
// input->tick( std::dynamic_pointer_cast<Player>( shared_from_this() ) );
// 4J-PB - make it a localplayer
input->tick(this);
if (isUsingItem()) {
if (isUsingItem() && !isRiding()) {
input->xa *= 0.2f;
input->ya *= 0.2f;
sprintTriggerTime = 0;
@ -373,6 +358,36 @@ void LocalPlayer::aiStep() {
}
}
if (isRidingJumpable()) {
if (jumpRidingTicks < 0) {
jumpRidingTicks++;
if (jumpRidingTicks == 0) {
// reset scale (for gui)
jumpRidingScale = 0;
}
}
if (wasJumping && !input->jumping) {
// jump release
jumpRidingTicks = -10;
sendRidingJump();
} else if (!wasJumping && input->jumping) {
// jump press
jumpRidingTicks = 0;
jumpRidingScale = 0;
} else if (wasJumping) {
// calc jump scale
jumpRidingTicks++;
if (jumpRidingTicks < 10) {
jumpRidingScale = (float)jumpRidingTicks * .1f;
} else {
jumpRidingScale =
.8f + (2.f / ((float)(jumpRidingTicks - 9))) * .1f;
}
}
} else {
jumpRidingScale = 0;
}
Player::aiStep();
// 4J-PB - If we're in Creative Mode, allow flying on ground
@ -491,8 +506,10 @@ float LocalPlayer::getFieldOfViewModifier() {
// modify for movement
if (abilities.flying) targetFov *= 1.1f;
targetFov *=
((walkingSpeed * getWalkingSpeedModifier()) / defaultWalkSpeed + 1) / 2;
AttributeInstance* speed =
getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED);
targetFov *= (speed->getValue() / abilities.getWalkingSpeed() + 1) / 2;
// modify for bow =)
if (isUsingItem() && getUseItem()->id == Item::bow->id) {
@ -511,12 +528,12 @@ float LocalPlayer::getFieldOfViewModifier() {
void LocalPlayer::addAdditonalSaveData(CompoundTag* entityTag) {
Player::addAdditonalSaveData(entityTag);
entityTag->putInt(L"Score", score);
// entityTag->putInt(L"Score", score);
}
void LocalPlayer::readAdditionalSaveData(CompoundTag* entityTag) {
Player::readAdditionalSaveData(entityTag);
score = entityTag->getInt(L"Score");
// score = entityTag->getInt(L"Score");
}
void LocalPlayer::closeContainer() {
@ -530,12 +547,23 @@ void LocalPlayer::closeContainer() {
ui.CloseUIScenes(m_iPad);
}
void LocalPlayer::openTextEdit(std::shared_ptr<SignTileEntity> sign) {
void LocalPlayer::openTextEdit(std::shared_ptr<TileEntity> tileEntity) {
#ifdef ENABLE_JAVA_GUIS
minecraft->setScreen(new TextEditScreen(sign));
bool success = true;
#else
bool success = app.LoadSignEntryMenu(GetXboxPad(), sign);
bool success;
if (tileEntity->GetType() == eTYPE_SIGNTILEENTITY) {
success = app.LoadSignEntryMenu(
GetXboxPad(),
std::dynamic_pointer_cast<SignTileEntity>(tileEntity));
} else if (tileEntity->GetType() == eTYPE_COMMANDBLOCKTILEENTITY) {
success = app.LoadCommandBlockMenu(
GetXboxPad(),
std::dynamic_pointer_cast<CommandBlockEntity>(tileEntity));
}
if (success) ui.PlayUISFX(eSFX_Press);
#endif
}
@ -548,6 +576,30 @@ bool LocalPlayer::openContainer(std::shared_ptr<Container> container) {
bool success = app.LoadContainerMenu(GetXboxPad(), inventory, container);
if (success) ui.PlayUISFX(eSFX_Press);
#endif
// minecraft->setScreen(new ContainerScreen(inventory, container));
return success;
}
bool LocalPlayer::openHopper(std::shared_ptr<HopperTileEntity> container) {
// minecraft->setScreen(new HopperScreen(inventory, container));
bool success = app.LoadHopperMenu(GetXboxPad(), inventory, container);
if (success) ui.PlayUISFX(eSFX_Press);
return success;
}
bool LocalPlayer::openHopper(std::shared_ptr<MinecartHopper> container) {
// minecraft->setScreen(new HopperScreen(inventory, container));
bool success = app.LoadHopperMenu(GetXboxPad(), inventory, container);
if (success) ui.PlayUISFX(eSFX_Press);
return success;
}
bool LocalPlayer::openHorseInventory(std::shared_ptr<EntityHorse> horse,
std::shared_ptr<Container> container) {
// minecraft->setScreen(new HorseInventoryScreen(inventory, container,
// horse));
bool success = app.LoadHorseMenu(GetXboxPad(), inventory, container, horse);
if (success) ui.PlayUISFX(eSFX_Press);
return success;
}
@ -562,12 +614,22 @@ bool LocalPlayer::startCrafting(int x, int y, int z) {
if (success) ui.PlayUISFX(eSFX_Press);
#endif
// app.LoadXuiCraftMenu(0,inventory, level, x, y, z);
// minecraft->setScreen(new CraftingScreen(inventory, level, x, y, z));
return success;
}
bool LocalPlayer::startEnchanting(int x, int y, int z) {
bool LocalPlayer::openFireworks(int x, int y, int z) {
bool success = app.LoadFireworksMenu(
GetXboxPad(),
std::dynamic_pointer_cast<LocalPlayer>(shared_from_this()), x, y, z);
if (success) ui.PlayUISFX(eSFX_Press);
return success;
}
bool LocalPlayer::startEnchanting(int x, int y, int z,
const std::wstring& name) {
bool success =
app.LoadEnchantingMenu(GetXboxPad(), inventory, x, y, z, level);
app.LoadEnchantingMenu(GetXboxPad(), inventory, x, y, z, level, name);
if (success) ui.PlayUISFX(eSFX_Press);
// minecraft.setScreen(new EnchantmentScreen(inventory, level, x, y, z));
return success;
@ -606,6 +668,13 @@ bool LocalPlayer::openBrewingStand(
return success;
}
bool LocalPlayer::openBeacon(std::shared_ptr<BeaconTileEntity> beacon) {
// minecraft->setScreen(new BeaconScreen(inventory, beacon));
bool success = app.LoadBeaconMenu(GetXboxPad(), inventory, beacon);
if (success) ui.PlayUISFX(eSFX_Press);
return success;
}
bool LocalPlayer::openTrap(std::shared_ptr<DispenserTileEntity> trap) {
bool success = app.LoadTrapMenu(GetXboxPad(), inventory, trap);
if (success) ui.PlayUISFX(eSFX_Press);
@ -613,9 +682,10 @@ bool LocalPlayer::openTrap(std::shared_ptr<DispenserTileEntity> trap) {
return success;
}
bool LocalPlayer::openTrading(std::shared_ptr<Merchant> traderTarget) {
bool LocalPlayer::openTrading(std::shared_ptr<Merchant> traderTarget,
const std::wstring& name) {
bool success =
app.LoadTradingMenu(GetXboxPad(), inventory, traderTarget, level);
app.LoadTradingMenu(GetXboxPad(), inventory, traderTarget, level, name);
if (success) ui.PlayUISFX(eSFX_Press);
// minecraft.setScreen(new MerchantScreen(inventory, traderTarget, level));
return success;
@ -645,8 +715,8 @@ void LocalPlayer::chat(const std::wstring& message) {}
bool LocalPlayer::isSneaking() { return input->sneaking && !m_isSleeping; }
void LocalPlayer::hurtTo(int newHealth, ETelemetryChallenges damageSource) {
int dmg = getHealth() - newHealth;
void LocalPlayer::hurtTo(float newHealth, ETelemetryChallenges damageSource) {
float dmg = getHealth() - newHealth;
if (dmg <= 0) {
setHealth(newHealth);
if (dmg < 0) {
@ -660,8 +730,9 @@ void LocalPlayer::hurtTo(int newHealth, ETelemetryChallenges damageSource) {
hurtTime = hurtDuration = 10;
}
if (this->health <= 0) {
int deathTime = (int)(level->getTime() % Level::TICKS_PER_DAY) / 1000;
if (this->getHealth() <= 0) {
int deathTime =
(int)(level->getGameTime() % Level::TICKS_PER_DAY) / 1000;
int carriedId =
inventory->getSelected() == NULL ? 0 : inventory->getSelected()->id;
TelemetryManager->RecordPlayerDiedOrFailed(GetXboxPad(), 0, y, 0, 0,
@ -972,15 +1043,15 @@ void LocalPlayer::awardStat(Stat* stat, byteArray param) {
bool justPickedupWool = false;
for (int i = 0; i < 16; i++)
if (stat == GenericStats::itemsCollected(Tile::cloth_Id, i))
if (stat == GenericStats::itemsCollected(Tile::wool_Id, i))
justPickedupWool = true;
if (justPickedupWool) {
unsigned int woolCount = 0;
for (unsigned int i = 0; i < 16; i++) {
if (pStats->getTotalValue(GenericStats::itemsCollected(
Tile::cloth_Id, i)) > 0)
if (pStats->getTotalValue(
GenericStats::itemsCollected(Tile::wool_Id, i)) > 0)
woolCount++;
}
@ -1084,6 +1155,33 @@ void LocalPlayer::setExperienceValues(float experienceProgress, int totalExp,
this->experienceLevel = experienceLevel;
}
// 4J: removed
// void LocalPlayer::sendMessage(ChatMessageComponent *message)
//{
// minecraft->gui->getChat()->addMessage(message.toString(true));
//}
Pos LocalPlayer::getCommandSenderWorldPosition() {
return new Pos(floor(x + .5), floor(y + .5), floor(z + .5));
}
std::shared_ptr<ItemInstance> LocalPlayer::getCarriedItem() {
return inventory->getSelected();
}
void LocalPlayer::playSound(int soundId, float volume, float pitch) {
level->playLocalSound(x, y - heightOffset, z, soundId, volume, pitch,
false);
}
bool LocalPlayer::isRidingJumpable() {
return riding != NULL && riding->GetType() == eTYPE_HORSE;
}
float LocalPlayer::getJumpRidingScale() { return jumpRidingScale; }
void LocalPlayer::sendRidingJump() {}
bool LocalPlayer::hasPermission(EGameCommand command) {
return level->getLevelData()->getAllowCommands();
}
@ -1168,7 +1266,7 @@ void LocalPlayer::handleMouseDown(int button, bool down) {
minecraft->gameMode->continueDestroyBlock(x, y, z,
minecraft->hitResult->f);
if (mayBuild(x, y, z)) {
if (mayDestroyBlockAt(x, y, z)) {
minecraft->particleEngine->crack(x, y, z, minecraft->hitResult->f);
swing();
}
@ -1449,15 +1547,12 @@ void LocalPlayer::updateRichPresence() {
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_FISHING);
} else if (selectedItem != NULL && selectedItem->id == Item::map_Id) {
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_MAP);
} else if (riding != NULL &&
std::dynamic_pointer_cast<Minecart>(riding) != NULL) {
} else if ((riding != NULL) && riding->instanceof(eTYPE_MINECART)) {
app.SetRichPresenceContext(m_iPad,
CONTEXT_GAME_STATE_RIDING_MINECART);
} else if (riding != NULL &&
std::dynamic_pointer_cast<Boat>(riding) != NULL) {
} else if ((riding != NULL) && riding->instanceof(eTYPE_BOAT)) {
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_BOATING);
} else if (riding != NULL &&
std::dynamic_pointer_cast<Pig>(riding) != NULL) {
} else if ((riding != NULL) && riding->instanceof(eTYPE_PIG)) {
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_RIDING_PIG);
} else if (this->dimension == -1) {
app.SetRichPresenceContext(m_iPad, CONTEXT_GAME_STATE_NETHER);

View file

@ -21,6 +21,8 @@ class LocalPlayer : public Player {
public:
static const int SPRINT_DURATION = 20 * 30;
eINSTANCEOF GetType() { return eTYPE_LOCALPLAYER; }
Input* input;
protected:
@ -42,24 +44,23 @@ public:
float yBob, xBob;
float yBobO, xBobO;
float portalTime;
float oPortalTime;
LocalPlayer(Minecraft* minecraft, Level* level, User* user, int dimension);
virtual ~LocalPlayer();
void move(
double xa, double ya, double za,
bool noEntityCubes = false); // 4J - added noEntityCubes parameter
int m_iScreenSection; // assuming 4player splitscreen for now, or -1 for
// single player
__uint64
uint64_t
ullButtonsPressed; // Stores the button presses, since the inputmanager
// can be ticked faster than the minecraft player
// tick, and a button press and release combo can be
// missed in the minecraft::tick
// can be ticked faster than the minecraft
// player tick, and a button press and release combo can be missed in the
// minecraft::tick
__uint64 ullDpad_last;
__uint64 ullDpad_this;
__uint64 ullDpad_filtered;
uint64_t ullDpad_last;
uint64_t ullDpad_this;
uint64_t ullDpad_filtered;
// 4J-PB - moved these in from the minecraft structure, since they are per
// player things for splitscreen
@ -74,6 +75,9 @@ public:
private:
float flyX, flyY, flyZ;
int jumpRidingTicks;
float jumpRidingScale;
protected:
// 4J-PB - player's xbox pad
int m_iPad;
@ -95,7 +99,7 @@ public:
virtual void serverAiStep();
protected:
bool isEffectiveAI();
bool isEffectiveAi();
public:
virtual void aiStep();
@ -104,26 +108,38 @@ public:
virtual void addAdditonalSaveData(CompoundTag* entityTag);
virtual void readAdditionalSaveData(CompoundTag* entityTag);
virtual void closeContainer();
virtual void openTextEdit(std::shared_ptr<SignTileEntity> sign);
virtual void openTextEdit(std::shared_ptr<TileEntity> sign);
virtual bool openContainer(
std::shared_ptr<Container> container); // 4J added bool return
virtual bool startCrafting(int x, int y, int z); // 4J added bool return
virtual bool startEnchanting(int x, int y, int z); // 4J added bool return
std::shared_ptr<Container> container); // 4J added bool return
virtual bool openHopper(
std::shared_ptr<HopperTileEntity> container); // 4J added bool return
virtual bool openHopper(
std::shared_ptr<MinecartHopper> container); // 4J added bool return
virtual bool openHorseInventory(
std::shared_ptr<EntityHorse> horse,
std::shared_ptr<Container> container); // 4J added bool return
virtual bool startCrafting(int x, int y, int z); // 4J added bool return
virtual bool openFireworks(int x, int y, int z); // 4J added
virtual bool startEnchanting(
int x, int y, int z, const std::wstring& name); // 4J added bool return
virtual bool startRepairing(int x, int y, int z);
virtual bool openFurnace(
std::shared_ptr<FurnaceTileEntity> furnace); // 4J added bool return
virtual bool openBrewingStand(std::shared_ptr<BrewingStandTileEntity>
brewingStand); // 4J added bool return
virtual bool openBeacon(
std::shared_ptr<BeaconTileEntity> beacon); // 4J added bool return
virtual bool openTrap(
std::shared_ptr<DispenserTileEntity> trap); // 4J added bool return
virtual bool openTrading(std::shared_ptr<Merchant> traderTarget);
virtual bool openTrading(std::shared_ptr<Merchant> traderTarget,
const std::wstring& name);
virtual void crit(std::shared_ptr<Entity> e);
virtual void magicCrit(std::shared_ptr<Entity> e);
virtual void take(std::shared_ptr<Entity> e, int orgCount);
virtual void chat(const std::wstring& message);
virtual bool isSneaking();
// virtual bool isIdle();
virtual void hurtTo(int newHealth, ETelemetryChallenges damageSource);
virtual void hurtTo(float newHealth, ETelemetryChallenges damageSource);
virtual void respawn();
virtual void animateRespawn();
virtual void displayClientMessage(int messageId);
@ -174,8 +190,8 @@ public:
// Minecraft.Client
virtual void onCrafted(std::shared_ptr<ItemInstance> item);
virtual void setAndBroadcastCustomSkin(std::uint32_t skinId);
virtual void setAndBroadcastCustomCape(std::uint32_t capeId);
virtual void setAndBroadcastCustomSkin(DWORD skinId);
virtual void setAndBroadcastCustomCape(DWORD capeId);
private:
bool isSolidBlock(int x, int y, int z);
@ -189,6 +205,17 @@ public:
void setExperienceValues(float experienceProgress, int totalExp,
int experienceLevel);
// virtual void sendMessage(ChatMessageComponent *message); // 4J: removed
virtual Pos getCommandSenderWorldPosition();
virtual std::shared_ptr<ItemInstance> getCarriedItem();
virtual void playSound(int soundId, float volume, float pitch);
bool isRidingJumpable();
float getJumpRidingScale();
protected:
virtual void sendRidingJump();
public:
bool hasPermission(EGameCommand command);
void updateRichPresence();
@ -197,7 +224,6 @@ public:
float m_sessionTimeStart;
float m_dimensionTimeStart;
public:
void SetSessionTimerStart(void);
float getSessionTimer(void);

View file

@ -19,8 +19,8 @@ MultiPlayerGameMode::MultiPlayerGameMode(Minecraft* minecraft,
xDestroyBlock = -1;
yDestroyBlock = -1;
zDestroyBlock = -1;
destroyingItem = nullptr;
destroyProgress = 0;
oDestroyProgress = 0;
destroyTicks = 0;
destroyDelay = 0;
isDestroying = false;
@ -58,8 +58,18 @@ bool MultiPlayerGameMode::canHurtPlayer() {
}
bool MultiPlayerGameMode::destroyBlock(int x, int y, int z, int face) {
if (localPlayerMode->isReadOnly()) {
return false;
if (localPlayerMode->isAdventureRestricted()) {
if (!minecraft->player->mayDestroyBlockAt(x, y, z)) {
return false;
}
}
if (localPlayerMode->isCreative()) {
if (minecraft->player->getCarriedItem() != NULL &&
dynamic_cast<WeaponItem*>(
minecraft->player->getCarriedItem()->getItem()) != NULL) {
return false;
}
}
Level* level = minecraft->level;
@ -72,10 +82,11 @@ bool MultiPlayerGameMode::destroyBlock(int x, int y, int z, int face) {
oldTile->id + (level->getData(x, y, z) << Tile::TILE_NUM_SHIFT));
int data = level->getData(x, y, z);
bool changed = level->setTile(x, y, z, 0);
bool changed = level->removeTile(x, y, z);
if (changed) {
oldTile->destroy(level, x, y, z, data);
}
yDestroyBlock = -1;
if (!localPlayerMode->isCreative()) {
std::shared_ptr<ItemInstance> item =
@ -93,8 +104,11 @@ bool MultiPlayerGameMode::destroyBlock(int x, int y, int z, int face) {
void MultiPlayerGameMode::startDestroyBlock(int x, int y, int z, int face) {
if (!minecraft->player->isAllowedToMine()) return;
if (localPlayerMode->isReadOnly()) {
return;
if (localPlayerMode->isAdventureRestricted()) {
if (!minecraft->player->mayDestroyBlockAt(x, y, z)) {
return;
}
}
if (localPlayerMode->isCreative()) {
@ -103,8 +117,13 @@ void MultiPlayerGameMode::startDestroyBlock(int x, int y, int z, int face) {
PlayerActionPacket::START_DESTROY_BLOCK, x, y, z, face)));
creativeDestroyBlock(minecraft, this, x, y, z, face);
destroyDelay = 5;
} else if (!isDestroying || x != xDestroyBlock || y != yDestroyBlock ||
z != zDestroyBlock) {
} else if (!isDestroying || !sameDestroyTarget(x, y, z)) {
if (isDestroying) {
connection->send(
std::shared_ptr<PlayerActionPacket>(new PlayerActionPacket(
PlayerActionPacket::ABORT_DESTROY_BLOCK, xDestroyBlock,
yDestroyBlock, zDestroyBlock, face)));
}
connection->send(
std::shared_ptr<PlayerActionPacket>(new PlayerActionPacket(
PlayerActionPacket::START_DESTROY_BLOCK, x, y, z, face)));
@ -114,18 +133,18 @@ void MultiPlayerGameMode::startDestroyBlock(int x, int y, int z, int face) {
minecraft->player);
if (t > 0 &&
(Tile::tiles[t]->getDestroyProgress(
minecraft->player, minecraft->player->level, x, y, z) >= 1 ||
(app.DebugSettingsOn() &&
app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad()) &
(1L << eDebugSetting_InstantDestroy)))) {
minecraft->player, minecraft->player->level, x, y, z) >= 1
// ||(app.DebugSettingsOn() &&
// app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad())&(1L<<eDebugSetting_InstantDestroy))
)) {
destroyBlock(x, y, z, face);
} else {
isDestroying = true;
xDestroyBlock = x;
yDestroyBlock = y;
zDestroyBlock = z;
destroyingItem = minecraft->player->getCarriedItem();
destroyProgress = 0;
oDestroyProgress = 0;
destroyTicks = 0;
minecraft->level->destroyTileProgress(
minecraft->player->entityId, xDestroyBlock, yDestroyBlock,
@ -170,7 +189,7 @@ void MultiPlayerGameMode::continueDestroyBlock(int x, int y, int z, int face) {
return;
}
if (x == xDestroyBlock && y == yDestroyBlock && z == zDestroyBlock) {
if (sameDestroyTarget(x, y, z)) {
int t = minecraft->level->getTile(x, y, z);
if (t == 0) {
isDestroying = false;
@ -201,7 +220,6 @@ void MultiPlayerGameMode::continueDestroyBlock(int x, int y, int z, int face) {
PlayerActionPacket::STOP_DESTROY_BLOCK, x, y, z, face)));
destroyBlock(x, y, z, face);
destroyProgress = 0;
oDestroyProgress = 0;
destroyTicks = 0;
destroyDelay = 5;
}
@ -223,10 +241,23 @@ float MultiPlayerGameMode::getPickRange() {
void MultiPlayerGameMode::tick() {
ensureHasSentCarriedItem();
oDestroyProgress = destroyProgress;
// minecraft->soundEngine->playMusicTick();
}
bool MultiPlayerGameMode::sameDestroyTarget(int x, int y, int z) {
std::shared_ptr<ItemInstance> selected =
minecraft->player->getCarriedItem();
bool sameItems = destroyingItem == NULL && selected == NULL;
if (destroyingItem != NULL && selected != NULL) {
sameItems = selected->id == destroyingItem->id &&
ItemInstance::tagMatches(selected, destroyingItem) &&
(selected->isDamageableItem() ||
selected->getAuxValue() == destroyingItem->getAuxValue());
}
return x == xDestroyBlock && y == yDestroyBlock && z == zDestroyBlock &&
sameItems;
}
void MultiPlayerGameMode::ensureHasSentCarriedItem() {
int newItem = minecraft->player->inventory->selected;
if (newItem != carriedItem) {
@ -251,31 +282,34 @@ bool MultiPlayerGameMode::useItemOn(std::shared_ptr<Player> player,
float clickY = (float)hit->y - y;
float clickZ = (float)hit->z - z;
bool didSomething = false;
int t = level->getTile(x, y, z);
if (t > 0 && player->isAllowedToUse(Tile::tiles[t])) {
if (bTestUseOnly) {
switch (t) {
case Tile::recordPlayer_Id:
case Tile::bed_Id: // special case for a bed
if (Tile::tiles[t]->TestUse(level, x, y, z, player)) {
return true;
} else if (t == Tile::bed_Id) // 4J-JEV: You can still use
// items on record players
// (ie. set fire to them).
{
// bed is too far away, or something
return false;
}
break;
default:
if (Tile::tiles[t]->TestUse()) return true;
break;
if (!player->isSneaking() || player->getCarriedItem() == NULL) {
int t = level->getTile(x, y, z);
if (t > 0 && player->isAllowedToUse(Tile::tiles[t])) {
if (bTestUseOnly) {
switch (t) {
case Tile::jukebox_Id:
case Tile::bed_Id: // special case for a bed
if (Tile::tiles[t]->TestUse(level, x, y, z, player)) {
return true;
} else if (t ==
Tile::bed_Id) // 4J-JEV: You can still use
// items on record players
// (ie. set fire to them).
{
// bed is too far away, or something
return false;
}
break;
default:
if (Tile::tiles[t]->TestUse()) return true;
break;
}
} else {
if (Tile::tiles[t]->use(level, x, y, z, player, face, clickX,
clickY, clickZ))
didSomething = true;
}
} else {
if (Tile::tiles[t]->use(level, x, y, z, player, face, clickX,
clickY, clickZ))
didSomething = true;
}
}
@ -306,6 +340,7 @@ bool MultiPlayerGameMode::useItemOn(std::shared_ptr<Player> player,
}
}
} else {
int t = level->getTile(x, y, z);
// 4J - Bit of a hack, however seems preferable to any larger changes
// which would have more chance of causing unwanted side effects. If we
// aren't going to be actually performing the use method locally, then
@ -355,7 +390,7 @@ bool MultiPlayerGameMode::useItem(std::shared_ptr<Player> player, Level* level,
// 4J-PB added for tooltips to test use only
if (bTestUseOnly) {
result = item->TestUse(level, player);
result = item->TestUse(item, level, player);
} else {
int oldCount = item->count;
std::shared_ptr<ItemInstance> itemInstance = item->use(level, player);
@ -445,7 +480,9 @@ void MultiPlayerGameMode::releaseUsingItem(std::shared_ptr<Player> player) {
player->releaseUsingItem();
}
bool MultiPlayerGameMode::hasExperience() { return true; }
bool MultiPlayerGameMode::hasExperience() {
return localPlayerMode->isSurvival();
}
bool MultiPlayerGameMode::hasMissTime() {
return !localPlayerMode->isCreative();
@ -459,6 +496,13 @@ bool MultiPlayerGameMode::hasFarPickRange() {
return localPlayerMode->isCreative();
}
// Returns true when the inventory is opened from the server-side. Currently
// only happens when the player is riding a horse.
bool MultiPlayerGameMode::isServerControlledInventory() {
return minecraft->player->isRiding() &&
minecraft->player->riding->instanceof(eTYPE_HORSE);
}
bool MultiPlayerGameMode::handleCraftItem(int recipe,
std::shared_ptr<Player> player) {
short changeUid = player->containerMenu->backup(player->inventory);

View file

@ -9,8 +9,8 @@ private:
int xDestroyBlock;
int yDestroyBlock;
int zDestroyBlock;
std::shared_ptr<ItemInstance> destroyingItem;
float destroyProgress;
float oDestroyProgress;
int destroyTicks; // 4J was float but doesn't seem to need to be
int destroyDelay;
bool isDestroying;
@ -22,7 +22,6 @@ protected:
public:
MultiPlayerGameMode(Minecraft* minecraft, ClientConnection* connection);
virtual ~MultiPlayerGameMode() {}
static void creativeDestroyBlock(Minecraft* minecraft,
MultiPlayerGameMode* gameMode, int x,
int y, int z, int face);
@ -42,6 +41,7 @@ private:
int carriedItem;
private:
bool sameDestroyTarget(int x, int y, int z);
void ensureHasSentCarriedItem();
public:
@ -70,6 +70,7 @@ public:
virtual bool hasMissTime();
virtual bool hasInfiniteItems();
virtual bool hasFarPickRange();
virtual bool isServerControlledInventory();
// 4J Stu - Added so we can send packets for this in the network game
virtual bool handleCraftItem(int recipe, std::shared_ptr<Player> player);
@ -80,4 +81,4 @@ public:
virtual bool isInputAllowed(int mapping) { return true; }
virtual bool isTutorial() { return false; }
virtual Tutorial* getTutorial() { return NULL; }
};
};

View file

@ -12,6 +12,13 @@
#include "../../Minecraft.World/Headers/net.minecraft.world.effect.h"
#include "../../Minecraft.World/Level/LevelData.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.entity.item.h"
#include "../Input/Input.h"
#include "../Rendering/LevelRenderer.h"
// 4J added for testing
#ifdef STRESS_TEST_MOVE
volatile bool stressTestEnabled = true;
#endif
MultiplayerLocalPlayer::MultiplayerLocalPlayer(Minecraft* minecraft,
Level* level, User* user,
@ -30,11 +37,11 @@ MultiplayerLocalPlayer::MultiplayerLocalPlayer(Minecraft* minecraft,
this->connection = connection;
}
bool MultiplayerLocalPlayer::hurt(DamageSource* source, int dmg) {
bool MultiplayerLocalPlayer::hurt(DamageSource* source, float dmg) {
return false;
}
void MultiplayerLocalPlayer::heal(int heal) {}
void MultiplayerLocalPlayer::heal(float heal) {}
void MultiplayerLocalPlayer::tick() {
// 4J Added
@ -57,14 +64,31 @@ void MultiplayerLocalPlayer::tick() {
if (!level->hasChunkAt(Mth::floor(x), 0, Mth::floor(z))) return;
double tempX = x, tempY = y, tempZ = z;
LocalPlayer::tick();
// 4J added for testing
#ifdef STRESS_TEST_MOVE
if (stressTestEnabled) {
StressTestMove(&tempX, &tempY, &tempZ);
}
#endif
// if( !minecraft->localgameModes[m_iPad]->isTutorial() ||
// minecraft->localgameModes[m_iPad]->getTutorial()->canMoveToPosition(tempX,
// tempY, tempZ, x, y, z) )
if (minecraft->localgameModes[m_iPad]->getTutorial()->canMoveToPosition(
tempX, tempY, tempZ, x, y, z)) {
sendPosition();
if (isRiding()) {
connection->send(
std::shared_ptr<MovePlayerPacket>(new MovePlayerPacket::Rot(
yRot, xRot, onGround, abilities.flying)));
connection->send(
std::shared_ptr<PlayerInputPacket>(new PlayerInputPacket(
xxa, yya, input->jumping, input->sneaking)));
} else {
sendPosition();
}
} else {
// app.Debugprintf("Cannot move to position (%f, %f, %f), falling back
// to (%f, %f, %f)\n", x, y, z, tempX, y, tempZ);
@ -189,7 +213,8 @@ void MultiplayerLocalPlayer::respawn() {
new ClientCommandPacket(ClientCommandPacket::PERFORM_RESPAWN)));
}
void MultiplayerLocalPlayer::actuallyHurt(DamageSource* source, int dmg) {
void MultiplayerLocalPlayer::actuallyHurt(DamageSource* source, float dmg) {
if (isInvulnerable()) return;
setHealth(getHealth() - dmg);
}
@ -216,7 +241,8 @@ void MultiplayerLocalPlayer::onEffectAdded(MobEffectInstance* effect) {
Player::onEffectAdded(effect);
}
void MultiplayerLocalPlayer::onEffectUpdated(MobEffectInstance* effect) {
void MultiplayerLocalPlayer::onEffectUpdated(MobEffectInstance* effect,
bool doRefreshAttributes) {
Minecraft* pMinecraft = Minecraft::GetInstance();
if (pMinecraft->localgameModes[m_iPad] != NULL) {
TutorialMode* gameMode =
@ -224,7 +250,7 @@ void MultiplayerLocalPlayer::onEffectUpdated(MobEffectInstance* effect) {
Tutorial* tutorial = gameMode->getTutorial();
tutorial->onEffectChanged(MobEffect::effects[effect->getId()]);
}
Player::onEffectUpdated(effect);
Player::onEffectUpdated(effect, doRefreshAttributes);
}
void MultiplayerLocalPlayer::onEffectRemoved(MobEffectInstance* effect) {
@ -241,11 +267,16 @@ void MultiplayerLocalPlayer::onEffectRemoved(MobEffectInstance* effect) {
void MultiplayerLocalPlayer::closeContainer() {
connection->send(std::shared_ptr<ContainerClosePacket>(
new ContainerClosePacket(containerMenu->containerId)));
clientSideCloseContainer();
}
// close the container without sending a packet to the server
void MultiplayerLocalPlayer::clientSideCloseContainer() {
inventory->setCarried(nullptr);
LocalPlayer::closeContainer();
}
void MultiplayerLocalPlayer::hurtTo(int newHealth,
void MultiplayerLocalPlayer::hurtTo(float newHealth,
ETelemetryChallenges damageSource) {
if (flashOnSetHealth) {
LocalPlayer::hurtTo(newHealth, damageSource);
@ -283,11 +314,30 @@ void MultiplayerLocalPlayer::onUpdateAbilities() {
bool MultiplayerLocalPlayer::isLocalPlayer() { return true; }
void MultiplayerLocalPlayer::sendRidingJump() {
connection->send(
std::shared_ptr<PlayerCommandPacket>(new PlayerCommandPacket(
shared_from_this(), PlayerCommandPacket::RIDING_JUMP,
(int)(getJumpRidingScale() * 100.0f))));
}
void MultiplayerLocalPlayer::sendOpenInventory() {
connection->send(
std::shared_ptr<PlayerCommandPacket>(new PlayerCommandPacket(
shared_from_this(), PlayerCommandPacket::OPEN_INVENTORY)));
}
void MultiplayerLocalPlayer::ride(std::shared_ptr<Entity> e) {
bool wasRiding = riding != NULL;
LocalPlayer::ride(e);
bool isRiding = riding != NULL;
// 4J Added
if (wasRiding && !isRiding) {
setSneaking(false);
input->sneaking = false;
}
if (isRiding) {
ETelemetryChallenges eventType = eTelemetryChallenges_Unknown;
if (this->riding != NULL) {
@ -301,8 +351,6 @@ void MultiplayerLocalPlayer::ride(std::shared_ptr<Entity> e) {
case eTYPE_PIG:
eventType = eTelemetryInGame_Ride_Pig;
break;
default:
break;
};
}
TelemetryManager->RecordEnemyKilledOrOvercome(GetXboxPad(), 0, y, 0, 0,
@ -320,12 +368,7 @@ void MultiplayerLocalPlayer::ride(std::shared_ptr<Entity> e) {
gameMode->getTutorial()->changeTutorialState(
e_Tutorial_State_Gameplay);
} else if (!wasRiding && isRiding) {
if (std::dynamic_pointer_cast<Minecart>(e) != NULL)
gameMode->getTutorial()->changeTutorialState(
e_Tutorial_State_Riding_Minecart);
else if (std::dynamic_pointer_cast<Boat>(e) != NULL)
gameMode->getTutorial()->changeTutorialState(
e_Tutorial_State_Riding_Boat);
gameMode->getTutorial()->onRideEntity(e);
}
}
}
@ -363,3 +406,78 @@ void MultiplayerLocalPlayer::setAndBroadcastCustomCape(std::uint32_t capeId) {
shared_from_this(), TextureChangePacket::e_TextureChange_Cape,
app.GetPlayerCapeName(GetXboxPad()))));
}
// 4J added for testing. This moves the player in a repeated sequence of 2
// modes: Mode 0 - teleports to random location in the world, and waits for the
// number of chunks that are fully loaded/created to have setting for 2 seconds
// before changing to mode 1 Mode 1 - picks a random direction to move in for
// 200 ticks (~10 seconds), repeating for a total of 2000 ticks, before cycling
// back to mode 0 Whilst carrying out this movement pattern, this calls
// checkAllPresentChunks which checks the integrity of all currently
// loaded/created chunks round the player.
#ifdef STRESS_TEST_MOVE
void MultiplayerLocalPlayer::StressTestMove(double* tempX, double* tempY,
double* tempZ) {
static volatile int64_t lastChangeTime = 0;
static volatile int64_t lastTeleportTime = 0;
static int lastCount = 0;
static int stressTestCount = 0;
const int dirChangeTickCount = 200;
int64_t currentTime = System::currentTimeMillis();
bool faultFound = false;
int count = Minecraft::GetInstance()->levelRenderer->checkAllPresentChunks(
&faultFound);
/*
if( faultFound )
{
app.DebugPrintf("Fault found\n");
stressTestEnabled = false;
}
*/
if (count != lastCount) {
lastChangeTime = currentTime;
lastCount = count;
}
static float angle = 30.0;
static float dx = cos(30.0);
static float dz = sin(30.0);
#if 0
if( ( stressTestCount % dirChangeTickCount) == 0 )
{
int angledeg = rand() % 360;
angle = (((double)angledeg) / 360.0 ) * ( 2.0 * 3.141592654 );
dx = cos(angle);
dz = sin(angle);
}
#endif
float nx = x + (dx * 1.2);
float nz = z + (dz * 1.2);
float ny = y;
if (ny < 140.0f) ny += 0.5f;
if (nx > 2539.0) {
nx = 2539.0;
dx = -dx;
}
if (nz > 2539.0) {
nz = 2539.0;
dz = -dz;
}
if (nx < -2550.0) {
nx = -2550.0;
dx = -dx;
}
if (nz < -2550.0) {
nz = -2550.0;
dz = -dz;
}
absMoveTo(nx, ny, nz, yRot, xRot);
stressTestCount++;
}
#endif

View file

@ -7,6 +7,8 @@ class ClientConnection;
class Minecraft;
class Level;
// #define STRESS_TEST_MOVE
class MultiplayerLocalPlayer : public LocalPlayer {
private:
static const int POSITION_REMINDER_INTERVAL =
@ -27,8 +29,8 @@ private:
float yRotLast, xRotLast;
public:
virtual bool hurt(DamageSource* source, int dmg);
virtual void heal(int heal);
virtual bool hurt(DamageSource* source, float dmg);
virtual void heal(float heal);
virtual void tick();
private:
@ -53,24 +55,32 @@ public:
virtual void respawn();
protected:
virtual void actuallyHurt(DamageSource* source, int dmg);
virtual void actuallyHurt(DamageSource* source, float dmg);
// 4J Added override to capture event for tutorial messages
virtual void completeUsingItem();
// 4J Added overrides to capture events for tutorial
virtual void onEffectAdded(MobEffectInstance* effect);
virtual void onEffectUpdated(MobEffectInstance* effect);
virtual void onEffectUpdated(MobEffectInstance* effect,
bool doRefreshAttributes);
virtual void onEffectRemoved(MobEffectInstance* effect);
public:
virtual void closeContainer();
virtual void hurtTo(int newHealth, ETelemetryChallenges damageSource);
void clientSideCloseContainer();
virtual void hurtTo(float newHealth, ETelemetryChallenges damageSource);
virtual void awardStat(Stat* stat, byteArray param);
void awardStatFromServer(Stat* stat, byteArray param);
void onUpdateAbilities();
bool isLocalPlayer();
protected:
virtual void sendRidingJump();
public:
virtual void sendOpenInventory();
// 4J - send the custom skin texture data if there is one
// void CustomSkin(PBYTE pbData, DWORD dwBytes);
@ -81,6 +91,11 @@ public:
virtual void StopSleeping();
// 4J Added
virtual void setAndBroadcastCustomSkin(std::uint32_t skinId);
virtual void setAndBroadcastCustomCape(std::uint32_t capeId);
virtual void setAndBroadcastCustomSkin(DWORD skinId);
virtual void setAndBroadcastCustomCape(DWORD capeId);
// 4J added for testing
#ifdef STRESS_TEST_MOVE
void StressTestMove(double* tempX, double* tempY, double* tempZ);
#endif
};

View file

@ -4,34 +4,28 @@
#include "../../Minecraft.World/Util/Mth.h"
RemotePlayer::RemotePlayer(Level* level, const std::wstring& name)
: Player(level) {
: Player(level, name) {
// 4J - added initialisers
hasStartedUsingItem = false;
lSteps = 0;
lx = ly = lz = lyr = lxr = 0.0;
fallTime = 0.0f;
this->name = name;
m_UUID = name;
app.DebugPrintf("Created RemotePlayer with name %ls\n", name.c_str());
heightOffset = 0;
this->footSize = 0;
if (name.length() > 0) {
customTextureUrl = L""; // L"http://s3.amazonaws.com/MinecraftSkins/" +
// name + L".png";
}
footSize = 0;
this->noPhysics = true;
noPhysics = true;
bedOffsetY = 4 / 16.0f;
this->viewScale = 10;
viewScale = 10;
}
void RemotePlayer::setDefaultHeadHeight() { heightOffset = 0; }
bool RemotePlayer::hurt(DamageSource* source, int dmg) { return true; }
bool RemotePlayer::hurt(DamageSource* source, float dmg) { return true; }
void RemotePlayer::lerpTo(double x, double y, double z, float yRot, float xRot,
int steps) {
@ -99,8 +93,8 @@ void RemotePlayer::aiStep() {
xRot += (float)((lxr - xRot) / lSteps);
lSteps--;
this->setPos(xt, yt, zt);
this->setRot(yRot, xRot);
setPos(xt, yt, zt);
setRot(yRot, xRot);
}
oBob = bob;
@ -129,4 +123,8 @@ void RemotePlayer::animateRespawn() {
// Player.animateRespawn(this, level);
}
float RemotePlayer::getHeadHeight() { return 1.82f; }
float RemotePlayer::getHeadHeight() { return 1.82f; }
Pos RemotePlayer::getCommandSenderWorldPosition() {
return new Pos(floor(x + .5), floor(y + .5), floor(z + .5));
}

View file

@ -5,6 +5,9 @@
class Input;
class RemotePlayer : public Player {
public:
eINSTANCEOF GetType() { return eTYPE_REMOTEPLAYER; }
private:
bool hasStartedUsingItem;
@ -16,7 +19,7 @@ protected:
virtual void setDefaultHeadHeight();
public:
virtual bool hurt(DamageSource* source, int dmg);
virtual bool hurt(DamageSource* source, float dmg);
private:
int lSteps;
@ -39,4 +42,5 @@ public:
virtual void animateRespawn();
virtual float getHeadHeight();
bool hasPermission(EGameCommand command) { return false; }
virtual Pos getCommandSenderWorldPosition();
};

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,10 @@ class Stat;
class TileEntity;
class Entity;
class BrewingStandTileEntity;
class HopperTileEntity;
class MinecartHopper;
class BeaconTileEntity;
class EntityHorse;
class Merchant;
class ServerPlayer : public Player,
@ -29,12 +33,14 @@ public:
Biome* currentBiome;
private:
int lastSentHealth;
float lastRecordedHealthAndAbsorption;
float lastSentHealth;
int lastSentFood;
bool lastFoodSaturationZero;
int lastSentExp;
int invulnerableTime;
int viewDistance;
int64_t lastActionTime;
int lastBrupSendTickCount; // 4J Added
public:
@ -46,15 +52,9 @@ public:
virtual void readAdditionalSaveData(CompoundTag* entityTag);
virtual void addAdditonalSaveData(CompoundTag* entityTag);
virtual void withdrawExperienceLevels(int amount);
virtual void giveExperienceLevels(int amount);
void initMenu();
private:
ItemInstanceArray lastCarried;
public:
virtual ItemInstanceArray getEquipmentSlots();
protected:
virtual void setDefaultHeadHeight();
@ -64,13 +64,14 @@ public:
void flushEntitiesToRemove();
virtual std::shared_ptr<ItemInstance> getCarried(int slot);
virtual void die(DamageSource* source);
virtual bool hurt(DamageSource* dmgSource, int dmg);
virtual bool isPlayerVersusPlayer();
virtual bool hurt(DamageSource* dmgSource, float dmg);
virtual bool canHarmPlayer(std::shared_ptr<Player> target);
bool canHarmPlayer(std::wstring targetName); // 4J: Added
void doTick(bool sendChunks, bool dontDelayChunks = false,
bool ignorePortal = false);
void doTickA();
void doChunkSendingTick(bool dontDelayChunks);
void doTickB(bool ignorePortal);
void doTickB();
virtual void changeDimension(int i);
private:
@ -78,7 +79,6 @@ private:
public:
virtual void take(std::shared_ptr<Entity> e, int orgCount);
virtual void swing();
virtual BedSleepingResult startSleepInBed(int x, int y, int z,
bool bTestUse = false);
@ -106,19 +106,27 @@ private:
void nextContainerCounter();
public:
virtual bool startCrafting(int x, int y, int z); // 4J added bool return
virtual bool startEnchanting(int x, int y, int z); // 4J added bool return
virtual bool startRepairing(int x, int y, int z); // 4J added bool return
virtual void openTextEdit(std::shared_ptr<TileEntity> sign);
virtual bool startCrafting(int x, int y, int z); // 4J added bool return
virtual bool openFireworks(int x, int y, int z); // 4J added
virtual bool startEnchanting(
int x, int y, int z, const std::wstring& name); // 4J added bool return
virtual bool startRepairing(int x, int y, int z); // 4J added bool return
virtual bool openContainer(
std::shared_ptr<Container> container); // 4J added bool return
virtual bool openHopper(std::shared_ptr<HopperTileEntity> container);
virtual bool openHopper(std::shared_ptr<MinecartHopper> container);
virtual bool openFurnace(
std::shared_ptr<FurnaceTileEntity> furnace); // 4J added bool return
virtual bool openTrap(
std::shared_ptr<DispenserTileEntity> trap); // 4J added bool return
virtual bool openBrewingStand(std::shared_ptr<BrewingStandTileEntity>
brewingStand); // 4J added bool return
virtual bool openTrading(
std::shared_ptr<Merchant> traderTarget); // 4J added bool return
virtual bool openBeacon(std::shared_ptr<BeaconTileEntity> beacon);
virtual bool openTrading(std::shared_ptr<Merchant> traderTarget,
const std::wstring& name); // 4J added bool return
virtual bool openHorseInventory(std::shared_ptr<EntityHorse> horse,
std::shared_ptr<Container> container);
virtual void slotChanged(AbstractContainerMenu* container, int slotIndex,
std::shared_ptr<ItemInstance> item);
void refreshContainer(AbstractContainerMenu* menu);
@ -130,8 +138,7 @@ public:
virtual void closeContainer();
void broadcastCarriedItem();
void doCloseContainer();
void setPlayerInput(float xa, float ya, bool jumping, bool sneaking,
float xRot, float yRot);
void setPlayerInput(float xa, float ya, bool jumping, bool sneaking);
virtual void awardStat(Stat* stat, byteArray param);
@ -150,7 +157,8 @@ public:
protected:
virtual void onEffectAdded(MobEffectInstance* effect);
virtual void onEffectUpdated(MobEffectInstance* effect);
virtual void onEffectUpdated(MobEffectInstance* effect,
bool doRefreshAttributes);
virtual void onEffectRemoved(MobEffectInstance* effect);
public:
@ -166,11 +174,14 @@ public:
ChatPacket::EChatPacketMessage type = ChatPacket::e_ChatCustom,
int customData = -1, const std::wstring& additionalMessage = L"");
bool hasPermission(EGameCommand command);
// 4J - Don't use
// void updateOptions(std::shared_ptr<ClientInformationPacket> packet);
// bool hasPermission(int permissionLevel, EGameCommand command);
// void updateOptions(std::shared_ptr<ClientInformationPacket> packet); //
// 4J: Don't use
int getViewDistance();
// bool canChatInColor();
// int getChatVisibility();
Pos* getCommandSenderWorldPosition();
void resetLastActionTime();
public:
static int getFlagIndexForChunk(const ChunkPos& pos,

View file

@ -118,8 +118,10 @@ void ServerPlayerGameMode::tick() {
void ServerPlayerGameMode::startDestroyBlock(int x, int y, int z, int face) {
if (!player->isAllowedToMine()) return;
if (gameModeForPlayer->isReadOnly()) {
return;
if (gameModeForPlayer->isAdventureRestricted()) {
if (!player->mayDestroyBlockAt(x, y, z)) {
return;
}
}
if (isCreative()) {
@ -138,9 +140,12 @@ void ServerPlayerGameMode::startDestroyBlock(int x, int y, int z, int face) {
Tile::tiles[t]->getDestroyProgress(player, player->level, x, y, z);
}
if (t > 0 && (progress >= 1 || (app.DebugSettingsOn() &&
(player->GetDebugOptions() &
(1L << eDebugSetting_InstantDestroy))))) {
if (t > 0 &&
(progress >=
1)) //|| (app.DebugSettingsOn() &&
//(player->GetDebugOptions()&(1L<<eDebugSetting_InstantDestroy)
//) )))
{
destroyBlock(x, y, z);
} else {
isDestroyingBlock = true;
@ -164,7 +169,7 @@ void ServerPlayerGameMode::stopDestroyBlock(int x, int y, int z) {
// MGH - removed checking for the destroy progress here, it has
// already been checked on the client before it sent the packet.
// fixes issues with this failing to destroy
//because of packets bunching up
// because of packets bunching up
// float destroyProgress =
// tile->getDestroyProgress(player, player->level, x, y,
// z) * (ticksSpentDestroying + 1); if (destroyProgress
@ -201,7 +206,7 @@ bool ServerPlayerGameMode::superDestroyBlock(int x, int y, int z) {
oldTile->playerWillDestroy(level, x, y, z, data, player);
}
bool changed = level->setTile(x, y, z, 0);
bool changed = level->removeTile(x, y, z);
if (oldTile != NULL && changed) {
oldTile->destroy(level, x, y, z, data);
}
@ -209,8 +214,18 @@ bool ServerPlayerGameMode::superDestroyBlock(int x, int y, int z) {
}
bool ServerPlayerGameMode::destroyBlock(int x, int y, int z) {
if (gameModeForPlayer->isReadOnly()) {
return false;
if (gameModeForPlayer->isAdventureRestricted()) {
if (!player->mayDestroyBlockAt(x, y, z)) {
return false;
}
}
if (gameModeForPlayer->isCreative()) {
if (player->getCarriedItem() != NULL &&
dynamic_cast<WeaponItem*>(player->getCarriedItem()->getItem()) !=
NULL) {
return false;
}
}
int t = level->getTile(x, y, z);
@ -293,17 +308,23 @@ bool ServerPlayerGameMode::useItem(std::shared_ptr<Player> player, Level* level,
int oldCount = item->count;
int oldAux = item->getAuxValue();
std::shared_ptr<ItemInstance> itemInstance = item->use(level, player);
if ((itemInstance != NULL && itemInstance != item) ||
(itemInstance != NULL && itemInstance->count != oldCount) ||
(itemInstance != NULL && itemInstance->getUseDuration() > 0)) {
if (itemInstance != item ||
(itemInstance != NULL && (itemInstance->count != oldCount ||
itemInstance->getUseDuration() > 0 ||
itemInstance->getAuxValue() != oldAux))) {
player->inventory->items[player->inventory->selected] = itemInstance;
if (isCreative()) {
itemInstance->count = oldCount;
itemInstance->setAuxValue(oldAux);
if (itemInstance->isDamageableItem())
itemInstance->setAuxValue(oldAux);
}
if (itemInstance->count == 0) {
player->inventory->items[player->inventory->selected] = nullptr;
}
if (!player->isUsingItem()) {
std::dynamic_pointer_cast<ServerPlayer>(player)->refreshContainer(
player->inventoryMenu);
}
return true;
}
return false;
@ -317,14 +338,16 @@ bool ServerPlayerGameMode::useItemOn(std::shared_ptr<Player> player,
bool bTestUseOnOnly, bool* pbUsedItem) {
// 4J-PB - Adding a test only version to allow tooltips to be displayed
int t = level->getTile(x, y, z);
if (t > 0 && player->isAllowedToUse(Tile::tiles[t])) {
if (bTestUseOnOnly) {
if (Tile::tiles[t]->TestUse()) return true;
} else {
if (Tile::tiles[t]->use(level, x, y, z, player, face, clickX,
clickY, clickZ)) {
if (m_gameRules != NULL) m_gameRules->onUseTile(t, x, y, z);
return true;
if (!player->isSneaking() || player->getCarriedItem() == NULL) {
if (t > 0 && player->isAllowedToUse(Tile::tiles[t])) {
if (bTestUseOnOnly) {
if (Tile::tiles[t]->TestUse()) return true;
} else {
if (Tile::tiles[t]->use(level, x, y, z, player, face, clickX,
clickY, clickZ)) {
if (m_gameRules != NULL) m_gameRules->onUseTile(t, x, y, z);
return true;
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -25,7 +25,8 @@ private:
bool updatedPlayerVisibility;
bool trackDelta;
int teleportDelay;
std::shared_ptr<Entity> wasRiding;
std::shared_ptr<Entity> lastRidingEntity;
bool wasRiding;
public:
bool moved;
@ -39,6 +40,11 @@ public:
void tick(EntityTracker* tracker,
std::vector<std::shared_ptr<Player> >* players);
private:
void sendDirtyEntityData();
public:
void broadcast(std::shared_ptr<Packet> packet);
void broadcastAndSend(std::shared_ptr<Packet> packet);
void broadcastRemoved();

View file

@ -5,8 +5,8 @@
std::vector<Tile*> User::allowedTiles;
void User::staticCtor() {
allowedTiles.push_back(Tile::rock);
allowedTiles.push_back(Tile::stoneBrick);
allowedTiles.push_back(Tile::stone);
allowedTiles.push_back(Tile::cobblestone);
allowedTiles.push_back(Tile::redBrick);
allowedTiles.push_back(Tile::dirt);
allowedTiles.push_back(Tile::wood);
@ -16,17 +16,17 @@ void User::staticCtor() {
allowedTiles.push_back(Tile::stoneSlabHalf);
allowedTiles.push_back(Tile::glass);
allowedTiles.push_back(Tile::mossStone);
allowedTiles.push_back(Tile::mossyCobblestone);
allowedTiles.push_back(Tile::sapling);
allowedTiles.push_back(Tile::flower);
allowedTiles.push_back(Tile::rose);
allowedTiles.push_back(Tile::mushroom1);
allowedTiles.push_back(Tile::mushroom2);
allowedTiles.push_back(Tile::mushroom_brown);
allowedTiles.push_back(Tile::mushroom_red);
allowedTiles.push_back(Tile::sand);
allowedTiles.push_back(Tile::gravel);
allowedTiles.push_back(Tile::sponge);
allowedTiles.push_back(Tile::cloth);
allowedTiles.push_back(Tile::wool);
allowedTiles.push_back(Tile::coalOre);
allowedTiles.push_back(Tile::ironOre);
allowedTiles.push_back(Tile::goldOre);