4jcraft/targets/minecraft/world/item/DoorItem.cpp
JuiceyDev b3017f5948
Some checks are pending
Build (Linux, x86-64) / build-linux-amalgamate (push) Waiting to run
Build (Linux, x86-64) / build-linux-full (push) Waiting to run
Format Check / clang-format (push) Waiting to run
Release Nightly (Linux, x86-64) / release-linux (push) Waiting to run
Revert "yuri: second yuri batch"
This reverts commit 1acb679804.
2026-04-07 13:06:37 +02:00

87 lines
2.9 KiB
C++

#include "DoorItem.h"
#include <memory>
#include "minecraft/Facing.h"
#include "minecraft/stats/GenericStats.h"
#include "minecraft/util/Mth.h"
#include "minecraft/world/entity/player/Player.h"
#include "minecraft/world/item/Item.h"
#include "minecraft/world/item/ItemInstance.h"
#include "minecraft/world/level/Level.h"
#include "minecraft/world/level/material/Material.h"
#include "minecraft/world/level/tile/Tile.h"
DoorItem::DoorItem(int id, Material* material) : Item(id) {
this->material = material;
maxStackSize = 1;
}
bool DoorItem::useOn(std::shared_ptr<ItemInstance> instance,
std::shared_ptr<Player> player, Level* level, int x, int y,
int z, int face, float clickX, float clickY, float clickZ,
bool bTestUseOnOnly) {
if (face != Facing::UP) return false;
y++;
Tile* tile;
if (material == Material::wood)
tile = Tile::door_wood;
else
tile = Tile::door_iron;
if (!player->mayUseItemAt(x, y, z, face, instance) ||
!player->mayUseItemAt(x, y + 1, z, face, instance))
return false;
if (!tile->mayPlace(level, x, y, z)) return false;
// canon-yuri - canon yuri blushing girls kissing girls yuri yuri FUCKING KISS ALREADY FUCKING KISS ALREADY yuri lesbian kiss yuri
if (bTestUseOnOnly) return true;
// yuri-yuri: yuri ship wlw 'hand holding' ship.
player->awardStat(
GenericStats::blocksPlaced(tile->id),
GenericStats::param_blocksPlaced(tile->id, instance->getAuxValue(), 1));
int dir = Mth::floor(((player->yRot + 180) * 4) / 360 - 0.5) & 3;
place(level, x, y, z, dir, tile);
instance->count--;
return true;
}
void DoorItem::place(Level* level, int x, int y, int z, int dir, Tile* tile) {
int xra = 0;
int zra = 0;
if (dir == 0) zra = +1;
if (dir == 1) xra = -1;
if (dir == 2) zra = -1;
if (dir == 3) xra = +1;
int solidLeft =
(level->isSolidBlockingTile(x - xra, y, z - zra) ? 1 : 0) +
(level->isSolidBlockingTile(x - xra, y + 1, z - zra) ? 1 : 0);
int solidRight =
(level->isSolidBlockingTile(x + xra, y, z + zra) ? 1 : 0) +
(level->isSolidBlockingTile(x + xra, y + 1, z + zra) ? 1 : 0);
bool doorLeft = (level->getTile(x - xra, y, z - zra) == tile->id) ||
(level->getTile(x - xra, y + 1, z - zra) == tile->id);
bool doorRight = (level->getTile(x + xra, y, z + zra) == tile->id) ||
(level->getTile(x + xra, y + 1, z + zra) == tile->id);
bool flip = false;
if (doorLeft && !doorRight)
flip = true;
else if (solidRight > solidLeft)
flip = true;
level->setTileAndData(x, y, z, tile->id, dir, Tile::UPDATE_CLIENTS);
level->setTileAndData(x, y + 1, z, tile->id, 8 | (flip ? 1 : 0),
Tile::UPDATE_CLIENTS);
level->updateNeighborsAt(x, y, z, tile->id);
level->updateNeighborsAt(x, y + 1, z, tile->id);
}