mirror of
https://github.com/neoStudiosLCE/neoLegacy.git
synced 2026-05-21 22:55:04 +00:00
fix: beacon menu item consumption, data sync, and button state issues
- Prevent payment item from being consumed when submitting unchanged powers - Reorder ServerPlayer::openBeacon to send ContainerOpenPacket before addSlotListener so beacon data packets arrive after the client menu is ready - Add BeaconMenu::broadcastChanges() to continuously sync levels and powers to clients, matching the pattern FurnaceMenu already uses - Initialize UIControl_BeaconEffectButton::m_lastState to prevent stale heap memory from suppressing Iggy ChangeState calls on menu re-entry
This commit is contained in:
@@ -9,6 +9,7 @@ UIControl_BeaconEffectButton::UIControl_BeaconEffectButton()
|
||||
m_selected = false;
|
||||
m_active = false;
|
||||
m_focus = false;
|
||||
m_lastState = eState_Disabled;
|
||||
}
|
||||
|
||||
bool UIControl_BeaconEffectButton::setupControl(UIScene *scene, IggyValuePath *parent, const string &controlName)
|
||||
|
||||
@@ -2132,12 +2132,21 @@ void PlayerConnection::handleCustomPayload(shared_ptr<CustomPayloadPacket> custo
|
||||
|
||||
BeaconMenu *beaconMenu = static_cast<BeaconMenu *>(player->containerMenu);
|
||||
Slot *slot = beaconMenu->getSlot(0);
|
||||
if (slot->hasItem())
|
||||
if (slot != nullptr && slot->hasItem())
|
||||
{
|
||||
slot->remove(1);
|
||||
shared_ptr<BeaconTileEntity> beacon = beaconMenu->getBeacon();
|
||||
int prevPrimary = beacon->getPrimaryPower();
|
||||
int prevSecondary = beacon->getSecondaryPower();
|
||||
|
||||
beacon->setPrimaryPower(primary);
|
||||
beacon->setSecondaryPower(secondary);
|
||||
|
||||
// Only consume the payment item if the powers actually changed
|
||||
if (beacon->getPrimaryPower() != prevPrimary || beacon->getSecondaryPower() != prevSecondary)
|
||||
{
|
||||
slot->remove(1);
|
||||
}
|
||||
|
||||
beacon->setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1431,7 +1431,6 @@ bool ServerPlayer::openBeacon(shared_ptr<BeaconTileEntity> beacon)
|
||||
nextContainerCounter();
|
||||
containerMenu = new BeaconMenu(inventory, beacon);
|
||||
containerMenu->containerId = containerCounter;
|
||||
containerMenu->addSlotListener(this);
|
||||
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
|
||||
if (FourKitBridge::FireInventoryOpen(entityId, ContainerOpenPacket::BEACON, beacon->getCustomName(), beacon->getContainerSize()))
|
||||
{
|
||||
@@ -1439,7 +1438,10 @@ bool ServerPlayer::openBeacon(shared_ptr<BeaconTileEntity> beacon)
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
// Send the open packet BEFORE addSlotListener so the client has the
|
||||
// menu ready when the beacon data (levels, powers) arrives.
|
||||
connection->send(std::make_shared<ContainerOpenPacket>(containerCounter, ContainerOpenPacket::BEACON, beacon->getCustomName(), beacon->getContainerSize(), beacon->hasCustomName()));
|
||||
containerMenu->addSlotListener(this);
|
||||
refreshContainer(containerMenu);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -39,6 +39,29 @@ void BeaconMenu::addSlotListener(ContainerListener *listener)
|
||||
listener->setContainerData(this, 2, secondaryPower);
|
||||
}
|
||||
|
||||
void BeaconMenu::broadcastChanges()
|
||||
{
|
||||
AbstractContainerMenu::broadcastChanges();
|
||||
|
||||
int currentLevels = beacon->getLevels();
|
||||
int currentPrimary = beacon->getPrimaryPower();
|
||||
int currentSecondary = beacon->getSecondaryPower();
|
||||
|
||||
for (auto& listener : containerListeners)
|
||||
{
|
||||
if (levels != currentLevels)
|
||||
listener->setContainerData(this, 0, currentLevels);
|
||||
if (primaryPower != currentPrimary)
|
||||
listener->setContainerData(this, 1, currentPrimary);
|
||||
if (secondaryPower != currentSecondary)
|
||||
listener->setContainerData(this, 2, currentSecondary);
|
||||
}
|
||||
|
||||
levels = currentLevels;
|
||||
primaryPower = currentPrimary;
|
||||
secondaryPower = currentSecondary;
|
||||
}
|
||||
|
||||
void BeaconMenu::setData(int id, int value)
|
||||
{
|
||||
if (id == 0) beacon->setLevels(value);
|
||||
|
||||
@@ -36,7 +36,8 @@ private:
|
||||
public:
|
||||
BeaconMenu(shared_ptr<Container> inventory, shared_ptr<BeaconTileEntity> beacon);
|
||||
|
||||
void addSlotListener(ContainerListener *listener);
|
||||
void addSlotListener(ContainerListener *listener) override;
|
||||
void broadcastChanges() override;
|
||||
void setData(int id, int value);
|
||||
shared_ptr<BeaconTileEntity> getBeacon();
|
||||
bool stillValid(shared_ptr<Player> player);
|
||||
|
||||
Reference in New Issue
Block a user