From b691c43c44ff180d10e7d4a9afc83b98551ff586 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 12:16:08 +0800 Subject: Initial commit --- Minecraft.World/BottleItem.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Minecraft.World/BottleItem.cpp (limited to 'Minecraft.World/BottleItem.cpp') diff --git a/Minecraft.World/BottleItem.cpp b/Minecraft.World/BottleItem.cpp new file mode 100644 index 00000000..3aecafee --- /dev/null +++ b/Minecraft.World/BottleItem.cpp @@ -0,0 +1,99 @@ +#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); +} + +shared_ptr BottleItem::use(shared_ptr itemInstance, Level *level, shared_ptr player) +{ + HitResult *hr = getPlayerPOVHitResult(level, player, true); + if (hr == NULL) return itemInstance; + + 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; + } + if (!player->mayBuild(xt, yt, zt)) + { + return itemInstance; + } + if (level->getMaterial(xt, yt, zt) == Material::water) + { + itemInstance->count--; + if (itemInstance->count <= 0) + { + return shared_ptr( new ItemInstance( (Item *)Item::potion) ); + } + else + { + if (!player->inventory->add(shared_ptr( new ItemInstance( (Item *)Item::potion) ))) + { + player->drop( shared_ptr( new ItemInstance(Item::potion_Id, 1, 0) )); + } + } + } + } + else + { + delete hr; + } + + return itemInstance; +} + +// 4J-PB - added to allow tooltips +bool BottleItem::TestUse(Level *level, shared_ptr player) +{ + HitResult *hr = getPlayerPOVHitResult(level, player, true); + if (hr == NULL) return false; + + 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; + } + if (!player->mayBuild(xt, yt, zt)) + { + 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. +} \ No newline at end of file -- cgit v1.2.3