mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-05-17 23:52:53 +00:00
Refactor pick block to use a dedicated MINECRAFT_ACTION and move logic to tick
This commit is contained in:
parent
5170b968b8
commit
8cbc7606ac
|
|
@ -862,6 +862,7 @@ enum EControllerActions
|
|||
MINECRAFT_ACTION_INVENTORY,
|
||||
MINECRAFT_ACTION_PAUSEMENU,
|
||||
MINECRAFT_ACTION_DROP,
|
||||
MINECRAFT_ACTION_PICK_ITEM,
|
||||
MINECRAFT_ACTION_SNEAK_TOGGLE,
|
||||
MINECRAFT_ACTION_CRAFTING,
|
||||
MINECRAFT_ACTION_RENDER_THIRD_PERSON,
|
||||
|
|
|
|||
|
|
@ -1479,83 +1479,9 @@ void Minecraft::run_middle()
|
|||
if(g_KBMInput.IsMouseButtonPressed(KeyboardMouseInput::MOUSE_RIGHT))
|
||||
localplayers[i]->ullButtonsPressed|=1LL<<MINECRAFT_ACTION_USE;
|
||||
|
||||
if (g_KBMInput.IsMouseButtonPressed(KeyboardMouseInput::MOUSE_MIDDLE) && hitResult && hitResult->type == HitResult::TILE)
|
||||
if (g_KBMInput.IsMouseButtonPressed(KeyboardMouseInput::MOUSE_MIDDLE))
|
||||
{
|
||||
auto inventory = localplayers[i]->inventory;
|
||||
auto inventoryMenu = localplayers[i]->inventoryMenu;
|
||||
bool isInCreative = gameMode->hasInfiniteItems();
|
||||
|
||||
int x = hitResult->x, y = hitResult->y, z = hitResult->z;
|
||||
|
||||
int containerId = inventoryMenu->containerId;
|
||||
int tileId = level->getTile(x, y, z);
|
||||
|
||||
if (tileId > 0 && tileId < Tile::TILE_NUM_COUNT)
|
||||
{
|
||||
Tile *tile = Tile::tiles[tileId];
|
||||
|
||||
int clonedTileId = tile->cloneTileId(level, x, y, z);
|
||||
int clonedTileData = tile->cloneTileData(level, x, y, z);
|
||||
|
||||
int itemSlot = inventory->getSlot(clonedTileId, clonedTileData);
|
||||
int firstEmpty = inventory->getFreeSlot();
|
||||
|
||||
if (itemSlot >= 0)
|
||||
{
|
||||
// Item is already in hotbar
|
||||
if (itemSlot < 9)
|
||||
{
|
||||
inventory->selected = itemSlot;
|
||||
}
|
||||
// There are free slots in the hotbar
|
||||
else if (firstEmpty >= 0 && firstEmpty < 9)
|
||||
{
|
||||
inventory->selected = firstEmpty;
|
||||
// Use quick move the item
|
||||
gameMode->handleInventoryMouseClick(
|
||||
containerId,
|
||||
itemSlot,
|
||||
AbstractContainerMenu::CLICK_QUICK_MOVE,
|
||||
true,
|
||||
localplayers[i]
|
||||
);
|
||||
}
|
||||
// Swap with item in inventory
|
||||
else {
|
||||
int currentHotbarSlot = inventory->selected;
|
||||
short changeUid = inventoryMenu->backup(inventory);
|
||||
|
||||
// Perform client side swap and sync with server using CLICK_SWAP to avoid ghost blocks
|
||||
shared_ptr<ItemInstance> clicked = inventoryMenu->clicked(
|
||||
itemSlot,
|
||||
currentHotbarSlot,
|
||||
AbstractContainerMenu::CLICK_SWAP,
|
||||
localplayers[i]
|
||||
);
|
||||
|
||||
localplayers[i]->connection->send(make_shared<ContainerClickPacket>(
|
||||
containerId,
|
||||
itemSlot,
|
||||
currentHotbarSlot,
|
||||
AbstractContainerMenu::CLICK_SWAP,
|
||||
clicked,
|
||||
changeUid
|
||||
));
|
||||
}
|
||||
}
|
||||
else if (isInCreative)
|
||||
{
|
||||
localplayers[i]->inventory->grabTexture(clonedTileId, clonedTileData, true, true);
|
||||
|
||||
shared_ptr<ItemInstance> selectedItem = localplayers[i]->inventory->getSelected();
|
||||
if (gameMode && selectedItem)
|
||||
{
|
||||
// Hotbar starts at slot 36
|
||||
// Sync new item instance with the server in creative mode
|
||||
gameMode->handleCreativeModeItemAdd(selectedItem, 36 + localplayers[i]->inventory->selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
localplayers[i]->ullButtonsPressed|=1LL<<MINECRAFT_ACTION_PICK_ITEM;
|
||||
}
|
||||
|
||||
if(g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_INVENTORY))
|
||||
|
|
@ -3890,6 +3816,85 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures)
|
|||
}
|
||||
if( !(player->ullButtonsPressed&(1LL<<MINECRAFT_ACTION_DROP)) || (selectedItem != NULL && selectedItem->GetCount() <= 1) ) ui.SetSelectedItem( iPad, itemName );
|
||||
}
|
||||
|
||||
if (player->ullButtonsPressed&(1LL<<MINECRAFT_ACTION_PICK_ITEM) && hitResult && hitResult->type == HitResult::TILE)
|
||||
{
|
||||
auto inventory = player->inventory;
|
||||
auto inventoryMenu = player->inventoryMenu;
|
||||
bool isInCreative = gameMode->hasInfiniteItems();
|
||||
|
||||
int x = hitResult->x, y = hitResult->y, z = hitResult->z;
|
||||
|
||||
int containerId = inventoryMenu->containerId;
|
||||
int tileId = level->getTile(x, y, z);
|
||||
|
||||
if (tileId > 0 && tileId < Tile::TILE_NUM_COUNT)
|
||||
{
|
||||
Tile *tile = Tile::tiles[tileId];
|
||||
|
||||
int clonedTileId = tile->cloneTileId(level, x, y, z);
|
||||
int clonedTileData = tile->cloneTileData(level, x, y, z);
|
||||
|
||||
int itemSlot = inventory->getSlot(clonedTileId, clonedTileData);
|
||||
int firstEmpty = inventory->getFreeSlot();
|
||||
|
||||
if (itemSlot >= 0)
|
||||
{
|
||||
// Item is already in hotbar
|
||||
if (itemSlot < 9)
|
||||
{
|
||||
inventory->selected = itemSlot;
|
||||
}
|
||||
// There are free slots in the hotbar
|
||||
else if (firstEmpty >= 0 && firstEmpty < 9)
|
||||
{
|
||||
inventory->selected = firstEmpty;
|
||||
// Use quick move the item
|
||||
gameMode->handleInventoryMouseClick(
|
||||
containerId,
|
||||
itemSlot,
|
||||
AbstractContainerMenu::CLICK_QUICK_MOVE,
|
||||
true,
|
||||
player
|
||||
);
|
||||
}
|
||||
// Swap with item in inventory
|
||||
else {
|
||||
int currentHotbarSlot = inventory->selected;
|
||||
short changeUid = inventoryMenu->backup(inventory);
|
||||
|
||||
// Perform client side swap and sync with server using CLICK_SWAP to avoid ghost blocks
|
||||
shared_ptr<ItemInstance> clicked = inventoryMenu->clicked(
|
||||
itemSlot,
|
||||
currentHotbarSlot,
|
||||
AbstractContainerMenu::CLICK_SWAP,
|
||||
player
|
||||
);
|
||||
|
||||
player->connection->send(make_shared<ContainerClickPacket>(
|
||||
containerId,
|
||||
itemSlot,
|
||||
currentHotbarSlot,
|
||||
AbstractContainerMenu::CLICK_SWAP,
|
||||
clicked,
|
||||
changeUid
|
||||
));
|
||||
}
|
||||
}
|
||||
else if (isInCreative)
|
||||
{
|
||||
inventory->grabTexture(clonedTileId, clonedTileData, true, true);
|
||||
|
||||
shared_ptr<ItemInstance> selectedItem = inventory->getSelected();
|
||||
if (gameMode && selectedItem)
|
||||
{
|
||||
// Hotbar starts at slot 36
|
||||
// Sync new item instance with the server in creative mode
|
||||
gameMode->handleCreativeModeItemAdd(selectedItem, 36 + player->inventory->selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue