[BlockCursor] Now reset breaking timer when switching item or activating a block. Thanks to obiwac who found these issues.
This commit is contained in:
parent
2251bc0b89
commit
54493e3d58
3
TODO
3
TODO
@ -20,7 +20,8 @@ TODO
|
||||
◦ DONE: When loading chunks with smooth lighting enabled, they have black borders
|
||||
◦ DONE: Flower lighting is weird
|
||||
◦ TODO: Trees should block light
|
||||
• TODO: `ServerWorld::sendWorldData` is useless and should be replaced by `sendSpawnData`
|
||||
• DONE: Reset breaking timer when right-clicking a block
|
||||
• DONE: Reset breaking timer when switching items
|
||||
• TODO: Shapeless recipe code isn’t working
|
||||
• TODO: GUI scale issues
|
||||
◦ TODO: `HUD` doesn’t update when GUI scale is changed
|
||||
|
@ -53,6 +53,7 @@ class BlockCursor : public gk::Drawable {
|
||||
unsigned int m_animationStart = 0;
|
||||
glm::vec4 m_selectedBlock{0, 0, 0, -1};
|
||||
const Block *m_currentBlock = nullptr;
|
||||
const ItemStack *m_currentTool = nullptr;
|
||||
};
|
||||
|
||||
#endif // BLOCKCURSOR_HPP_
|
||||
|
@ -67,8 +67,12 @@ void BlockCursor::onEvent(const SDL_Event &event, const Hotbar &hotbar) {
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN && m_selectedBlock.w != -1) {
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
m_animationStart = gk::GameClock::getTicks();
|
||||
m_currentTool = &m_player.inventory().getStack(hotbar.cursorPos(), 0);
|
||||
}
|
||||
else if (event.button.button == SDL_BUTTON_RIGHT) {
|
||||
if (m_animationStart != 0)
|
||||
m_animationStart = 0;
|
||||
|
||||
u32 blockId = m_world.getBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z);
|
||||
const Block &block = Registry::getInstance().getBlock(blockId);
|
||||
const Item &item = Registry::getInstance().getItem(hotbar.currentItem());
|
||||
@ -133,15 +137,22 @@ void BlockCursor::update(const Hotbar &hotbar, bool useDepthBuffer) {
|
||||
const ItemStack ¤tStack = m_player.inventory().getStack(hotbar.cursorPos(), 0);
|
||||
float timeToBreak = 0;
|
||||
if (m_animationStart) {
|
||||
timeToBreak = m_currentBlock->timeToBreak(currentStack.item().harvestCapability(), currentStack.item().miningSpeed());
|
||||
if (gk::GameClock::getTicks() > m_animationStart + timeToBreak * 1000) {
|
||||
ItemStack itemDrop = m_currentBlock->getItemDrop();
|
||||
m_player.inventory().addStack(itemDrop.item().name(), itemDrop.amount());
|
||||
m_world.setBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z, 0);
|
||||
if (m_currentTool->item().id() != currentStack.item().id()) {
|
||||
m_animationStart = gk::GameClock::getTicks();
|
||||
m_currentTool = ¤tStack;
|
||||
}
|
||||
else {
|
||||
timeToBreak = m_currentBlock->timeToBreak(currentStack.item().harvestCapability(), currentStack.item().miningSpeed());
|
||||
|
||||
m_client.sendPlayerDigBlock(m_selectedBlock);
|
||||
m_client.sendPlayerInvUpdate();
|
||||
if (gk::GameClock::getTicks() > m_animationStart + timeToBreak * 1000) {
|
||||
ItemStack itemDrop = m_currentBlock->getItemDrop();
|
||||
m_player.inventory().addStack(itemDrop.item().name(), itemDrop.amount());
|
||||
m_world.setBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z, 0);
|
||||
m_animationStart = gk::GameClock::getTicks();
|
||||
|
||||
m_client.sendPlayerDigBlock(m_selectedBlock);
|
||||
m_client.sendPlayerInvUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user