mirror of
https://git.neolegacy.dev/neoStudiosLCE/neoLegacy.git
synced 2026-11-19 12:04:15 +01:00
Co-authored-by: DrPerkyLegit <116128211+DrPerkyLegit@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Anaël <60509176+Bakoubak@users.noreply.github.com> Reviewed-on: https://git.neolegacy.dev/neoStudiosLCE/neoLegacy/pulls/4205
90 lines
2.1 KiB
C++
90 lines
2.1 KiB
C++
#include "stdafx.h"
|
|
#include "SoundTypes.h"
|
|
#include "net.minecraft.world.phys.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.level.tile.h"
|
|
#include "net.minecraft.world.level.material.h"
|
|
#include "net.minecraft.world.entity.player.h"
|
|
#include "WaterLilyTileItem.h"
|
|
|
|
WaterLilyTileItem::WaterLilyTileItem(int id) : ColoredTileItem(id, false)
|
|
{
|
|
}
|
|
|
|
bool WaterLilyTileItem::TestUse(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player)
|
|
{
|
|
HitResult *hr = getPlayerPOVHitResult(level, player, true);
|
|
if (hr == nullptr) return false;
|
|
|
|
if (hr->type == HitResult::TILE)
|
|
{
|
|
int xt = hr->x;
|
|
int yt = hr->y;
|
|
int zt = hr->z;
|
|
if (!level->mayInteract(player, xt, yt, zt, 0))
|
|
{
|
|
delete hr;
|
|
return false;
|
|
}
|
|
if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance))
|
|
{
|
|
delete hr;
|
|
return false;
|
|
}
|
|
|
|
delete hr;
|
|
if (level->getMaterial(xt, yt, zt) == Material::water && level->getData(xt, yt, zt) == 0 && level->isEmptyTile(xt, yt + 1, zt))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
delete hr;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> WaterLilyTileItem::use(shared_ptr<ItemInstance> itemInstance, Level *level, shared_ptr<Player> player)
|
|
{
|
|
HitResult *hr = getPlayerPOVHitResult(level, player, true);
|
|
if (hr == nullptr) return itemInstance;
|
|
|
|
if (hr->type == HitResult::TILE)
|
|
{
|
|
int xt = hr->x;
|
|
int yt = hr->y;
|
|
int zt = hr->z;
|
|
if (!level->mayInteract(player, xt, yt, zt, 0))
|
|
{
|
|
delete hr;
|
|
return itemInstance;
|
|
}
|
|
if (!player->mayUseItemAt(xt, yt, zt, hr->f, itemInstance))
|
|
{
|
|
delete hr;
|
|
return itemInstance;
|
|
}
|
|
|
|
delete hr;
|
|
if (level->getMaterial(xt, yt, zt) == Material::water && level->getData(xt, yt, zt) == 0 && level->isEmptyTile(xt, yt + 1, zt))
|
|
{
|
|
level->setTileAndUpdate(xt, yt + 1, zt, Tile::waterLily->id);
|
|
level->playSound(xt + 0.5, yt + 1.5, zt + 0.5, eSoundType_BLOCK_WATERLILY_PLACE, 1.0f, 1.0f);
|
|
if (!player->abilities.instabuild)
|
|
{
|
|
itemInstance->count--;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
delete hr;
|
|
}
|
|
return itemInstance;
|
|
}
|
|
|
|
int WaterLilyTileItem::getColor(int data, int spriteLayer)
|
|
{
|
|
return Tile::waterLily->getColor(data);
|
|
} |