mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-05-25 07:46:07 +00:00
TU19: merge Minecraft.Client/Player
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user