diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index e996c6fb..a485210b 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -3997,6 +3997,36 @@ void ClientConnection::handleCustomPayload(shared_ptr custo trader->overrideOffers(recipeList); } } + else if (CustomPayloadPacket::ENCHANTMENT_LIST_PACKET.compare(customPayloadPacket->identifier) == 0) { + ByteArrayInputStream bais(customPayloadPacket->data); + DataInputStream input(&bais); + bool done = false; + int l = 0; + bool firstInGroup = true; + EnchantmentEntry temp; + //int firstAmount = input.readInt(); + while (!done) { + int a = input.readInt(); + if (a == -1) { + minecraft->localplayers[m_userIndex]->enchantmentEntries[l] = temp; + l++; + firstInGroup = true; + } + else if (a == -2) { + done = true; + } + else { + if (firstInGroup) { + temp.id = a; + temp.level = input.readInt(); + firstInGroup = false; + } + else { + input.readInt(); + } + } + } + } } Connection *ClientConnection::getConnection() diff --git a/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu1080.swf b/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu1080.swf index c86b678b..fe5cee4d 100644 Binary files a/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu1080.swf and b/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu1080.swf differ diff --git a/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu480.swf b/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu480.swf index eeee87ad..fe5cee4d 100644 Binary files a/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu480.swf and b/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu480.swf differ diff --git a/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu720.swf b/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu720.swf index f309fec9..fe5cee4d 100644 Binary files a/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu720.swf and b/Minecraft.Client/Common/Media/MediaWindows64/EnchantingMenu720.swf differ diff --git a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp index 1b35b155..2084305e 100644 --- a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp +++ b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp @@ -14,7 +14,9 @@ #include "../../PlayerList.h" #include "../../Minecraft.h" #include "../../Options.h" - +#include "../../Minecraft.World/Level.h" +#include "../../MultiplayerLevel.h" +#include "../../../Minecraft.World/Enchantment.h" #ifdef __ORBIS__ #include #endif @@ -270,45 +272,45 @@ void IUIScene_AbstractContainerMenu::UpdateTooltips() } void IUIScene_AbstractContainerMenu::handleEnchantButton(int slot, int iPad) { - UIScene* t = ui.FindScene(eUIScene_EnchantingMenu); - MinecraftServer* aMinecraft = MinecraftServer::getInstance(); - EnchantmentMenu* menu = dynamic_cast(aMinecraft->getPlayers()->players[iPad]->containerMenu); + EnchantmentMenu* menu = new EnchantmentMenu(Minecraft::GetInstance()->player->inventory, dynamic_cast(Minecraft::GetInstance()->level), 0, 0, 0); + if (0 == 0) { //uhh don't worry that is temporary + int lapisCost = slot + 1; // slot 0 = 1 lapis, slot 1 = 2, slot 2 = 3 - if (menu->en == false && menu->cachedEnchantments[slot] != nullptr) { - EnchantmentInstance* a = menu->cachedEnchantments[slot]->at(0); - if (a != nullptr) { - int lapisCost = slot + 1; // slot 0 = 1 lapis, slot 1 = 2, slot 2 = 3 + Minecraft* pMinecraft = Minecraft::GetInstance(); + auto player = pMinecraft->player; + EnchantmentMenu* menu = dynamic_cast(player->containerMenu); + HtmlString title = HtmlString( + wstring(app.GetString(Enchantment::enchantments[player->enchantmentEntries[slot].id]->getDescriptionId())) + + L" " + + Enchantment::enchantments[player->enchantmentEntries[slot].id]->getLevelString(player->enchantmentEntries[slot].level) + + L"...?", + eHTMLColor_White + ); - HtmlString title = HtmlString( - wstring(app.GetString(a->enchantment->enchantments[a->enchantment->id]->getDescriptionId())) + - L" " + - a->enchantment->enchantments[a->enchantment->id]->getLevelString(a->level) + - L"...?", - eHTMLColor_White - ); + bool costEnough = Minecraft::GetInstance()->player->experienceLevel >= menu->costs[slot]; + bool enough = menu->getLapisCount() >= lapisCost; + eMinecraftColour col = enough ? eHTMLColor_7 : eHTMLColor_c; + eMinecraftColour colCost = costEnough ? eHTMLColor_7 : eHTMLColor_c; - bool costEnough = aMinecraft->getPlayers()->players[iPad]->experienceLevel >= menu->costs[slot]; - bool enough = menu->getLapisCount() >= lapisCost; - eMinecraftColour col = enough ? eHTMLColor_7 : eHTMLColor_c; - eMinecraftColour colCost = costEnough ? eHTMLColor_7 : eHTMLColor_c; + std::wstring message = costEnough + ? std::to_wstring(slot + 1) + (slot == 0 ? L" Enchantment Level" : L" Enchantment Levels") + : L"Level Requirement: " + std::to_wstring(menu->costs[slot]); - std::wstring message = costEnough - ? std::to_wstring(slot + 1) + (slot == 0 ? L" Enchantment Level" : L" Enchantment Levels") - : L"Level Requirement: " + std::to_wstring(menu->costs[slot]); + vector* lines = new vector(); + lines->push_back(title); - vector* lines = new vector(); - lines->push_back(title); - if (!aMinecraft->getPlayers()->players[iPad]->abilities.instabuild) { - lines->push_back(HtmlString(L"")); // title1 blank line - if (costEnough) { - lines->push_back(HtmlString(std::to_wstring(lapisCost) + L" Lapis Lazuli", col)); - } - lines->push_back(HtmlString(message, colCost)); + if (!Minecraft::GetInstance()->player->abilities.instabuild) { + lines->push_back(HtmlString(L"")); // title1 blank line + if (costEnough) { + lines->push_back(HtmlString(std::to_wstring(lapisCost) + L" Lapis Lazuli", col)); } - SetPointerText(lines, false); + lines->push_back(HtmlString(message, colCost)); } + + SetPointerText(lines, false); + return; } - }; +}; void IUIScene_AbstractContainerMenu::onMouseTick() { diff --git a/Minecraft.Client/Common/UI/IUIScene_EnchantingMenu.cpp b/Minecraft.Client/Common/UI/IUIScene_EnchantingMenu.cpp index 242fb83f..c36cdead 100644 --- a/Minecraft.Client/Common/UI/IUIScene_EnchantingMenu.cpp +++ b/Minecraft.Client/Common/UI/IUIScene_EnchantingMenu.cpp @@ -143,10 +143,9 @@ void IUIScene_EnchantingMenu::handleOtherClicked(int iPad, ESceneSection eSectio break; }; Minecraft *pMinecraft = Minecraft::GetInstance(); - MinecraftServer *aMinecraft = MinecraftServer::getInstance(); - if (index >= 0 && dynamic_cast(aMinecraft->getPlayers()->players[iPad]->containerMenu)->clickMenuButton(dynamic_pointer_cast(aMinecraft->getPlayers()->players[iPad]), index)) + if (index >= 0 && m_menu->clickMenuButton(dynamic_pointer_cast(pMinecraft->localplayers[iPad]), index)) { - pMinecraft->localgameModes[iPad]->handleInventoryButtonClick(dynamic_cast(aMinecraft->getPlayers()->players[iPad]->containerMenu)->containerId, index); + pMinecraft->localgameModes[iPad]->handleInventoryButtonClick(m_menu->containerId, index); } } diff --git a/Minecraft.World/ArmorItem.cpp b/Minecraft.World/ArmorItem.cpp index 51bf3def..d1f01208 100644 --- a/Minecraft.World/ArmorItem.cpp +++ b/Minecraft.World/ArmorItem.cpp @@ -130,33 +130,33 @@ ArmorItem::ArmorItem(int id, const ArmorMaterial *armorType, int icon, int slot) } shared_ptr ArmorItem::use(shared_ptr instance, Level* level, shared_ptr player) { - int slot = Mob::getEquipmentSlotForItem(instance) - 1; + //int slot = Mob::getEquipmentSlotForItem(instance) - 1; - // If player is in survival mode (not creative) - if (!player->abilities.instabuild) { // - // Equip the armor to the appropriate slot - ItemInstance copy = *instance->copy_not_shared(); - if (player->inventory->armor[slot] == nullptr) { - player->inventory->armor[slot] = make_shared(copy); - player->inventory->removeItemNoUpdate(player->inventory->selected); - // Remove the item from hand (set count to 0) - instance->count = 0; - } - else { - player->inventory->setItem(player->inventory->selected, player->inventory->armor[slot]); - player->inventory->armor[slot] = make_shared(copy); - } - } - else { - ItemInstance copy = *instance->copy_not_shared(); - if (player->inventory->armor[slot] == nullptr) { - player->inventory->armor[slot] = make_shared(copy); - } - else { - player->inventory->setItem(player->inventory->selected, player->inventory->armor[slot]); - player->inventory->armor[slot] = make_shared(copy); - } - } + //// If player is in survival mode (not creative) + //if (!player->abilities.instabuild) { // + // // Equip the armor to the appropriate slot + // ItemInstance copy = *instance->copy_not_shared(); + // if (player->inventory->armor[slot] == nullptr) { + // player->inventory->armor[slot] = make_shared(copy); + // player->inventory->removeItemNoUpdate(player->inventory->selected); + // // Remove the item from hand (set count to 0) + // instance->count = 0; + // } + // else { + // player->inventory->setItem(player->inventory->selected, player->inventory->armor[slot]); + // player->inventory->armor[slot] = make_shared(copy); + // } + //} + //else { + // ItemInstance copy = *instance->copy_not_shared(); + // if (player->inventory->armor[slot] == nullptr) { + // player->inventory->armor[slot] = make_shared(copy); + // } + // else { + // player->inventory->setItem(player->inventory->selected, player->inventory->armor[slot]); + // player->inventory->armor[slot] = make_shared(copy); + // } + //} int material = Item::items[instance->id]->getMaterial(); int lo, hi; diff --git a/Minecraft.World/CustomPayloadPacket.cpp b/Minecraft.World/CustomPayloadPacket.cpp index 208e272b..4c23f237 100644 --- a/Minecraft.World/CustomPayloadPacket.cpp +++ b/Minecraft.World/CustomPayloadPacket.cpp @@ -25,6 +25,11 @@ const wstring CustomPayloadPacket::IDENTITY_TOKEN_RESPONSE = L"MC|CTResponse"; const wstring CustomPayloadPacket::FORK_HELLO_CHANNEL = L"MC|ForkHello"; const wstring CustomPayloadPacket::FORK_PLAYER_LEAVE_CHANNEL = L"MC|ForkPLeave"; +const wstring CustomPayloadPacket::QUICK_EQUIP_PACKET = L"MC|QEquip"; +const wstring CustomPayloadPacket::QUICK_EQUIP_SERVER_PACKET = L"MC|QEquipServer"; + +const wstring CustomPayloadPacket::ENCHANTMENT_LIST_PACKET = L"MC|EnchList"; + CustomPayloadPacket::CustomPayloadPacket() : length(0) { diff --git a/Minecraft.World/CustomPayloadPacket.h b/Minecraft.World/CustomPayloadPacket.h index 7445bdf8..ae7163bf 100644 --- a/Minecraft.World/CustomPayloadPacket.h +++ b/Minecraft.World/CustomPayloadPacket.h @@ -31,6 +31,12 @@ public: static const wstring FORK_HELLO_CHANNEL; // server->client: identifies fork server (empty payload) static const wstring FORK_PLAYER_LEAVE_CHANNEL; // server->client: player disconnected (payload: UTF gamertag) + // Fixes for MP related crashes + static const wstring QUICK_EQUIP_PACKET; + static const wstring QUICK_EQUIP_SERVER_PACKET; + + static const wstring ENCHANTMENT_LIST_PACKET; + wstring identifier; int length; byteArray data; diff --git a/Minecraft.World/EnchantmentMenu.cpp b/Minecraft.World/EnchantmentMenu.cpp index ad5b230d..a1b12096 100644 --- a/Minecraft.World/EnchantmentMenu.cpp +++ b/Minecraft.World/EnchantmentMenu.cpp @@ -9,6 +9,10 @@ #include "../../../Minecraft.Client/ServerPlayer.h" #include "../../../Minecraft.Client/MinecraftServer.h" #include "../../../Minecraft.Client/PlayerList.h" +#include "../../../Minecraft.Client/MultiPlayerLocalPlayer.h" +#include "../../../Minecraft.Client/PlayerConnection.h" +#include "../../../Minecraft.World/CustomPayloadPacket.h" +#include "../../../Minecraft.Client/Minecraft.h" EnchantmentMenu::EnchantmentMenu(shared_ptr inventory, Level *level, int xt, int yt, int zt) { @@ -169,7 +173,28 @@ void EnchantmentMenu::slotsChanged(int a) // 4J used to take a shared_ptrenchantmentSeed); + int b = 0; + + for (int a = 0; a < 3; a++) { + vector* newEnchantment = cachedEnchantments[a]; + + for (int index = 0; index < newEnchantment->size(); index++) + { + EnchantmentInstance* e = newEnchantment->at(index); + dos.writeInt(e->enchantment->id); + dos.writeInt(e->level); + //delete e; + } + dos.writeInt(-1); + } + dos.writeInt(-2); + + //MinecraftServer::getInstance()->getPlayers()->players[0]->connection->send(std::make_shared(CustomPayloadPacket::ENCHANTMENT_LIST_PACKET, baos.toByteArray())); + PlayerList* playerList = MinecraftServer::getInstance()->getPlayers(); + playerList->broadcastAll(std::make_shared(CustomPayloadPacket::ENCHANTMENT_LIST_PACKET, baos.toByteArray())); } alreadyRan = true; @@ -228,7 +253,7 @@ bool EnchantmentMenu::clickMenuButton(shared_ptr player, int i) return false; } -EnchantmentInstance* EnchantmentMenu::predictEnchantment(shared_ptr player, int i) +EnchantmentInstance* EnchantmentMenu::predictEnchantment(Player* player, int i) { shared_ptr item = enchantSlots->getItem(0); if (costs[i] > 0 && item != nullptr && (player->experienceLevel >= costs[i] || player->abilities.instabuild)) diff --git a/Minecraft.World/EnchantmentMenu.h b/Minecraft.World/EnchantmentMenu.h index ee53608b..6b568b28 100644 --- a/Minecraft.World/EnchantmentMenu.h +++ b/Minecraft.World/EnchantmentMenu.h @@ -51,7 +51,7 @@ public: virtual void setData(int id, int value); virtual void slotsChanged(int a);// 4J used to take a shared_ptr container but wasn't using it, so removed to simplify things virtual bool clickMenuButton(shared_ptr player, int i); - virtual EnchantmentInstance* predictEnchantment(shared_ptr player, int i); + virtual EnchantmentInstance* predictEnchantment(Player* player, int i); void removed(shared_ptr player); virtual bool stillValid(shared_ptr player); virtual shared_ptr quickMoveStack(shared_ptr player, int slotIndex); diff --git a/Minecraft.World/Player.h b/Minecraft.World/Player.h index ea972481..97552f98 100644 --- a/Minecraft.World/Player.h +++ b/Minecraft.World/Player.h @@ -32,6 +32,11 @@ class Merchant; class PlayerEnderChestContainer; class GameType; class Scoreboard; +struct EnchantmentEntry { + int level; + int id; +}; + class Player : public LivingEntity, public CommandSender, public ScoreHolder { @@ -67,6 +72,7 @@ public: AbstractContainerMenu *inventoryMenu; AbstractContainerMenu *containerMenu; int enchantmentSeed = 0; + vector enchantmentEntries = vector(3); protected: FoodData foodData;