the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.phys.h"
3#include "net.minecraft.world.entity.player.h"
4#include "net.minecraft.world.level.h"
5#include "net.minecraft.world.level.material.h"
6#include "net.minecraft.world.item.h"
7#include "BottleItem.h"
8
9BottleItem::BottleItem(int id) : Item(id)
10{
11}
12
13Icon *BottleItem::getIcon(int auxValue)
14{
15 return Item::potion->getIcon(0);
16}
17
18shared_ptr<ItemInstance> BottleItem::use(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player)
19{
20 HitResult *hr = getPlayerPOVHitResult(level, player, true);
21 if (hr == NULL) return itemInstance;
22
23 if (hr->type == HitResult::TILE)
24 {
25 int xt = hr->x;
26 int yt = hr->y;
27 int zt = hr->z;
28 delete hr;
29
30 if (!level->mayInteract(player, xt, yt, zt, 0))
31 {
32 return itemInstance;
33 }
34 if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance))
35 {
36 return itemInstance;
37 }
38 if (level->getMaterial(xt, yt, zt) == Material::water)
39 {
40 itemInstance->count--;
41 if (itemInstance->count <= 0)
42 {
43 return shared_ptr<ItemInstance>( new ItemInstance( (Item *)Item::potion) );
44 }
45 else
46 {
47 if (!player->inventory->add(shared_ptr<ItemInstance>( new ItemInstance( (Item *)Item::potion) )))
48 {
49 player->drop( shared_ptr<ItemInstance>( new ItemInstance(Item::potion_Id, 1, 0) ));
50 }
51 }
52 }
53 }
54 else
55 {
56 delete hr;
57 }
58
59 return itemInstance;
60}
61
62// 4J-PB - added to allow tooltips
63bool BottleItem::TestUse(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player)
64{
65 HitResult *hr = getPlayerPOVHitResult(level, player, true);
66 if (hr == NULL) return false;
67
68 if (hr->type == HitResult::TILE)
69 {
70 int xt = hr->x;
71 int yt = hr->y;
72 int zt = hr->z;
73 delete hr;
74
75 if (!level->mayInteract(player, xt, yt, zt, 0))
76 {
77 return false;
78 }
79 if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance))
80 {
81 return false;
82 }
83 if (level->getMaterial(xt, yt, zt) == Material::water)
84 {
85 return true;
86 }
87 }
88 else
89 {
90 delete hr;
91 }
92
93 return false;
94}
95
96void BottleItem::registerIcons(IconRegister *iconRegister)
97{
98 // We reuse another texture.
99}