[Block] Item drop added. Now CoalOre drops Coal and Stone drops Cobblestone.

This commit is contained in:
Quentin Bazin 2018-06-29 21:18:48 +02:00
parent fb46ab479c
commit 95842ddc07
4 changed files with 14 additions and 4 deletions

View File

@ -18,6 +18,7 @@
#include "BlockType.hpp"
#include "IntTypes.hpp"
#include "ItemStack.hpp"
class Chunk;
class Player;
@ -45,6 +46,9 @@ class Block {
bool canUpdate() const { return m_canUpdate; }
ItemStack getItemDrop() const { return ItemStack{m_itemDrop, m_itemDropAmount}; };
void setItemDrop(u16 itemDrop, u16 itemDropAmount = 1) { m_itemDrop = itemDrop; m_itemDropAmount = itemDropAmount; }
protected:
glm::vec4 getTexCoordsFromID(int textureID) const;
@ -56,6 +60,9 @@ class Block {
bool m_isSelected = false;
s8 m_selectedFace = -1;
u16 m_itemDrop;
u16 m_itemDropAmount;
};
#endif // BLOCK_HPP_

View File

@ -27,11 +27,11 @@ void Registry::registerBlocks() {
registerBlock<Block>(BlockType::Grass, 226);
registerBlock<Block>(BlockType::Leaves, 266);
registerBlock<Block>(BlockType::Wood, 277);
registerBlock<Block>(BlockType::Stone, 402);
registerBlock<Block>(BlockType::Stone, 402).setItemDrop(ItemType::Cobblestone);
registerBlock<Block>(BlockType::Sand, 369);
registerBlock<BlockWater>();
registerBlock<Block>(BlockType::Glass, 168);
registerBlock<Block>(BlockType::CoalOre, 36);
registerBlock<Block>(BlockType::CoalOre, 36).setItemDrop(ItemType::Coal);
registerBlock<Block>(BlockType::Planks, 316);
registerBlock<Block>(BlockType::Glowstone, 218);
registerBlock<BlockWorkbench>();

View File

@ -134,8 +134,8 @@ void BlockCursor::update(Inventory &playerInventory, bool useDepthBuffer) {
m_selectedBlock = selectedBlock;
if (m_animationStart && GameClock::getTicks() > m_animationStart + 1000) {
u16 block = m_world.getBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z);
playerInventory.addStack(block);
ItemStack itemDrop = Registry::getInstance().getBlock(m_world.getBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z)).getItemDrop();
playerInventory.addStack(itemDrop.item().id(), itemDrop.amount());
m_world.setBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z, 0);
m_animationStart = GameClock::getTicks();
}

View File

@ -16,6 +16,9 @@
Block::Block(u32 id, u32 textureID) {
m_id = id;
m_textureID = textureID;
m_itemDrop = id;
m_itemDropAmount = 1;
}
glm::vec4 Block::getTexCoords(int face, u16) const {