2026-03-01 12:16:08 +08:00
# pragma once
using namespace std ;
# include "UseAnim.h"
# include "com.mojang.nbt.h"
2026-03-03 03:04:10 +08:00
# include "Attribute.h"
2026-03-01 12:16:08 +08:00
class Entity ;
class Level ;
class Player ;
class Mob ;
2026-03-03 03:04:10 +08:00
class LivingEntity ;
2026-03-01 12:16:08 +08:00
class CompoundTag ;
class Enchantment ;
class Rarity ;
2026-03-03 03:04:10 +08:00
class AttributeModifier ;
class Random ;
2026-03-01 12:16:08 +08:00
// 4J-PB - added
class MapItem ;
class ItemFrame ;
class Icon ;
2026-03-03 03:04:10 +08:00
class HtmlString ;
2026-03-01 12:16:08 +08:00
// 4J Stu - While this is not really an abstract class, we don't want to make new instances of it,
// mainly because there are too many ctors and that doesn't fit well into out macroisation setup
class ItemInstance : public enable_shared_from_this < ItemInstance >
{
public :
2026-03-03 03:04:10 +08:00
static const wstring ATTRIBUTE_MODIFIER_FORMAT ;
2026-03-01 12:16:08 +08:00
static const wchar_t * TAG_ENCH_ID ;
2026-03-03 03:04:10 +08:00
static const wchar_t * TAG_ENCH_LEVEL ;
2026-03-01 12:16:08 +08:00
int count ;
2026-03-03 03:04:10 +08:00
int popTime ;
int id ;
2026-03-01 12:16:08 +08:00
// 4J Stu - Brought forward for enchanting/game rules
CompoundTag * tag ;
2026-03-03 03:04:10 +08:00
/**
* This was previously the damage value , but is now used for different stuff
* depending on item / tile . Use the getter methods to make sure the value
* is interpreted correctly .
*/
2026-03-01 12:16:08 +08:00
private :
int auxValue ;
// 4J-PB - added for trading menu
bool m_bForceNumberDisplay ;
void _init ( int id , int count , int auxValue ) ;
// TU9
2026-03-02 17:37:16 +07:00
shared_ptr < ItemFrame > frame ;
2026-03-01 12:16:08 +08:00
public :
ItemInstance ( Tile * tile ) ;
ItemInstance ( Tile * tile , int count ) ;
ItemInstance ( Tile * tile , int count , int auxValue ) ;
ItemInstance ( Item * item ) ;
// 4J-PB - added
ItemInstance ( MapItem * item , int count ) ;
ItemInstance ( Item * item , int count ) ;
ItemInstance ( Item * item , int count , int auxValue ) ;
ItemInstance ( int id , int count , int damage ) ;
2026-03-02 17:37:16 +07:00
static shared_ptr < ItemInstance > fromTag ( CompoundTag * itemTag ) ;
2026-03-01 12:16:08 +08:00
private :
ItemInstance ( ) { _init ( - 1 , 0 , 0 ) ; }
public :
~ ItemInstance ( ) ;
2026-03-02 17:37:16 +07:00
shared_ptr < ItemInstance > remove ( int count ) ;
2026-03-01 12:16:08 +08:00
Item * getItem ( ) const ;
Icon * getIcon ( ) ;
int getIconType ( ) ;
2026-03-02 17:37:16 +07:00
bool useOn ( shared_ptr < Player > player , Level * level , int x , int y , int z , int face , float clickX , float clickY , float clickZ , bool bTestUseOnOnly = false ) ;
2026-03-01 12:16:08 +08:00
float getDestroySpeed ( Tile * tile ) ;
2026-03-03 06:14:34 +07:00
bool TestUse ( shared_ptr < ItemInstance > itemInstance , Level * level , shared_ptr < Player > player ) ;
2026-03-02 17:37:16 +07:00
shared_ptr < ItemInstance > use ( Level * level , shared_ptr < Player > player ) ;
shared_ptr < ItemInstance > useTimeDepleted ( Level * level , shared_ptr < Player > player ) ;
2026-03-01 12:16:08 +08:00
CompoundTag * save ( CompoundTag * compoundTag ) ;
void load ( CompoundTag * compoundTag ) ;
2026-03-03 06:14:34 +07:00
int getMaxStackSize ( ) const ;
2026-03-01 12:16:08 +08:00
bool isStackable ( ) ;
bool isDamageableItem ( ) ;
bool isStackedByData ( ) ;
bool isDamaged ( ) ;
int getDamageValue ( ) ;
int getAuxValue ( ) const ;
void setAuxValue ( int value ) ;
int getMaxDamage ( ) ;
2026-03-03 03:04:10 +08:00
bool hurt ( int dmg , Random * random ) ;
void hurtAndBreak ( int dmg , shared_ptr < LivingEntity > owner ) ;
void hurtEnemy ( shared_ptr < LivingEntity > mob , shared_ptr < Player > attacker ) ;
2026-03-02 17:37:16 +07:00
void mineBlock ( Level * level , int tile , int x , int y , int z , shared_ptr < Player > owner ) ;
2026-03-01 12:16:08 +08:00
bool canDestroySpecial ( Tile * tile ) ;
2026-03-03 03:04:10 +08:00
bool interactEnemy ( shared_ptr < Player > player , shared_ptr < LivingEntity > mob ) ;
2026-03-02 17:37:16 +07:00
shared_ptr < ItemInstance > copy ( ) const ;
2026-03-01 12:16:08 +08:00
ItemInstance * copy_not_shared ( ) const ; // 4J Stu - Added for use in recipes
2026-03-02 17:37:16 +07:00
static bool tagMatches ( shared_ptr < ItemInstance > a , shared_ptr < ItemInstance > b ) ; // 4J Brought forward from 1.2
static bool matches ( shared_ptr < ItemInstance > a , shared_ptr < ItemInstance > b ) ;
2026-03-01 12:16:08 +08:00
// 4J-PB
int GetCount ( ) { return count ; }
void ForceNumberDisplay ( bool bForce ) { m_bForceNumberDisplay = bForce ; } // to force the display of 0 and 1 on the required trading items when you have o or 1 of the item
bool GetForceNumberDisplay ( ) { return m_bForceNumberDisplay ; } // to force the display of 0 and 1 on the required trading items when you have o or 1 of the item
private :
2026-03-02 17:37:16 +07:00
bool matches ( shared_ptr < ItemInstance > b ) ;
2026-03-01 12:16:08 +08:00
public :
2026-03-02 17:37:16 +07:00
bool sameItem ( shared_ptr < ItemInstance > b ) ;
bool sameItemWithTags ( shared_ptr < ItemInstance > b ) ; //4J Added
2026-03-03 06:14:34 +07:00
bool sameItem_not_shared ( const ItemInstance * b ) ; // 4J Stu - Added this for the one time I need it
2026-03-01 12:16:08 +08:00
virtual unsigned int getUseDescriptionId ( ) ; // 4J Added
virtual unsigned int getDescriptionId ( int iData = - 1 ) ;
virtual ItemInstance * setDescriptionId ( unsigned int id ) ;
2026-03-02 17:37:16 +07:00
static shared_ptr < ItemInstance > clone ( shared_ptr < ItemInstance > item ) ;
2026-03-01 12:16:08 +08:00
wstring toString ( ) ;
2026-03-02 17:37:16 +07:00
void inventoryTick ( Level * level , shared_ptr < Entity > owner , int slot , bool selected ) ;
void onCraftedBy ( Level * level , shared_ptr < Player > player , int craftCount ) ;
bool equals ( shared_ptr < ItemInstance > ii ) ;
2026-03-01 12:16:08 +08:00
int getUseDuration ( ) ;
UseAnim getUseAnimation ( ) ;
2026-03-02 17:37:16 +07:00
void releaseUsing ( Level * level , shared_ptr < Player > player , int durationLeft ) ;
2026-03-01 12:16:08 +08:00
// 4J Stu - Brought forward these functions for enchanting/game rules
bool hasTag ( ) ;
CompoundTag * getTag ( ) ;
ListTag < CompoundTag > * getEnchantmentTags ( ) ;
void setTag ( CompoundTag * tag ) ;
wstring getHoverName ( ) ;
void setHoverName ( const wstring & name ) ;
2026-03-03 03:04:10 +08:00
void resetHoverName ( ) ;
2026-03-01 12:16:08 +08:00
bool hasCustomHoverName ( ) ;
2026-03-03 03:04:10 +08:00
vector < HtmlString > * getHoverText ( shared_ptr < Player > player , bool advanced ) ;
vector < HtmlString > * getHoverTextOnly ( shared_ptr < Player > player , bool advanced ) ; // 4J Added
2026-03-01 12:16:08 +08:00
bool isFoil ( ) ;
const Rarity * getRarity ( ) ;
bool isEnchantable ( ) ;
void enchant ( const Enchantment * enchantment , int level ) ;
bool isEnchanted ( ) ;
void addTagElement ( wstring name , Tag * tag ) ;
2026-03-03 03:04:10 +08:00
bool mayBePlacedInAdventureMode ( ) ;
bool isFramed ( ) ;
void setFramed ( shared_ptr < ItemFrame > frame ) ;
shared_ptr < ItemFrame > getFrame ( ) ;
int getBaseRepairCost ( ) ;
void setRepairCost ( int cost ) ;
attrAttrModMap * getAttributeModifiers ( ) ;
2026-03-01 12:16:08 +08:00
// 4J Added
void set4JData ( int data ) ;
int get4JData ( ) ;
bool hasPotionStrengthBar ( ) ;
int GetPotionStrength ( ) ;
} ;