Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ add_library(reminecraftpe-core STATIC
world/item/ClothItem.cpp
world/item/DyeColor.cpp
world/item/SlabItem.cpp
world/item/ToolItem.cpp
world/item/HatchetItem.cpp
world/item/PickaxeItem.cpp
world/item/ShovelItem.cpp
world/particle/RedDustParticle.cpp
world/particle/TerrainParticle.cpp
world/particle/BubbleParticle.cpp
Expand Down
23 changes: 22 additions & 1 deletion source/client/renderer/entity/ItemRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,30 @@ void ItemRenderer::renderGuiItemOverlay(Font* font, Textures* textures, ItemStac
if (item.isEmpty())
return;

if (item.m_count == 1)
// Draw damage amount
if (item.isDamaged()) {
int duraWidth = ceilf(13.0 - static_cast<double>(item.getDamageValue()) * 13.0 / static_cast<double>(item.getMaxDamage()));
int duraPercent = ceilf(255.0 - static_cast<double>(item.getDamageValue()) * 255.0 / static_cast<double>(item.getMaxDamage()));


int duraBgColor = (((255 - duraPercent) / 4) << 16) | 0x3F00;
int duraColor = ((255 - duraPercent) << 16) | (duraPercent << 8);

Tesselator& t = Tesselator::instance;

blitRect(t, x + 2, y + 13, 13, 2, 0);
blitRect(t, x + 2, y + 13, 12, 1, duraBgColor);
blitRect(t, x + 2, y + 13, duraWidth, 1, duraColor);


glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}

if (item.m_count <= 1) {
return;
}

// Draw num items
std::stringstream ss;
ss << item.m_count;
std::string amtstr = ss.str();
Expand Down
36 changes: 35 additions & 1 deletion source/world/entity/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,15 @@ void Player::useItem(ItemStack& item) const

bool Player::canDestroy(const Tile* pTile) const
{
return true;
// If the tile's material does not need tool check then allow destroy regardless of equipped item
if (pTile->m_pMaterial->isMineable())
return true;

ItemStack& item = getSelectedItem();
if (!item.isEmpty())
return item.canDestroySpecial(pTile);

return false;
}

void Player::closeContainer()
Expand All @@ -347,6 +355,32 @@ void Player::displayClientMessage(const std::string& msg)

}

float Player::getDestroySpeed(const Tile* tile) const
{
float speed = 1.0f;

ItemStack& item = getSelectedItem();
if (!item.isEmpty())
{
// Original multiplies but there's no need since you're just multiplying by 1 on the first check.
speed = item.getDestroySpeed(tile);
}

// Speed penalty for being underwater
if (isUnderLiquid(Material::water))
{
speed /= 5.0F;
}

// Speed penalty for jumping/falling
if (!m_bOnGround)
{
speed /= 5.0F;
}

return speed;
}

int Player::getInventorySlot(int x) const
{
return 0;
Expand Down
2 changes: 1 addition & 1 deletion source/world/entity/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Player : public Mob
bool canDestroy(const Tile*) const;
void closeContainer();
void displayClientMessage(const std::string& msg);
float getDestroySpeed() const { return 1.0f; }
float getDestroySpeed(const Tile* tile) const;
int getInventorySlot(int x) const;
TilePos getRespawnPosition() const { return m_respawnPos; }
int getScore() const { return m_score; }
Expand Down
2 changes: 1 addition & 1 deletion source/world/gamemode/SurvivalMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool SurvivalMode::destroyBlock(Player* player, const TilePos& pos, Facing::Name
ItemStack& item = player->getSelectedItem();
if (!item.isEmpty())
{
item.mineBlock(pos, face);
item.mineBlock(pos, face, player);
if (item.m_count == 0)
{
item.snap(player);
Expand Down
16 changes: 16 additions & 0 deletions source/world/item/HatchetItem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "HatchetItem.hpp"
#include "world/tile/Tile.hpp"

HatchetItem::HatchetItem(int id, Tier& tier) : ToolItem(id, 1, tier)
{
static const Tile* hatchetTiles[] =
{
Tile::wood,
Tile::bookshelf,
Tile::treeTrunk,
// Tile::chest
};

static const int HATCHET_TILE_COUNT = sizeof(hatchetTiles) / sizeof(Tile*);
initializeTiles(hatchetTiles, HATCHET_TILE_COUNT);
}
9 changes: 9 additions & 0 deletions source/world/item/HatchetItem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "ToolItem.hpp"

class HatchetItem : public ToolItem
{
public:
HatchetItem(int id, Tier& tier);
};
52 changes: 27 additions & 25 deletions source/world/item/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "TileItem.hpp"
#include "TilePlanterItem.hpp"
#include "RocketItem.hpp"
#include "PickaxeItem.hpp"
#include "ShovelItem.hpp"
#include "HatchetItem.hpp"

#define ITEM(x) ((x) - 256)

Expand Down Expand Up @@ -119,17 +122,16 @@ void Item::initItems()
->setDescriptionId("swordWood")
->handEquipped();

Item::pickAxe_wood = NEW_ITEM(ITEM_PICKAXE_WOOD)
Item::pickAxe_wood = NEW_X_ITEM(PickaxeItem, ITEM_PICKAXE_WOOD, Tier::WOOD)
->setIcon(0, 6)
->setDescriptionId("pickaxeWood")
->handEquipped();
->setDescriptionId("pickaxeWood");

Item::hatchet_wood = NEW_ITEM(ITEM_HATCHET_WOOD)
Item::hatchet_wood = NEW_X_ITEM(HatchetItem, ITEM_HATCHET_WOOD, Tier::WOOD)
->setIcon(0, 7)
->setDescriptionId("hatchetWood")
->handEquipped();

Item::shovel_wood = NEW_ITEM(ITEM_SHOVEL_WOOD)
Item::shovel_wood = NEW_X_ITEM(ShovelItem, ITEM_SHOVEL_WOOD, Tier::WOOD)
->setIcon(0, 5)
->setDescriptionId("shovelWood")
->handEquipped();
Expand All @@ -144,17 +146,17 @@ void Item::initItems()
->setDescriptionId("swordStone")
->handEquipped();

Item::pickAxe_stone = NEW_ITEM(ITEM_PICKAXE_STONE)
Item::pickAxe_stone = NEW_X_ITEM(PickaxeItem, ITEM_PICKAXE_STONE, Tier::STONE)
->setIcon(1, 6)
->setDescriptionId("pickaxeStone")
->handEquipped();

Item::hatchet_stone = NEW_ITEM(ITEM_HATCHET_STONE)
Item::hatchet_stone = NEW_X_ITEM(HatchetItem, ITEM_HATCHET_STONE, Tier::STONE)
->setIcon(1, 7)
->setDescriptionId("hatchetStone")
->handEquipped();

Item::shovel_stone = NEW_ITEM(ITEM_SHOVEL_STONE)
Item::shovel_stone = NEW_X_ITEM(ShovelItem, ITEM_SHOVEL_STONE, Tier::STONE)
->setIcon(1, 5)
->setDescriptionId("shovelStone")
->handEquipped();
Expand All @@ -169,17 +171,17 @@ void Item::initItems()
->setDescriptionId("swordIron")
->handEquipped();

Item::pickAxe_iron = NEW_ITEM(ITEM_PICKAXE_IRON)
Item::pickAxe_iron = NEW_X_ITEM(PickaxeItem, ITEM_PICKAXE_IRON, Tier::IRON)
->setIcon(2, 6)
->setDescriptionId("pickaxeIron")
->handEquipped();

Item::hatchet_iron = NEW_ITEM(ITEM_HATCHET_IRON)
Item::hatchet_iron = NEW_X_ITEM(HatchetItem, ITEM_HATCHET_IRON, Tier::IRON)
->setIcon(2, 7)
->setDescriptionId("hatchetIron")
->handEquipped();

Item::shovel_iron= NEW_ITEM(ITEM_SHOVEL_IRON)
Item::shovel_iron= NEW_X_ITEM(ShovelItem, ITEM_SHOVEL_IRON, Tier::IRON)
->setIcon(2, 5)
->setDescriptionId("shovelIron")
->handEquipped();
Expand All @@ -194,17 +196,17 @@ void Item::initItems()
->setDescriptionId("swordGold")
->handEquipped();

Item::pickAxe_gold = NEW_ITEM(ITEM_PICKAXE_GOLD)
Item::pickAxe_gold = NEW_X_ITEM(PickaxeItem, ITEM_PICKAXE_GOLD, Tier::GOLD)
->setIcon(4, 6)
->setDescriptionId("pickaxeGold")
->handEquipped();

Item::hatchet_gold = NEW_ITEM(ITEM_HATCHET_GOLD)
Item::hatchet_gold = NEW_X_ITEM(HatchetItem, ITEM_HATCHET_GOLD, Tier::GOLD)
->setIcon(4, 7)
->setDescriptionId("hatchetGold")
->handEquipped();

Item::shovel_gold = NEW_ITEM(ITEM_SHOVEL_GOLD)
Item::shovel_gold = NEW_X_ITEM(ShovelItem, ITEM_SHOVEL_GOLD, Tier::GOLD)
->setIcon(4, 5)
->setDescriptionId("shovelGold")
->handEquipped();
Expand All @@ -219,17 +221,17 @@ void Item::initItems()
->setDescriptionId("swordDiamond")
->handEquipped();

Item::pickAxe_emerald = NEW_ITEM(ITEM_PICKAXE_EMERALD)
Item::pickAxe_emerald = NEW_X_ITEM(PickaxeItem, ITEM_PICKAXE_EMERALD, Tier::EMERALD)
->setIcon(3, 6)
->setDescriptionId("pickaxeDiamond")
->handEquipped();

Item::hatchet_emerald = NEW_ITEM(ITEM_HATCHET_EMERALD)
Item::hatchet_emerald = NEW_X_ITEM(HatchetItem, ITEM_HATCHET_EMERALD, Tier::EMERALD)
->setIcon(3, 7)
->setDescriptionId("hatchetDiamond")
->handEquipped();

Item::shovel_emerald = NEW_ITEM(ITEM_SHOVEL_EMERALD)
Item::shovel_emerald = NEW_X_ITEM(ShovelItem, ITEM_SHOVEL_EMERALD, Tier::EMERALD)
->setIcon(3, 5)
->setDescriptionId("shovelDiamond")
->handEquipped();
Expand Down Expand Up @@ -571,7 +573,7 @@ bool Item::useOn(ItemStack* instance, Player* player, Level* level, const TilePo
return false;
}

float Item::getDestroySpeed(ItemStack* instance, Tile* tile) const
float Item::getDestroySpeed(ItemStack* instance, const Tile* tile) const
{
return 1.0f;
}
Expand Down Expand Up @@ -606,7 +608,7 @@ void Item::hurtEnemy(ItemStack* instance, Mob* mob) const

}

void Item::mineBlock(ItemStack* instance, const TilePos& pos, Facing::Name face) const
void Item::mineBlock(ItemStack* instance, const TilePos& pos, Facing::Name face, Player* player) const
{

}
Expand All @@ -616,7 +618,7 @@ int Item::getAttackDamage(Entity* ent) const
return 1;
}

bool Item::canDestroySpecial(Tile* tile) const
bool Item::canDestroySpecial(const Tile* tile) const
{
return false;
}
Expand Down Expand Up @@ -800,10 +802,10 @@ Item
*Item::quiver;

Item::Tier
Item::Tier::WOOD (0, 59, 2.0f, 0),
Item::Tier::STONE (1, 131, 4.0f, 1),
Item::Tier::IRON (2, 250, 6.0f, 2),
Item::Tier::EMERALD(3, 1561, 8.0f, 3),
Item::Tier::GOLD (0, 32, 12.0f, 0);
Item::Tier::WOOD (0, 0/* 59 */, 2.0f, 0),
Item::Tier::STONE (1, 0/* 131 */, 4.0f, 1),
Item::Tier::IRON (2, 0/* 250 */, 6.0f, 2),
Item::Tier::EMERALD(3, 0/* 1561 */, 8.0f, 3),
Item::Tier::GOLD (0, 0/* 32 */, 12.0f, 0);

std::string Item::ICON_DESCRIPTION_PREFIX = "item.";
29 changes: 15 additions & 14 deletions source/world/item/Item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ class Item

struct Tier
{
int field_0;
int m_Durability;
float m_HitStrength;
int field_C;

Tier(int a, int b, float c, int d) :
field_0(a),
m_Durability(b),
m_HitStrength(c),
field_C(d)
{}
int m_level;
int m_uses;
float m_speed;
int m_damage;

Tier(int level, int uses, float speed, int damage) :
m_level(level),
m_uses(uses),
m_speed(speed),
m_damage(damage)
{
}

// Item tiers
static Tier WOOD, STONE, IRON, EMERALD, GOLD;
Expand All @@ -72,16 +73,16 @@ class Item
virtual int getIcon(const ItemStack*) const;
virtual bool useOn(ItemStack*, Level*, const TilePos& pos, Facing::Name face) const;
virtual bool useOn(ItemStack*, Player*, Level*, const TilePos& pos, Facing::Name face) const;
virtual float getDestroySpeed(ItemStack*, Tile*) const;
virtual float getDestroySpeed(ItemStack*, const Tile*) const;
virtual ItemStack* use(ItemStack*, Level*, Player*) const;
virtual int getMaxStackSize() const;
virtual TileData getLevelDataForAuxValue(int x) const;
virtual bool isStackedByData() const;
virtual int getMaxDamage() const;
virtual void hurtEnemy(ItemStack*, Mob*) const;
virtual void mineBlock(ItemStack*, const TilePos& pos, Facing::Name face) const;
virtual void mineBlock(ItemStack*, const TilePos& pos, Facing::Name face, Player* player) const;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should take a Mob*, not a Player*

virtual int getAttackDamage(Entity*) const;
virtual bool canDestroySpecial(Tile*) const;
virtual bool canDestroySpecial(const Tile*) const;
virtual void interactEnemy(ItemStack*, Mob*) const;
virtual Item* handEquipped();
virtual bool isHandEquipped() const;
Expand Down
Loading
Loading