Updated to use smartcmd's MinecraftConsoles

This commit is contained in:
AlexBarthel
2026-03-08 13:41:16 -05:00
parent b682d5b1c4
commit c2974b66a6
7631 changed files with 841377 additions and 127862 deletions
+89 -41
View File
@@ -6,6 +6,7 @@
#include "Minecraft.h"
#include "ClientConnection.h"
#include "LevelRenderer.h"
#include "Common\Network\GameNetworkManager.h"
#include "..\Minecraft.World\net.minecraft.world.level.h"
#include "..\Minecraft.World\net.minecraft.world.item.h"
#include "..\Minecraft.World\net.minecraft.world.entity.player.h"
@@ -19,8 +20,8 @@ MultiPlayerGameMode::MultiPlayerGameMode(Minecraft *minecraft, ClientConnection
xDestroyBlock = -1;
yDestroyBlock = -1;
zDestroyBlock = -1;
destroyingItem = nullptr;
destroyProgress = 0;
oDestroyProgress = 0;
destroyTicks = 0;
destroyDelay = 0;
isDestroying = false;
@@ -66,10 +67,19 @@ bool MultiPlayerGameMode::canHurtPlayer()
bool MultiPlayerGameMode::destroyBlock(int x, int y, int z, int face)
{
if (localPlayerMode->isReadOnly())
if (localPlayerMode->isAdventureRestricted()) {
if (!minecraft->player->mayDestroyBlockAt(x, y, z)) {
return false;
}
}
if (localPlayerMode->isCreative())
{
return false;
}
if (minecraft->player->getCarriedItem() != NULL && dynamic_cast<WeaponItem *>(minecraft->player->getCarriedItem()->getItem()) != NULL)
{
return false;
}
}
Level *level = minecraft->level;
Tile *oldTile = Tile::tiles[level->getTile(x, y, z)];
@@ -79,11 +89,12 @@ bool MultiPlayerGameMode::destroyBlock(int x, int y, int z, int face)
level->levelEvent(LevelEvent::PARTICLES_DESTROY_BLOCK, x, y, z, 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())
{
@@ -104,25 +115,36 @@ 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())
if (localPlayerMode->isAdventureRestricted())
{
return;
}
if (!minecraft->player->mayDestroyBlockAt(x, y, z))
{
return;
}
}
if (localPlayerMode->isCreative())
{
// Skip if we just broke a block — prevents double-break on single clicks
if (destroyDelay > 0) return;
connection->send(shared_ptr<PlayerActionPacket>( new PlayerActionPacket(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(shared_ptr<PlayerActionPacket>(new PlayerActionPacket(PlayerActionPacket::ABORT_DESTROY_BLOCK, xDestroyBlock, yDestroyBlock, zDestroyBlock, face)));
}
connection->send( shared_ptr<PlayerActionPacket>( new PlayerActionPacket(PlayerActionPacket::START_DESTROY_BLOCK, x, y, z, face) ) );
int t = minecraft->level->getTile(x, y, z);
if (t > 0 && destroyProgress == 0) Tile::tiles[t]->attack(minecraft->level, x, y, z, 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))
(Tile::tiles[t]->getDestroyProgress(minecraft->player, minecraft->player->level, x, y, z) >= 1
// ||(app.DebugSettingsOn() && app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad())&(1L<<eDebugSetting_InstantDestroy))
)
)
{
@@ -134,8 +156,8 @@ void MultiPlayerGameMode::startDestroyBlock(int x, int y, int z, int face)
xDestroyBlock = x;
yDestroyBlock = y;
zDestroyBlock = z;
destroyProgress = 0;
oDestroyProgress = 0;
destroyingItem = minecraft->player->getCarriedItem();
destroyProgress = 0;
destroyTicks = 0;
minecraft->level->destroyTileProgress(minecraft->player->entityId, xDestroyBlock, yDestroyBlock, zDestroyBlock, (int)(destroyProgress * 10) - 1);
}
@@ -152,6 +174,7 @@ void MultiPlayerGameMode::stopDestroyBlock()
isDestroying = false;
destroyProgress = 0;
destroyDelay = 0;
minecraft->level->destroyTileProgress(minecraft->player->entityId, xDestroyBlock, yDestroyBlock, zDestroyBlock, -1);
}
@@ -175,7 +198,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)
@@ -205,7 +228,6 @@ void MultiPlayerGameMode::continueDestroyBlock(int x, int y, int z, int face)
connection->send( shared_ptr<PlayerActionPacket>( new PlayerActionPacket(PlayerActionPacket::STOP_DESTROY_BLOCK, x, y, z, face) ) );
destroyBlock(x, y, z, face);
destroyProgress = 0;
oDestroyProgress = 0;
destroyTicks = 0;
destroyDelay = 5;
}
@@ -231,10 +253,23 @@ float MultiPlayerGameMode::getPickRange()
void MultiPlayerGameMode::tick()
{
ensureHasSentCarriedItem();
oDestroyProgress = destroyProgress;
//minecraft->soundEngine->playMusicTick();
}
bool MultiPlayerGameMode::sameDestroyTarget(int x, int y, int z)
{
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;
@@ -258,34 +293,37 @@ bool MultiPlayerGameMode::useItemOn(shared_ptr<Player> player, Level *level, sha
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 (!player->isSneaking() || player->getCarriedItem() == NULL)
{
if(bTestUseOnly)
int t = level->getTile(x, y, z);
if (t > 0 && player->isAllowedToUse(Tile::tiles[t]))
{
switch(t)
if(bTestUseOnly)
{
case Tile::recordPlayer_Id:
case Tile::bed_Id: // special case for a bed
if (Tile::tiles[t]->TestUse(level, x, y, z, player ))
switch(t)
{
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;
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;
}
}
@@ -321,13 +359,16 @@ bool MultiPlayerGameMode::useItemOn(shared_ptr<Player> player, Level *level, sha
}
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 call this method with its "soundOnly" parameter set to true.
// This is an addition from the java version, and as its name suggests, doesn't actually perform the use locally but just makes any sounds that
// are meant to be directly caused by this. If we don't do this, then the sounds never happen as the tile's use method is only called on the
// server, and that won't allow any sounds that are directly made, or broadcast back level events to us that would make the sound, since we are
// the source of the event.
if( ( t > 0 ) && ( !bTestUseOnly ) && player->isAllowedToUse(Tile::tiles[t]) )
// ---------------------------------------------------------------------------------
// Only call soundOnly version if we didn't already call the tile's use method above
if( !didSomething && ( t > 0 ) && ( !bTestUseOnly ) && player->isAllowedToUse(Tile::tiles[t]) )
{
Tile::tiles[t]->use(level, x, y, z, player, face, clickX, clickY, clickZ, true);
}
@@ -361,7 +402,7 @@ bool MultiPlayerGameMode::useItem(shared_ptr<Player> player, Level *level, share
// 4J-PB added for tooltips to test use only
if(bTestUseOnly)
{
result = item->TestUse(level, player);
result = item->TestUse(item, level, player);
}
else
{
@@ -444,7 +485,7 @@ void MultiPlayerGameMode::releaseUsingItem(shared_ptr<Player> player)
bool MultiPlayerGameMode::hasExperience()
{
return true;
return localPlayerMode->isSurvival();
}
bool MultiPlayerGameMode::hasMissTime()
@@ -462,6 +503,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, shared_ptr<Player> player)
{
short changeUid = player->containerMenu->backup(player->inventory);