finish rewrite; port to cmake, loads of other changes

Theres documentation at https://sylvessa.zip/fourkit/ now. And a bunch of other changes. Check the discord server for a more comprehensive list
This commit is contained in:
sylvessa 2026-03-21 13:52:26 -05:00
parent ecb3f00bd6
commit f5f9aa1cf5
107 changed files with 14289 additions and 40 deletions

View file

@ -4,6 +4,10 @@
#include "net.minecraft.world.level.redstone.h"
#include "Slot.h"
#include "AbstractContainerMenu.h"
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
#include "Mth.h"
#include "../Minecraft.Server/FourKitBridge.h"
#endif
// 4J Stu - The java does not have ctor here (being an abstract) but we need one to initialise the member variables
// TODO Make sure all derived classes also call this
@ -248,13 +252,64 @@ shared_ptr<ItemInstance> AbstractContainerMenu::clicked(int slotIndex, int butto
{
if (buttonNum == 0)
{
player->drop(inventory->getCarried());
inventory->setCarried(nullptr);
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
{
auto carried = inventory->getCarried();
bool dropAllowed = true;
if (carried != nullptr && carried->count > 0)
{
int outId = carried->id, outCount = carried->count, outAux = carried->getAuxValue();
if (FourKitBridge::FirePlayerDropItem(
player->entityId, carried->id, carried->count, carried->getAuxValue(),
&outId, &outCount, &outAux))
dropAllowed = false;
else
{
player->drop(std::make_shared<ItemInstance>(outId, outCount, outAux));
inventory->setCarried(nullptr);
dropAllowed = false;
}
}
if (dropAllowed)
{
#endif
player->drop(inventory->getCarried());
inventory->setCarried(nullptr);
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
}
}
#endif
}
if (buttonNum == 1)
{
player->drop(inventory->getCarried()->remove(1));
if (inventory->getCarried()->count == 0) inventory->setCarried(nullptr);
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
{
auto carried = inventory->getCarried();
bool dropAllowed = true;
if (carried != nullptr && carried->count > 0)
{
int outId = carried->id, outCount = 1, outAux = carried->getAuxValue();
if (FourKitBridge::FirePlayerDropItem(
player->entityId, carried->id, 1, carried->getAuxValue(),
&outId, &outCount, &outAux))
dropAllowed = false;
else
{
carried->remove(1);
if (carried->count == 0) inventory->setCarried(nullptr);
player->drop(std::make_shared<ItemInstance>(outId, outCount, outAux));
dropAllowed = false;
}
}
if (dropAllowed)
{
#endif
player->drop(inventory->getCarried()->remove(1));
if (inventory->getCarried()->count == 0) inventory->setCarried(nullptr);
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
}
}
#endif
}
}
@ -476,7 +531,32 @@ shared_ptr<ItemInstance> AbstractContainerMenu::clicked(int slotIndex, int butto
Slot *slot = slots.at(slotIndex);
if (slot != nullptr && slot->hasItem() && slot->mayPickup(player))
{
shared_ptr<ItemInstance> item = slot->remove(buttonNum == 0 ? 1 : slot->getItem()->count);
int dropCount = buttonNum == 0 ? 1 : slot->getItem()->count;
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
// fix for issue reported by aiden
{
auto slotItem = slot->getItem();
bool dropAllowed = true;
if (slotItem != nullptr && slotItem->count > 0)
{
int outId = slotItem->id, outCount = dropCount, outAux = slotItem->getAuxValue();
if (FourKitBridge::FirePlayerDropItem(
player->entityId, slotItem->id, dropCount, slotItem->getAuxValue(),
&outId, &outCount, &outAux))
dropAllowed = false;
else
{
shared_ptr<ItemInstance> item = slot->remove(dropCount);
slot->onTake(player, item);
player->drop(std::make_shared<ItemInstance>(outId, outCount, outAux));
dropAllowed = false;
}
}
if (!dropAllowed)
return nullptr;
}
#endif
shared_ptr<ItemInstance> item = slot->remove(dropCount);
slot->onTake(player, item);
player->drop(item);
}