mirror of
https://git.neolegacy.dev/neoStudiosLCE/neoLegacy.git
synced 2026-11-26 21:26:38 +01:00
Patch Notes: Blocks + Colored shulker boxes + Concrete powder + Concrete + Glazed terracotta Items + Shulker shell + Iron nugget UI Changes + Added Custom Controls to Keyboard & Mouse, as well as Controller + Added Custom SuperFlat + Added Edit Server Menu + Added Firework Crafting Feature Changes + Host Options + Added Pick Block + Added off-hand slot for maps and arrows. Bug Fixes & changes + TU47: Banner hitbox wrong (and inventory model fixed) + TU47/48: Ice not melting properly + TU48: Dead bushes not dropping sticks + TU48: Guardians and polar bears not dropping cooked fish when on fire + TU48: Bonus chest missing saplings and seeds + TU48: Frosted ice obtainable + TU48: Hoppers not collecting items + TU48: Wither skeletons spawning in 2-high gaps + TU48: End crystals exploding with “TNT Explodes” off + TU48: Tamed ocelots staying hostile + TU48: Signs not placing on tall grass + TU51: Skeleton hitbox wrong + TU53: Fall damage in shallow water + TU53: Squids not spawning in man-made pools + Elytra has been improved to be more accurate to the source material + Removed Spectral Arrow from crafting + Fixed several broken item descriptions + You can no longer cook Pufferfish or Clownfish + Fixed scaling issue with paperdoll and chat + Iron and gold armor can now be smelted into nuggets. + More items can now be used as fuel in a furnace. + Using a firework rocket while gliding with elytra will now give the player a boost. + Changed the color of dyes, wool, carpets, and banners. + Reordered all colored blocks and items in the Creative inventory. Banners now have the same order of colors as all other colored blocks and items. + Fishing rods can now hook on entities without causing knockback or pseudo-damage. + Fixed banner crafting + Fixed Map colors for certain blocks + Fixed Path block height + Fixed String block issues + Fixed Item frame culling. + Fixed Tutorial world NBT/Block State issues + Fixed World Slider + Fixed Enderman AI + Fixed Player animation bug + HUD Flash text changes + Generation accuracy changes + Many other small accuracy changes and fixes
382 lines
9.1 KiB
C++
382 lines
9.1 KiB
C++
#include "stdafx.h"
|
|
#include "com.mojang.nbt.h"
|
|
#include "net.minecraft.world.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.entity.player.h"
|
|
#include "net.minecraft.world.item.h"
|
|
#include "net.minecraft.world.level.tile.h"
|
|
#include "ShulkerBoxTileEntity.h"
|
|
#include "ContainerOpenPacket.h"
|
|
#include "SoundTypes.h"
|
|
#include "Facing.h"
|
|
#include "net.minecraft.world.entity.h"
|
|
#include "net.minecraft.world.phys.h"
|
|
|
|
const float ShulkerBoxTileEntity::LID_HEIGHT_FACTOR = 0.5f;
|
|
const float ShulkerBoxTileEntity::LID_ROTATION_DEGREES = 270.0f;
|
|
|
|
ShulkerBoxTileEntity::ShulkerBoxTileEntity(int color) : TileEntity()
|
|
{
|
|
items = new ItemInstanceArray(CONTAINER_SIZE);
|
|
name = L"";
|
|
this->color = color;
|
|
openCount = 0;
|
|
animationStatus = ANIMATION_CLOSED;
|
|
progress = 0.0f;
|
|
progressOld = 0.0f;
|
|
cleared = false;
|
|
destroyedByCreativePlayer = false;
|
|
}
|
|
|
|
ShulkerBoxTileEntity::~ShulkerBoxTileEntity()
|
|
{
|
|
delete[] items->data;
|
|
delete items;
|
|
}
|
|
|
|
int ShulkerBoxTileEntity::getColor()
|
|
{
|
|
if (color < 0 && hasLevel())
|
|
{
|
|
Tile *tile = getTile();
|
|
if (tile != nullptr && tile->id >= Tile::white_shulker_box_Id && tile->id <= Tile::black_shulker_box_Id)
|
|
{
|
|
color = tile->id - Tile::white_shulker_box_Id;
|
|
}
|
|
}
|
|
return color < 0 ? 10 : color;
|
|
}
|
|
|
|
int ShulkerBoxTileEntity::getAnimationStatus()
|
|
{
|
|
return animationStatus;
|
|
}
|
|
|
|
float ShulkerBoxTileEntity::getProgress(float a)
|
|
{
|
|
return progressOld + (progress - progressOld) * a;
|
|
}
|
|
|
|
bool ShulkerBoxTileEntity::isEmpty()
|
|
{
|
|
for (unsigned int i = 0; i < items->length; i++)
|
|
{
|
|
if (items->data[i] != nullptr) return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool ShulkerBoxTileEntity::isCleared()
|
|
{
|
|
return cleared;
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::setDestroyedByCreativePlayer(bool value)
|
|
{
|
|
destroyedByCreativePlayer = value;
|
|
}
|
|
|
|
bool ShulkerBoxTileEntity::shouldDrop()
|
|
{
|
|
return !destroyedByCreativePlayer || !isEmpty() || hasCustomName();
|
|
}
|
|
|
|
bool ShulkerBoxTileEntity::isShulkerBoxItem(shared_ptr<ItemInstance> item)
|
|
{
|
|
return item != nullptr && item->id >= Tile::white_shulker_box_Id && item->id <= Tile::black_shulker_box_Id;
|
|
}
|
|
|
|
int ShulkerBoxTileEntity::getContainerType()
|
|
{
|
|
return ContainerOpenPacket::SHULKER_BOX;
|
|
}
|
|
|
|
unsigned int ShulkerBoxTileEntity::getContainerSize()
|
|
{
|
|
return CONTAINER_SIZE;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> ShulkerBoxTileEntity::getItem(unsigned int slot)
|
|
{
|
|
return items->data[slot];
|
|
}
|
|
|
|
shared_ptr<ItemInstance> ShulkerBoxTileEntity::removeItem(unsigned int slot, int count)
|
|
{
|
|
if (items->data[slot] != nullptr)
|
|
{
|
|
if (items->data[slot]->count <= count)
|
|
{
|
|
shared_ptr<ItemInstance> item = items->data[slot];
|
|
items->data[slot] = nullptr;
|
|
setChanged();
|
|
if (item->count <= 0) return nullptr;
|
|
return item;
|
|
}
|
|
shared_ptr<ItemInstance> i = items->data[slot]->remove(count);
|
|
if (items->data[slot]->count == 0) items->data[slot] = nullptr;
|
|
setChanged();
|
|
if (i->count <= 0) return nullptr;
|
|
return i;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> ShulkerBoxTileEntity::removeItemNoUpdate(int slot)
|
|
{
|
|
if (items->data[slot] != nullptr)
|
|
{
|
|
shared_ptr<ItemInstance> item = items->data[slot];
|
|
items->data[slot] = nullptr;
|
|
return item;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::setItem(unsigned int slot, shared_ptr<ItemInstance> item)
|
|
{
|
|
items->data[slot] = item;
|
|
if (item != nullptr && item->count > getMaxStackSize()) item->count = getMaxStackSize();
|
|
setChanged();
|
|
}
|
|
|
|
wstring ShulkerBoxTileEntity::getName()
|
|
{
|
|
return hasCustomName() ? name : app.GetString(IDS_TILE_SHULKER_BOX);
|
|
}
|
|
|
|
wstring ShulkerBoxTileEntity::getCustomName()
|
|
{
|
|
return hasCustomName() ? name : L"";
|
|
}
|
|
|
|
bool ShulkerBoxTileEntity::hasCustomName()
|
|
{
|
|
return !name.empty();
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::setCustomName(const wstring &name)
|
|
{
|
|
this->name = name;
|
|
}
|
|
|
|
int ShulkerBoxTileEntity::getMaxStackSize() const
|
|
{
|
|
return Container::LARGE_MAX_STACK_SIZE;
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::setChanged()
|
|
{
|
|
TileEntity::setChanged();
|
|
}
|
|
|
|
bool ShulkerBoxTileEntity::stillValid(shared_ptr<Player> player)
|
|
{
|
|
if (level == nullptr) return true;
|
|
if (level->getTileEntity(x, y, z) != shared_from_this()) return false;
|
|
if (player->distanceToSqr(x + 0.5, y + 0.5, z + 0.5) > 8 * 8) return false;
|
|
return true;
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::startOpen()
|
|
{
|
|
if (level == nullptr || getTile() == nullptr) return;
|
|
if (openCount < 0) openCount = 0;
|
|
openCount++;
|
|
level->tileEvent(x, y, z, getTile()->id, EVENT_SET_OPEN_COUNT, openCount);
|
|
if (openCount == 1)
|
|
{
|
|
level->playSound(x + 0.5, y + 0.5, z + 0.5, eSoundType_BLOCK_SHULKER_BOX_OPEN, 0.5f, level->random->nextFloat() * 0.1f + 0.9f);
|
|
}
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::stopOpen()
|
|
{
|
|
if (level == nullptr || getTile() == nullptr) return;
|
|
openCount--;
|
|
level->tileEvent(x, y, z, getTile()->id, EVENT_SET_OPEN_COUNT, openCount);
|
|
if (openCount <= 0)
|
|
{
|
|
level->playSound(x + 0.5, y + 0.5, z + 0.5, eSoundType_BLOCK_SHULKER_BOX_CLOSE, 0.5f, level->random->nextFloat() * 0.1f + 0.9f);
|
|
}
|
|
}
|
|
|
|
bool ShulkerBoxTileEntity::canPlaceItem(int slot, shared_ptr<ItemInstance> item)
|
|
{
|
|
return !isShulkerBoxItem(item);
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::clearContent()
|
|
{
|
|
cleared = true;
|
|
for (unsigned int i = 0; i < items->length; i++)
|
|
{
|
|
items->data[i] = nullptr;
|
|
}
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::saveContents(CompoundTag *base)
|
|
{
|
|
ListTag<CompoundTag> *listTag = new ListTag<CompoundTag>;
|
|
for (unsigned int i = 0; i < items->length; i++)
|
|
{
|
|
if (items->data[i] != nullptr)
|
|
{
|
|
CompoundTag *tag = new CompoundTag();
|
|
tag->putByte(L"Slot", static_cast<byte>(i));
|
|
items->data[i]->save(tag);
|
|
listTag->add(tag);
|
|
}
|
|
}
|
|
base->put(L"Items", listTag);
|
|
if (hasCustomName()) base->putString(L"CustomName", name);
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::loadContents(CompoundTag *base)
|
|
{
|
|
for (unsigned int i = 0; i < items->length; i++)
|
|
{
|
|
items->data[i] = nullptr;
|
|
}
|
|
if (base->contains(L"Items"))
|
|
{
|
|
ListTag<CompoundTag> *inventoryList = (ListTag<CompoundTag> *) base->getList(L"Items");
|
|
for (int i = 0; i < inventoryList->size(); i++)
|
|
{
|
|
CompoundTag *tag = inventoryList->get(i);
|
|
unsigned int slot = tag->getByte(L"Slot") & 0xff;
|
|
if (slot < items->length)
|
|
{
|
|
(*items)[slot] = ItemInstance::fromTag(tag);
|
|
}
|
|
}
|
|
}
|
|
if (base->contains(L"CustomName")) name = base->getString(L"CustomName");
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::load(CompoundTag *base)
|
|
{
|
|
TileEntity::load(base);
|
|
loadContents(base);
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::save(CompoundTag *base)
|
|
{
|
|
TileEntity::save(base);
|
|
saveContents(base);
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::updateAnimation()
|
|
{
|
|
progressOld = progress;
|
|
switch (animationStatus)
|
|
{
|
|
case ANIMATION_CLOSED:
|
|
progress = 0.0f;
|
|
break;
|
|
case ANIMATION_OPENING:
|
|
progress += 0.1f;
|
|
if (progress >= 1.0f)
|
|
{
|
|
moveCollidedEntities();
|
|
animationStatus = ANIMATION_OPENED;
|
|
progress = 1.0f;
|
|
}
|
|
break;
|
|
case ANIMATION_CLOSING:
|
|
progress -= 0.1f;
|
|
if (progress <= 0.0f)
|
|
{
|
|
animationStatus = ANIMATION_CLOSED;
|
|
progress = 0.0f;
|
|
}
|
|
break;
|
|
case ANIMATION_OPENED:
|
|
progress = 1.0f;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::tick()
|
|
{
|
|
updateAnimation();
|
|
if (animationStatus == ANIMATION_OPENING || animationStatus == ANIMATION_CLOSING)
|
|
moveCollidedEntities();
|
|
}
|
|
|
|
void ShulkerBoxTileEntity::moveCollidedEntities()
|
|
{
|
|
if (level == nullptr)
|
|
return;
|
|
Tile *tile = Tile::tiles[level->getTile(x, y, z)];
|
|
if (dynamic_cast<ShulkerBoxTile *>(tile) == nullptr)
|
|
return;
|
|
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];
|
|
float grow = 0.5f * getProgress(1.0f);
|
|
|
|
double x0 = x, y0 = y, z0 = z, x1 = x + 1.0, y1 = y + 1.0, z1 = z + 1.0;
|
|
if (sx > 0) { x0 = x + 1.0; x1 = x + 1.0 + grow; }
|
|
else if (sx < 0) { x1 = x; x0 = x - grow; }
|
|
if (sy > 0) { y0 = y + 1.0; y1 = y + 1.0 + grow; }
|
|
else if (sy < 0) { y1 = y; y0 = y - grow; }
|
|
if (sz > 0) { z0 = z + 1.0; z1 = z + 1.0 + grow; }
|
|
else if (sz < 0) { z1 = z; z0 = z - grow; }
|
|
if (x1 - x0 <= 0.0 || y1 - y0 <= 0.0 || z1 - z0 <= 0.0)
|
|
return;
|
|
|
|
AABB *box = AABB::newTemp(x0, y0, z0, x1, y1, z1);
|
|
vector<shared_ptr<Entity> > *entities = level->getEntities(nullptr, box);
|
|
if (entities == nullptr)
|
|
return;
|
|
for (size_t i = 0; i < entities->size(); ++i)
|
|
{
|
|
shared_ptr<Entity> entity = entities->at(i);
|
|
if (entity == nullptr || entity->bb == nullptr)
|
|
continue;
|
|
double dx = 0.0, dy = 0.0, dz = 0.0;
|
|
if (sx > 0) dx = box->x1 - entity->bb->x0 + 0.01;
|
|
else if (sx < 0) dx = -(entity->bb->x1 - box->x0 + 0.01);
|
|
if (sy > 0) dy = box->y1 - entity->bb->y0 + 0.01;
|
|
else if (sy < 0) dy = -(entity->bb->y1 - box->y0 + 0.01);
|
|
if (sz > 0) dz = box->z1 - entity->bb->z0 + 0.01;
|
|
else if (sz < 0) dz = -(entity->bb->z1 - box->z0 + 0.01);
|
|
entity->move(dx, dy, dz);
|
|
}
|
|
}
|
|
|
|
bool ShulkerBoxTileEntity::triggerEvent(int b0, int b1)
|
|
{
|
|
if (b0 == EVENT_SET_OPEN_COUNT)
|
|
{
|
|
openCount = b1;
|
|
if (b1 == 0)
|
|
{
|
|
animationStatus = ANIMATION_CLOSING;
|
|
}
|
|
else if (b1 == 1)
|
|
{
|
|
animationStatus = ANIMATION_OPENING;
|
|
}
|
|
return true;
|
|
}
|
|
return TileEntity::triggerEvent(b0, b1);
|
|
}
|
|
|
|
shared_ptr<TileEntity> ShulkerBoxTileEntity::clone()
|
|
{
|
|
shared_ptr<ShulkerBoxTileEntity> result = std::make_shared<ShulkerBoxTileEntity>(color);
|
|
TileEntity::clone(result);
|
|
for (unsigned int i = 0; i < items->length; i++)
|
|
{
|
|
if (items->data[i] != nullptr)
|
|
{
|
|
result->items->data[i] = ItemInstance::clone(items->data[i]);
|
|
}
|
|
}
|
|
result->name = name;
|
|
return result;
|
|
}
|