2026-03-01 12:16:08 +08:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "net.minecraft.world.phys.h"
|
|
|
|
|
#include "net.minecraft.world.entity.player.h"
|
|
|
|
|
#include "net.minecraft.world.level.h"
|
|
|
|
|
#include "net.minecraft.world.level.material.h"
|
|
|
|
|
#include "net.minecraft.world.item.h"
|
|
|
|
|
#include "BottleItem.h"
|
|
|
|
|
|
|
|
|
|
BottleItem::BottleItem(int id) : Item(id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Icon *BottleItem::getIcon(int auxValue)
|
|
|
|
|
{
|
|
|
|
|
return Item::potion->getIcon(0);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 17:37:16 +07:00
|
|
|
shared_ptr<ItemInstance> BottleItem::use(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player)
|
2026-03-01 12:16:08 +08:00
|
|
|
{
|
|
|
|
|
HitResult *hr = getPlayerPOVHitResult(level, player, true);
|
2026-03-08 19:08:36 -04:00
|
|
|
if (hr == nullptr) return itemInstance;
|
2026-03-01 12:16:08 +08:00
|
|
|
|
|
|
|
|
if (hr->type == HitResult::TILE)
|
|
|
|
|
{
|
|
|
|
|
int xt = hr->x;
|
|
|
|
|
int yt = hr->y;
|
|
|
|
|
int zt = hr->z;
|
|
|
|
|
delete hr;
|
|
|
|
|
|
|
|
|
|
if (!level->mayInteract(player, xt, yt, zt, 0))
|
|
|
|
|
{
|
|
|
|
|
return itemInstance;
|
|
|
|
|
}
|
2026-03-03 03:04:10 +08:00
|
|
|
if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance))
|
2026-03-01 12:16:08 +08:00
|
|
|
{
|
|
|
|
|
return itemInstance;
|
|
|
|
|
}
|
|
|
|
|
if (level->getMaterial(xt, yt, zt) == Material::water)
|
|
|
|
|
{
|
|
|
|
|
itemInstance->count--;
|
|
|
|
|
if (itemInstance->count <= 0)
|
|
|
|
|
{
|
2026-03-08 19:08:36 -04:00
|
|
|
return std::make_shared<ItemInstance>(static_cast<Item *>(Item::potion));
|
2026-03-01 12:16:08 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-03-08 19:08:36 -04:00
|
|
|
if (!player->inventory->add(std::make_shared<ItemInstance>(static_cast<Item *>(Item::potion))))
|
2026-03-01 12:16:08 +08:00
|
|
|
{
|
2026-03-08 19:08:36 -04:00
|
|
|
player->drop(std::make_shared<ItemInstance>(Item::potion_Id, 1, 0));
|
2026-03-01 12:16:08 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
delete hr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return itemInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 4J-PB - added to allow tooltips
|
2026-03-03 03:04:10 +08:00
|
|
|
bool BottleItem::TestUse(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player)
|
2026-03-01 12:16:08 +08:00
|
|
|
{
|
|
|
|
|
HitResult *hr = getPlayerPOVHitResult(level, player, true);
|
2026-03-08 19:08:36 -04:00
|
|
|
if (hr == nullptr) return false;
|
2026-03-01 12:16:08 +08:00
|
|
|
|
|
|
|
|
if (hr->type == HitResult::TILE)
|
|
|
|
|
{
|
|
|
|
|
int xt = hr->x;
|
|
|
|
|
int yt = hr->y;
|
|
|
|
|
int zt = hr->z;
|
|
|
|
|
delete hr;
|
|
|
|
|
|
|
|
|
|
if (!level->mayInteract(player, xt, yt, zt, 0))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-03-03 03:04:10 +08:00
|
|
|
if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance))
|
2026-03-01 12:16:08 +08:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (level->getMaterial(xt, yt, zt) == Material::water)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
delete hr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BottleItem::registerIcons(IconRegister *iconRegister)
|
|
|
|
|
{
|
|
|
|
|
// We reuse another texture.
|
|
|
|
|
}
|