#include "stdafx.h" #include "com.mojang.nbt.h" #include "net.minecraft.world.h" #include "net.minecraft.world.level.h" #include "net.minecraft.world.entity.h" #include "net.minecraft.world.entity.item.h" #include "net.minecraft.world.entity.player.h" #include "net.minecraft.world.item.h" #include "net.minecraft.world.inventory.h" #include "net.minecraft.world.phys.h" #include "Facing.h" #include "ShulkerBoxTileEntity.h" #include "ShulkerBoxTile.h" ShulkerBoxTile::ShulkerBoxTile(int id, int color) : BaseEntityTile(id, Material::stone, false) { this->color = color; } static const int SHULKER_BOX_TILE_RGB[16] = { 0xFFFFFF, 0xFF760B, 0xC341B6, 0x31A9E2, 0xFFC02B, 0x74C218, 0xF589A9, 0x4B4F52, 0x999991, 0x22919C, 0x9B6E9B, 0x3537A4, 0x7C4C29, 0x5F7928, 0xA81513, 0x2A2A2F }; void ShulkerBoxTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr forceEntity) { shared_ptr box = dynamic_pointer_cast(forceEntity); if (box == nullptr && level != nullptr) box = dynamic_pointer_cast(level->getTileEntity(x, y, z)); float grow = box != nullptr ? 0.5f * box->getProgress(1.0f) : 0.0f; int data = forceData >= 0 ? forceData : (level != nullptr ? level->getData(x, y, z) : 1); int facing = data % 6; float x0 = 0.0f, y0 = 0.0f, z0 = 0.0f, x1 = 1.0f, y1 = 1.0f, z1 = 1.0f; if (Facing::STEP_X[facing] > 0) x1 += grow; else if (Facing::STEP_X[facing] < 0) x0 -= grow; if (Facing::STEP_Y[facing] > 0) y1 += grow; else if (Facing::STEP_Y[facing] < 0) y0 -= grow; if (Facing::STEP_Z[facing] > 0) z1 += grow; else if (Facing::STEP_Z[facing] < 0) z0 -= grow; setShape(x0, y0, z0, x1, y1, z1); } AABB *ShulkerBoxTile::getAABB(Level *level, int x, int y, int z) { updateShape(level, x, y, z); return BaseEntityTile::getAABB(level, x, y, z); } AABB *ShulkerBoxTile::getTileAABB(Level *level, int x, int y, int z) { updateShape(level, x, y, z); return BaseEntityTile::getTileAABB(level, x, y, z); } int ShulkerBoxTile::getDyeColor() { return color; } int ShulkerBoxTile::getBoxRGB() { return SHULKER_BOX_TILE_RGB[color & 15]; } int ShulkerBoxTile::getColor(int auxData) { return getBoxRGB(); } int ShulkerBoxTile::getColor(LevelSource *level, int x, int y, int z) { return getBoxRGB(); } int ShulkerBoxTile::getColor(LevelSource *level, int x, int y, int z, int data) { return getBoxRGB(); } bool ShulkerBoxTile::isSolidRender(bool isServerLevel) { return false; } bool ShulkerBoxTile::isCubeShaped() { return false; } int ShulkerBoxTile::getRenderShape() { return Tile::SHAPE_ENTITYTILE_ANIMATED; } shared_ptr ShulkerBoxTile::newTileEntity(Level *level) { return std::make_shared(color); } bool ShulkerBoxTile::TestUse() { return true; } bool ShulkerBoxTile::use(Level *level, int x, int y, int z, shared_ptr player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly) { if (soundOnly) return true; if (level->isClientSide) return true; if (player->isSpectator()) return true; shared_ptr box = dynamic_pointer_cast(level->getTileEntity(x, y, z)); if (box == nullptr) return false; bool canOpen = true; if (box->getAnimationStatus() == ShulkerBoxTileEntity::ANIMATION_CLOSED) { int facing = level->getData(x, y, z) % 6; int sx = Facing::STEP_X[facing]; int sy = Facing::STEP_Y[facing]; int sz = Facing::STEP_Z[facing]; double nx = x + sx; double ny = y + sy; double nz = z + sz; double x0 = nx, y0 = ny, z0 = nz, x1 = nx + 1, y1 = ny + 1, z1 = nz + 1; if (sx > 0) x1 = nx + 0.5; else if (sx < 0) x0 = nx + 0.5; if (sy > 0) y1 = ny + 0.5; else if (sy < 0) y0 = ny + 0.5; if (sz > 0) z1 = nz + 0.5; else if (sz < 0) z0 = nz + 0.5; AABBList *cubes = level->getCubes(nullptr, AABB::newTemp(x0 + 0.001, y0 + 0.001, z0 + 0.001, x1 - 0.001, y1 - 0.001, z1 - 0.001), true); canOpen = cubes == nullptr || cubes->empty(); if (canOpen) { vector > *onTop = level->getEntitiesOfClass(typeid(LivingEntity), AABB::newTemp(x0, y0, z0, x1, y1, z1)); if (onTop != nullptr) { canOpen = onTop->empty(); delete onTop; } } } if (canOpen) { player->openContainer(box); } return true; } int ShulkerBoxTile::getPlacedOnFaceDataValue(Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, int itemValue) { return face; } void ShulkerBoxTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr by, shared_ptr itemInstance) { shared_ptr box = dynamic_pointer_cast(level->getTileEntity(x, y, z)); if (box == nullptr || itemInstance == nullptr) return; if (itemInstance->hasTag()) { CompoundTag *tag = itemInstance->getTag(); if (tag->contains(L"BlockEntityTag")) { box->loadContents(tag->getCompound(L"BlockEntityTag")); } } if (itemInstance->hasCustomHoverName()) { box->setCustomName(itemInstance->getHoverName()); } box->setChanged(); } void ShulkerBoxTile::playerWillDestroy(Level *level, int x, int y, int z, int data, shared_ptr player) { shared_ptr box = dynamic_pointer_cast(level->getTileEntity(x, y, z)); if (box != nullptr) { box->setDestroyedByCreativePlayer(player->abilities.instabuild); } BaseEntityTile::playerWillDestroy(level, x, y, z, data, player); } void ShulkerBoxTile::onRemove(Level *level, int x, int y, int z, int id, int data) { shared_ptr box = dynamic_pointer_cast(level->getTileEntity(x, y, z)); if (box != nullptr && !level->isClientSide) { if (!box->isCleared() && box->shouldDrop()) { shared_ptr item = std::make_shared(this->id, 1, 0); if (!box->isEmpty()) { CompoundTag *entityTag = new CompoundTag(); box->saveContents(entityTag); entityTag->remove(L"CustomName"); CompoundTag *rootTag = new CompoundTag(); rootTag->putCompound(L"BlockEntityTag", entityTag); item->setTag(rootTag); } if (box->hasCustomName()) { item->setHoverName(box->getCustomName()); } popResource(level, x, y, z, item); } box->clearContent(); level->updateNeighbourForOutputSignal(x, y, z, id); } BaseEntityTile::onRemove(level, x, y, z, id, data); } int ShulkerBoxTile::getResourceCount(Random *random) { return 0; } int ShulkerBoxTile::getPistonPushReaction() { return Material::PUSH_DESTROY; } bool ShulkerBoxTile::hasAnalogOutputSignal() { return true; } int ShulkerBoxTile::getAnalogOutputSignal(Level *level, int x, int y, int z, int dir) { return AbstractContainerMenu::getRedstoneSignalFromContainer(dynamic_pointer_cast(level->getTileEntity(x, y, z))); } int ShulkerBoxTile::cloneTileData(Level *level, int x, int y, int z) { return 0; } void ShulkerBoxTile::registerIcons(IconRegister *iconRegister) { icon = iconRegister->registerIcon(L"shulker_top"); }