mirror of
https://github.com/neoStudiosLCE/neoLegacy.git
synced 2026-07-06 07:47:02 +00:00
Feat: Updated Enchanting Mechanics
Updated in the ARC: EnchantingMenu1080 SkinHDGraphicsInGame SkinHDInGame may have override other changes in the arc but it dont think so...
This commit is contained in:
parent
61b6e6adca
commit
490ac0eed1
Binary file not shown.
|
|
@ -5,9 +5,13 @@
|
|||
#include "UI.h"
|
||||
#include "../../../Minecraft.World/net.minecraft.world.inventory.h"
|
||||
#include "../../../Minecraft.World/net.minecraft.world.item.h"
|
||||
#include "../../../Minecraft.World/net.minecraft.world.item.enchantment.h"
|
||||
#include "../../../Minecraft.World/net.minecraft.world.item.crafting.h"
|
||||
#include "../../../Minecraft.World/net.minecraft.world.level.tile.entity.h"
|
||||
#include "../../MultiPlayerLocalPlayer.h"
|
||||
#include "../../ServerPlayer.h"
|
||||
#include "../../MinecraftServer.h"
|
||||
#include "../../PlayerList.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../Options.h"
|
||||
|
||||
|
|
@ -264,6 +268,47 @@ 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<EnchantmentMenu*>(aMinecraft->getPlayers()->players[iPad]->containerMenu);
|
||||
|
||||
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
|
||||
|
||||
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 = 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(menu->costs[slot]) + L" Enchantment Levels"
|
||||
: L"Level Requirement: " + std::to_wstring(menu->costs[slot]);
|
||||
|
||||
vector<HtmlString>* lines = new vector<HtmlString>();
|
||||
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));
|
||||
}
|
||||
SetPointerText(lines, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void IUIScene_AbstractContainerMenu::onMouseTick()
|
||||
{
|
||||
Minecraft *pMinecraft = Minecraft::GetInstance();
|
||||
|
|
@ -826,6 +871,9 @@ void IUIScene_AbstractContainerMenu::onMouseTick()
|
|||
SetPointerText(nullptr, false);
|
||||
m_lastPointerLabelSlot = nullptr;
|
||||
}
|
||||
if (eSectionUnderPointer == eSectionEnchantButton1) handleEnchantButton(0, iPad);
|
||||
else if (eSectionUnderPointer == eSectionEnchantButton2) handleEnchantButton(1, iPad);
|
||||
else if (eSectionUnderPointer == eSectionEnchantButton3) handleEnchantButton(2, iPad);
|
||||
|
||||
EToolTipItem buttonA, buttonX, buttonY, buttonRT, buttonBack;
|
||||
buttonA = buttonX = buttonY = buttonRT = buttonBack = eToolTipNone;
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ protected:
|
|||
eSectionEnchantUsing,
|
||||
eSectionEnchantInventory,
|
||||
eSectionEnchantSlot,
|
||||
eSectionLapisSlot,
|
||||
eSectionEnchantButton1,
|
||||
eSectionEnchantButton2,
|
||||
eSectionEnchantButton3,
|
||||
|
|
@ -216,6 +217,7 @@ protected:
|
|||
virtual void PlatformInitialize(int iPad, int startIndex) = 0;
|
||||
virtual void InitDataAssociations(int iPad, AbstractContainerMenu *menu, int startIndex = 0) = 0;
|
||||
|
||||
void handleEnchantButton(int slot, int iPad);
|
||||
void onMouseTick();
|
||||
bool handleKeyDown(int iPad, int iAction, bool bRepeat);
|
||||
virtual bool handleValidKeyPress(int iUserIndex, int buttonNum, BOOL quickKeyHeld);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@
|
|||
#include "../../../Minecraft.World/net.minecraft.world.inventory.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../MultiPlayerLocalPlayer.h"
|
||||
#include "../../PlayerList.h"
|
||||
#include "../../ServerPlayer.h"
|
||||
#include "IUIScene_EnchantingMenu.h"
|
||||
#include <MinecraftServer.h>
|
||||
|
||||
IUIScene_AbstractContainerMenu::ESceneSection IUIScene_EnchantingMenu::GetSectionAndSlotInDirection( IUIScene_AbstractContainerMenu::ESceneSection eSection, ETapState eTapDirection, int *piTargetX, int *piTargetY )
|
||||
{
|
||||
|
|
@ -140,9 +143,10 @@ void IUIScene_EnchantingMenu::handleOtherClicked(int iPad, ESceneSection eSectio
|
|||
break;
|
||||
};
|
||||
Minecraft *pMinecraft = Minecraft::GetInstance();
|
||||
if (index >= 0 && m_menu->clickMenuButton(dynamic_pointer_cast<Player>(pMinecraft->localplayers[iPad]), index))
|
||||
MinecraftServer *aMinecraft = MinecraftServer::getInstance();
|
||||
if (index >= 0 && dynamic_cast<EnchantmentMenu*>(aMinecraft->getPlayers()->players[iPad]->containerMenu)->clickMenuButton(dynamic_pointer_cast<Player>(aMinecraft->getPlayers()->players[iPad]), index))
|
||||
{
|
||||
pMinecraft->localgameModes[iPad]->handleInventoryButtonClick(m_menu->containerId, index);
|
||||
pMinecraft->localgameModes[iPad]->handleInventoryButtonClick(dynamic_cast<EnchantmentMenu*>(aMinecraft->getPlayers()->players[iPad]->containerMenu)->containerId, index);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -154,11 +158,14 @@ int IUIScene_EnchantingMenu::getSectionStartOffset(ESceneSection eSection)
|
|||
case eSectionEnchantSlot:
|
||||
offset = 0;
|
||||
break;
|
||||
case eSectionEnchantInventory:
|
||||
case eSectionLapisSlot:
|
||||
offset = 1;
|
||||
break;
|
||||
case eSectionEnchantInventory:
|
||||
offset = 2;
|
||||
break;
|
||||
case eSectionEnchantUsing:
|
||||
offset = 1 + 27;
|
||||
offset = 2 + 27;
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
|
|
@ -174,6 +181,7 @@ bool IUIScene_EnchantingMenu::IsSectionSlotList( ESceneSection eSection )
|
|||
case eSectionEnchantInventory:
|
||||
case eSectionEnchantUsing:
|
||||
case eSectionEnchantSlot:
|
||||
case eSectionLapisSlot:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ bool UIControl_EnchantmentButton::setupControl(UIScene *scene, IggyValuePath *pa
|
|||
|
||||
//Button specific initialisers
|
||||
m_funcChangeState = registerFastName(L"ChangeState");
|
||||
m_CLevel = registerFastName(L"m_iCurrentLevel");
|
||||
m_CLevelU = registerFastName(L"SetEnchantmentLevel");
|
||||
|
||||
return success;
|
||||
}
|
||||
|
|
@ -33,6 +35,18 @@ bool UIControl_EnchantmentButton::setupControl(UIScene *scene, IggyValuePath *pa
|
|||
void UIControl_EnchantmentButton::init(int index)
|
||||
{
|
||||
m_index = index;
|
||||
//IggyValueSetF64RS(getIggyValuePath(), m_CLevel, nullptr, index + 1);
|
||||
}
|
||||
|
||||
void UIControl_EnchantmentButton::setLevel()
|
||||
{
|
||||
IggyValueSetF64RS(getIggyValuePath(), m_CLevel, nullptr, m_index + 1);
|
||||
|
||||
IggyDataValue value[1];
|
||||
value[0].type = IGGY_DATATYPE_number;
|
||||
value[0].number = m_index + 1;
|
||||
IggyDataValue result;
|
||||
IggyResult out = IggyPlayerCallMethodRS(m_parentScene->getMovie(), &result, getIggyValuePath(), m_CLevelU, 1, value);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -176,6 +190,8 @@ void UIControl_EnchantmentButton::updateState()
|
|||
setLabel(L"");
|
||||
}
|
||||
|
||||
IggyValueSetF64RS(getIggyValuePath(), m_CLevel, nullptr, m_BValue);
|
||||
|
||||
if(state != m_lastState)
|
||||
{
|
||||
IggyDataValue result;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ private:
|
|||
bool m_bHasFocus;
|
||||
|
||||
IggyName m_funcChangeState;
|
||||
IggyName m_CLevel;
|
||||
IggyName m_CLevelU;
|
||||
|
||||
unsigned int m_textColour, m_textFocusColour, m_textDisabledColour;
|
||||
|
||||
|
|
@ -27,6 +29,7 @@ private:
|
|||
{
|
||||
public:
|
||||
static EnchantmentNames instance;
|
||||
|
||||
|
||||
private:
|
||||
Random random;
|
||||
|
|
@ -40,12 +43,13 @@ private:
|
|||
|
||||
public:
|
||||
UIControl_EnchantmentButton();
|
||||
|
||||
int m_BValue = 1;
|
||||
virtual bool setupControl(UIScene *scene, IggyValuePath *parent, const string &controlName);
|
||||
|
||||
virtual void tick();
|
||||
|
||||
void init(int index);
|
||||
void setLevel();
|
||||
virtual void ReInit();
|
||||
void render(IggyCustomDrawCallbackRegion *region);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,10 +10,18 @@ UIScene_EnchantingMenu::UIScene_EnchantingMenu(int iPad, void *_initData, UILaye
|
|||
// Setup all the Iggy references we need for this scene
|
||||
initialiseMovie();
|
||||
|
||||
m_enchantButton[0].m_BValue = 1.0f;
|
||||
m_enchantButton[1].m_BValue = 2.0f;
|
||||
m_enchantButton[2].m_BValue = 3.0f;
|
||||
|
||||
m_enchantButton[0].init(0);
|
||||
m_enchantButton[1].init(1);
|
||||
m_enchantButton[2].init(2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
EnchantingScreenInput *initData = static_cast<EnchantingScreenInput *>(_initData);
|
||||
|
||||
m_labelEnchant.init( initData->name.empty() ? app.GetString(IDS_ENCHANT) : initData->name );
|
||||
|
|
@ -26,15 +34,21 @@ UIScene_EnchantingMenu::UIScene_EnchantingMenu(int iPad, void *_initData, UILaye
|
|||
gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Enchanting_Menu, this);
|
||||
}
|
||||
|
||||
EnchantmentMenu *menu = new EnchantmentMenu(initData->inventory, initData->level, initData->x, initData->y, initData->z);
|
||||
menu = new EnchantmentMenu(initData->inventory, initData->level, initData->x, initData->y, initData->z);
|
||||
//menu->iPad = initData->iPad;
|
||||
|
||||
Initialize( initData->iPad, menu, true, EnchantmentMenu::INV_SLOT_START, eSectionEnchantUsing, eSectionEnchantMax );
|
||||
|
||||
m_slotListIngredient.addSlots(EnchantmentMenu::INGREDIENT_SLOT, 1);
|
||||
m_slotListLapis.addSlots(EnchantmentMenu::LAPIS_SLOT, 1);
|
||||
|
||||
app.SetRichPresenceContext(m_iPad,CONTEXT_GAME_STATE_ENCHANTING);
|
||||
|
||||
delete initData;
|
||||
|
||||
m_enchantButton[0].setLevel();
|
||||
m_enchantButton[1].setLevel();
|
||||
m_enchantButton[2].setLevel();
|
||||
}
|
||||
|
||||
wstring UIScene_EnchantingMenu::getMoviePath()
|
||||
|
|
@ -54,6 +68,7 @@ void UIScene_EnchantingMenu::handleReload()
|
|||
Initialize( m_iPad, m_menu, true, EnchantmentMenu::INV_SLOT_START, eSectionEnchantUsing, eSectionEnchantMax );
|
||||
|
||||
m_slotListIngredient.addSlots(EnchantmentMenu::INGREDIENT_SLOT, 1);
|
||||
m_slotListLapis.addSlots(EnchantmentMenu::LAPIS_SLOT, 1);
|
||||
}
|
||||
|
||||
int UIScene_EnchantingMenu::getSectionColumns(ESceneSection eSection)
|
||||
|
|
@ -64,6 +79,9 @@ int UIScene_EnchantingMenu::getSectionColumns(ESceneSection eSection)
|
|||
case eSectionEnchantSlot:
|
||||
cols = 1;
|
||||
break;
|
||||
case eSectionLapisSlot:
|
||||
cols = 1;
|
||||
break;
|
||||
case eSectionEnchantInventory:
|
||||
cols = 9;
|
||||
break;
|
||||
|
|
@ -85,6 +103,9 @@ int UIScene_EnchantingMenu::getSectionRows(ESceneSection eSection)
|
|||
case eSectionEnchantSlot:
|
||||
rows = 1;
|
||||
break;
|
||||
case eSectionLapisSlot:
|
||||
rows = 1;
|
||||
break;
|
||||
case eSectionEnchantInventory:
|
||||
rows = 3;
|
||||
break;
|
||||
|
|
@ -106,6 +127,10 @@ void UIScene_EnchantingMenu::GetPositionOfSection( ESceneSection eSection, UIVec
|
|||
pPosition->x = m_slotListIngredient.getXPos();
|
||||
pPosition->y = m_slotListIngredient.getYPos();
|
||||
break;
|
||||
case eSectionLapisSlot:
|
||||
pPosition->x = m_slotListLapis.getXPos();
|
||||
pPosition->y = m_slotListLapis.getYPos();
|
||||
break;
|
||||
case eSectionEnchantInventory:
|
||||
pPosition->x = m_slotListInventory.getXPos();
|
||||
pPosition->y = m_slotListInventory.getYPos();
|
||||
|
|
@ -141,6 +166,10 @@ void UIScene_EnchantingMenu::GetItemScreenData( ESceneSection eSection, int iIte
|
|||
sectionSize.x = m_slotListIngredient.getWidth();
|
||||
sectionSize.y = m_slotListIngredient.getHeight();
|
||||
break;
|
||||
case eSectionLapisSlot:
|
||||
sectionSize.x = m_slotListLapis.getWidth();
|
||||
sectionSize.y = m_slotListLapis.getHeight();
|
||||
break;
|
||||
case eSectionEnchantInventory:
|
||||
sectionSize.x = m_slotListInventory.getWidth();
|
||||
sectionSize.y = m_slotListInventory.getHeight();
|
||||
|
|
@ -200,6 +229,9 @@ void UIScene_EnchantingMenu::setSectionSelectedSlot(ESceneSection eSection, int
|
|||
case eSectionEnchantSlot:
|
||||
slotList = &m_slotListIngredient;
|
||||
break;
|
||||
case eSectionLapisSlot:
|
||||
slotList = &m_slotListLapis;
|
||||
break;
|
||||
case eSectionEnchantInventory:
|
||||
slotList = &m_slotListInventory;
|
||||
break;
|
||||
|
|
@ -222,6 +254,9 @@ UIControl *UIScene_EnchantingMenu::getSection(ESceneSection eSection)
|
|||
case eSectionEnchantSlot:
|
||||
control = &m_slotListIngredient;
|
||||
break;
|
||||
case eSectionLapisSlot:
|
||||
control = &m_slotListLapis;
|
||||
break;
|
||||
case eSectionEnchantInventory:
|
||||
control = &m_slotListInventory;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@ public:
|
|||
|
||||
virtual EUIScene getSceneType() { return eUIScene_EnchantingMenu;}
|
||||
|
||||
EnchantmentMenu* menu;
|
||||
|
||||
protected:
|
||||
UIControl_SlotList m_slotListIngredient;
|
||||
UIControl_SlotList m_slotListIngredient, m_slotListLapis;
|
||||
UIControl_Label m_labelEnchant;
|
||||
UIControl_EnchantmentButton m_enchantButton[3];
|
||||
UIControl_EnchantmentBook m_enchantBook;
|
||||
|
|
@ -29,6 +31,7 @@ protected:
|
|||
UI_BEGIN_MAP_ELEMENTS_AND_NAMES(UIScene_AbstractContainerMenu)
|
||||
UI_BEGIN_MAP_CHILD_ELEMENTS( m_controlMainPanel )
|
||||
UI_MAP_ELEMENT( m_slotListIngredient, "ingredient")
|
||||
UI_MAP_ELEMENT(m_slotListLapis, "lapis")
|
||||
UI_MAP_ELEMENT( m_enchantButton[0], "Button1")
|
||||
UI_MAP_ELEMENT( m_enchantButton[1], "Button2")
|
||||
UI_MAP_ELEMENT( m_enchantButton[2], "Button3")
|
||||
|
|
|
|||
|
|
@ -84,8 +84,9 @@ public:
|
|||
virtual int getDescriptionId();
|
||||
virtual HtmlString getFullname(int level);
|
||||
virtual bool canEnchant(shared_ptr<ItemInstance> item);
|
||||
|
||||
private:
|
||||
// 4J Added
|
||||
wstring getLevelString(int level);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
|
@ -2,19 +2,22 @@
|
|||
#include "net.minecraft.world.inventory.h"
|
||||
#include "EnchantmentContainer.h"
|
||||
|
||||
EnchantmentContainer::EnchantmentContainer(EnchantmentMenu *menu) : SimpleContainer(IDS_ENCHANT, L"", false, 1), m_menu( menu )
|
||||
|
||||
|
||||
EnchantmentContainer::EnchantmentContainer(EnchantmentMenu *menu, int size) : SimpleContainer(IDS_ENCHANT, L"", false, 2), m_menu( menu )
|
||||
{
|
||||
MAX_STACK_SIZE = size;
|
||||
}
|
||||
|
||||
int EnchantmentContainer::getMaxStackSize() const
|
||||
{
|
||||
return 1;
|
||||
return MAX_STACK_SIZE;
|
||||
}
|
||||
|
||||
void EnchantmentContainer::setChanged()
|
||||
{
|
||||
SimpleContainer::setChanged();
|
||||
m_menu->slotsChanged(); // Remove this param as it's not needed
|
||||
m_menu->slotsChanged(MAX_STACK_SIZE);
|
||||
}
|
||||
|
||||
bool EnchantmentContainer::canPlaceItem(int slot, shared_ptr<ItemInstance> item)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ class EnchantmentContainer : public SimpleContainer
|
|||
private:
|
||||
EnchantmentMenu *m_menu;
|
||||
public:
|
||||
EnchantmentContainer(EnchantmentMenu *menu);
|
||||
int MAX_STACK_SIZE;
|
||||
|
||||
EnchantmentContainer(EnchantmentMenu *menu, int size = 1);
|
||||
virtual int getMaxStackSize() const;
|
||||
virtual void setChanged();
|
||||
virtual bool canPlaceItem(int slot, shared_ptr<ItemInstance> item);
|
||||
|
|
|
|||
|
|
@ -6,11 +6,15 @@
|
|||
#include "net.minecraft.world.item.h"
|
||||
#include "net.minecraft.world.item.enchantment.h"
|
||||
#include "EnchantmentMenu.h"
|
||||
#include "../../../Minecraft.Client/ServerPlayer.h"
|
||||
#include "../../../Minecraft.Client/MinecraftServer.h"
|
||||
#include "../../../Minecraft.Client/PlayerList.h"
|
||||
|
||||
EnchantmentMenu::EnchantmentMenu(shared_ptr<Inventory> inventory, Level *level, int xt, int yt, int zt)
|
||||
{
|
||||
enchantSlots = std::make_shared<EnchantmentContainer>(this);
|
||||
|
||||
lapisSlot = std::make_shared<EnchantmentContainer>(this, 64);
|
||||
playerT = inventory->player;
|
||||
for(int i = 0; i < 3; ++i)
|
||||
{
|
||||
costs[i] = 0;
|
||||
|
|
@ -21,6 +25,7 @@ EnchantmentMenu::EnchantmentMenu(shared_ptr<Inventory> inventory, Level *level,
|
|||
y = yt;
|
||||
z = zt;
|
||||
addSlot(new EnchantmentSlot(enchantSlots, 0, 21 + 4, 43 + 4));
|
||||
addSlot(new EnchantmentSlot(lapisSlot, 1, 40 + 4, 43 + 4));
|
||||
|
||||
for (int y = 0; y < 3; y++)
|
||||
{
|
||||
|
|
@ -53,6 +58,9 @@ void EnchantmentMenu::broadcastChanges()
|
|||
// 4J Added m_costsChanged to stop continually sending update packets even when no changes have been made
|
||||
if(m_costsChanged)
|
||||
{
|
||||
/*if (EnchantmentMenu::lapisSlot->getItem(1) == nullptr) {
|
||||
return;
|
||||
}*/
|
||||
for (size_t i = 0; i < containerListeners.size(); i++)
|
||||
{
|
||||
ContainerListener *listener = containerListeners.at(i);
|
||||
|
|
@ -77,22 +85,31 @@ void EnchantmentMenu::setData(int id, int value)
|
|||
}
|
||||
}
|
||||
|
||||
void EnchantmentMenu::slotsChanged() // 4J used to take a shared_ptr<Container> container but wasn't using it, so removed to simplify things
|
||||
vector<EnchantmentInstance*> EnchantmentMenu::getEnchantment() {
|
||||
random.setSeed(playerT->enchantmentSeed);
|
||||
shared_ptr<ItemInstance> item = enchantSlots->getItem(0);
|
||||
return *EnchantmentHelper::selectEnchantment(&random, item, costs[2]);
|
||||
}
|
||||
|
||||
void EnchantmentMenu::slotsChanged(int a) // 4J used to take a shared_ptr<Container> container but wasn't using it, so removed to simplify things
|
||||
{
|
||||
shared_ptr<ItemInstance> item = enchantSlots->getItem(0);
|
||||
|
||||
shared_ptr<ItemInstance> lapis = lapisSlot->getItem(1);
|
||||
|
||||
if (item == nullptr || !item->isEnchantable())
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
tempCosts[i] = costs[i];
|
||||
costs[i] = 0;
|
||||
}
|
||||
m_costsChanged = true;
|
||||
alreadyRan = false;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
nameSeed = random.nextLong();
|
||||
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
// find book cases
|
||||
|
|
@ -139,15 +156,30 @@ void EnchantmentMenu::slotsChanged() // 4J used to take a shared_ptr<Container>
|
|||
}
|
||||
}
|
||||
}
|
||||
bookcasesC = bookcases;
|
||||
random.setSeed(playerT->enchantmentSeed);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
costs[i] = EnchantmentHelper::getEnchantmentCost(&random, i, bookcases, item);
|
||||
}
|
||||
if (!alreadyRan) {
|
||||
en = false;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
//delete cachedEnchantments[i]; // clean up old one first <- doing it elsewhere
|
||||
cachedEnchantments[i] = EnchantmentHelper::selectEnchantment(&random, item, costs[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
alreadyRan = true;
|
||||
m_costsChanged = true;
|
||||
broadcastChanges();
|
||||
}
|
||||
}
|
||||
|
||||
wasLapis = lapis != nullptr;
|
||||
}
|
||||
|
||||
bool EnchantmentMenu::clickMenuButton(shared_ptr<Player> player, int i)
|
||||
|
|
@ -155,44 +187,86 @@ bool EnchantmentMenu::clickMenuButton(shared_ptr<Player> player, int i)
|
|||
shared_ptr<ItemInstance> item = enchantSlots->getItem(0);
|
||||
if (costs[i] > 0 && item != nullptr && (player->experienceLevel >= costs[i] || player->abilities.instabuild) )
|
||||
{
|
||||
bool enough = getLapisCount() >= i+1;
|
||||
if (!enough && !player->abilities.instabuild) return false;
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
bool isBook = item->id == Item::book_Id;
|
||||
|
||||
vector<EnchantmentInstance *> *newEnchantment = EnchantmentHelper::selectEnchantment(&random, item, costs[i]);
|
||||
vector<EnchantmentInstance *> *newEnchantment = cachedEnchantments[i];
|
||||
if (newEnchantment != nullptr)
|
||||
{
|
||||
|
||||
player->giveExperienceLevels(-costs[i]);
|
||||
if (isBook) item->id = Item::enchantedBook_Id;
|
||||
int randomIndex = isBook ? random.nextInt(newEnchantment->size()) : -1;
|
||||
//for (EnchantmentInstance e : newEnchantment)
|
||||
|
||||
for (int index = 0; index < newEnchantment->size(); index++)
|
||||
{
|
||||
EnchantmentInstance *e = newEnchantment->at(index);
|
||||
if (isBook && index != randomIndex)
|
||||
{}
|
||||
EnchantmentInstance* e = newEnchantment->at(index);
|
||||
if (isBook)
|
||||
{
|
||||
Item::enchantedBook->addEnchantment(item, e);
|
||||
en = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isBook)
|
||||
{
|
||||
Item::enchantedBook->addEnchantment(item, e);
|
||||
}
|
||||
else
|
||||
{
|
||||
item->enchant(e->enchantment, e->level);
|
||||
}
|
||||
item->enchant(e->enchantment, e->level);
|
||||
en = true;
|
||||
}
|
||||
delete e;
|
||||
}
|
||||
delete newEnchantment;
|
||||
slotsChanged();// Removed enchantSlots parameter as the function can reference it directly
|
||||
slotsChanged(1);// Removed enchantSlots parameter as the function can reference it directly
|
||||
}
|
||||
}
|
||||
if (!player->abilities.instabuild) lapisSlot->removeItem(1, i+1);
|
||||
nameSeed = (long)nameSeed + random.nextInt(10000);
|
||||
player->enchantmentSeed = random.nextInt(1000000);
|
||||
alreadyRan = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
EnchantmentInstance* EnchantmentMenu::predictEnchantment(shared_ptr<Player> player, int i)
|
||||
{
|
||||
shared_ptr<ItemInstance> item = enchantSlots->getItem(0);
|
||||
if (costs[i] > 0 && item != nullptr && (player->experienceLevel >= costs[i] || player->abilities.instabuild))
|
||||
{
|
||||
if (0 == 0)
|
||||
{
|
||||
bool isBook = item->id == Item::book_Id;
|
||||
Random tempRandom = random;
|
||||
vector<EnchantmentInstance*>* newEnchantment = cachedEnchantments[i];
|
||||
if (newEnchantment != nullptr)
|
||||
{
|
||||
int randomIndex = isBook ? tempRandom.nextInt(newEnchantment->size()) : -1;
|
||||
for (int index = 0; index < newEnchantment->size(); index++)
|
||||
{
|
||||
EnchantmentInstance* e = newEnchantment->at(index);
|
||||
if (isBook)
|
||||
{
|
||||
return e;
|
||||
//en = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//item->enchant(e->enchantment, e->level);
|
||||
return e;
|
||||
//en = true;
|
||||
}
|
||||
//delete e;
|
||||
}
|
||||
//delete newEnchantment;
|
||||
//slotsChanged(1);// Removed enchantSlots parameter as the function can reference it directly
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void EnchantmentMenu::removed(shared_ptr<Player> player)
|
||||
{
|
||||
|
|
@ -204,6 +278,11 @@ void EnchantmentMenu::removed(shared_ptr<Player> player)
|
|||
{
|
||||
player->drop(item);
|
||||
}
|
||||
item = lapisSlot->removeItemNoUpdate(1);
|
||||
if (item != nullptr)
|
||||
{
|
||||
player->drop(item);
|
||||
}
|
||||
}
|
||||
|
||||
bool EnchantmentMenu::stillValid(shared_ptr<Player> player)
|
||||
|
|
@ -213,6 +292,11 @@ bool EnchantmentMenu::stillValid(shared_ptr<Player> player)
|
|||
return true;
|
||||
}
|
||||
|
||||
int EnchantmentMenu::getLapisCount() {
|
||||
if (lapisSlot->getItem(1) == nullptr) return 0;
|
||||
return lapisSlot->getItem(1)->count;
|
||||
}
|
||||
|
||||
shared_ptr<ItemInstance> EnchantmentMenu::quickMoveStack(shared_ptr<Player> player, int slotIndex)
|
||||
{
|
||||
if (slotIndex < 0 || slotIndex >= static_cast<int>(slots.size()))
|
||||
|
|
@ -223,10 +307,15 @@ shared_ptr<ItemInstance> EnchantmentMenu::quickMoveStack(shared_ptr<Player> play
|
|||
shared_ptr<ItemInstance> clicked = nullptr;
|
||||
Slot *slot = slots.at(slotIndex);
|
||||
Slot *IngredientSlot = nullptr;
|
||||
Slot *LapisSlot = nullptr;
|
||||
if (INGREDIENT_SLOT >= 0 && INGREDIENT_SLOT < static_cast<int>(slots.size()))
|
||||
{
|
||||
IngredientSlot = slots.at(INGREDIENT_SLOT);
|
||||
}
|
||||
if (LAPIS_SLOT >= 0 && LAPIS_SLOT < static_cast<int>(slots.size()))
|
||||
{
|
||||
LapisSlot = slots.at(LAPIS_SLOT);
|
||||
}
|
||||
|
||||
if (slot != nullptr && slot->hasItem())
|
||||
{
|
||||
|
|
@ -244,6 +333,16 @@ shared_ptr<ItemInstance> EnchantmentMenu::quickMoveStack(shared_ptr<Player> play
|
|||
|
||||
}
|
||||
}
|
||||
else if (slotIndex == LAPIS_SLOT) {
|
||||
if (!moveItemStackTo(stack, INV_SLOT_START, INV_SLOT_END, true))
|
||||
{
|
||||
if (!moveItemStackTo(stack, USE_ROW_SLOT_START, USE_ROW_SLOT_END, false))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (slotIndex >= INV_SLOT_START && slotIndex < INV_SLOT_END)
|
||||
{
|
||||
// if the item is an enchantable tool
|
||||
|
|
@ -255,6 +354,14 @@ shared_ptr<ItemInstance> EnchantmentMenu::quickMoveStack(shared_ptr<Player> play
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
//DyePowderItem::BLACK
|
||||
else if (stack->getItem()->id == 351 && stack->getItem()->getMaterial() == 11)
|
||||
{
|
||||
if(!moveItemStackTo(stack, LAPIS_SLOT, LAPIS_SLOT+1, false))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!moveItemStackTo(stack, USE_ROW_SLOT_START, USE_ROW_SLOT_END, false))
|
||||
|
|
@ -274,6 +381,13 @@ shared_ptr<ItemInstance> EnchantmentMenu::quickMoveStack(shared_ptr<Player> play
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
else if (stack->getItem()->id == 351 && stack->getItem()->getMaterial() == 11)
|
||||
{
|
||||
if (!moveItemStackTo(stack, LAPIS_SLOT, LAPIS_SLOT + 1, false))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!moveItemStackTo(stack, INV_SLOT_START, INV_SLOT_END, false))
|
||||
|
|
|
|||
|
|
@ -1,40 +1,57 @@
|
|||
#pragma once
|
||||
#include "AbstractContainerMenu.h"
|
||||
#include "Random.h"
|
||||
#include "EnchantmentInstance.h"
|
||||
|
||||
class EnchantmentMenu : public AbstractContainerMenu
|
||||
{
|
||||
// 4J Stu Made these public for UI menus, perhaps should make friend class?
|
||||
public:
|
||||
static const int INGREDIENT_SLOT = 0;
|
||||
static const int INV_SLOT_START = EnchantmentMenu::INGREDIENT_SLOT + 1;
|
||||
static const int LAPIS_SLOT = 1;
|
||||
static const int INV_SLOT_START = EnchantmentMenu::INGREDIENT_SLOT + 2;
|
||||
static const int INV_SLOT_END = EnchantmentMenu::INV_SLOT_START + 9 * 3;
|
||||
static const int USE_ROW_SLOT_START = EnchantmentMenu::INV_SLOT_END;
|
||||
static const int USE_ROW_SLOT_END = EnchantmentMenu::USE_ROW_SLOT_START + 9;
|
||||
|
||||
public:
|
||||
shared_ptr<Container> enchantSlots;
|
||||
shared_ptr<Container> lapisSlot;
|
||||
bool alreadyRan = false;
|
||||
bool en = false;
|
||||
// Header
|
||||
std::vector<EnchantmentInstance*>* cachedEnchantments[3] = { nullptr, nullptr, nullptr };
|
||||
int getLapisCount();
|
||||
//int iPad;
|
||||
Player* playerT;
|
||||
|
||||
private:
|
||||
Level *level;
|
||||
int x, y, z;
|
||||
Random random;
|
||||
|
||||
|
||||
bool m_costsChanged; // 4J Added
|
||||
int bookcasesC = -1;
|
||||
|
||||
public:
|
||||
int64_t nameSeed;
|
||||
|
||||
bool wasLapis;
|
||||
|
||||
Random random;
|
||||
public:
|
||||
int costs[3];
|
||||
int tempCosts[3];
|
||||
|
||||
|
||||
EnchantmentMenu(shared_ptr<Inventory> inventory, Level *level, int xt, int yt, int zt);
|
||||
|
||||
virtual void addSlotListener(ContainerListener *listener);
|
||||
virtual void broadcastChanges();
|
||||
vector<EnchantmentInstance*> getEnchantment();
|
||||
virtual void setData(int id, int value);
|
||||
virtual void slotsChanged();// 4J used to take a shared_ptr<Container> container but wasn't using it, so removed to simplify things
|
||||
virtual void slotsChanged(int a);// 4J used to take a shared_ptr<Container> container but wasn't using it, so removed to simplify things
|
||||
virtual bool clickMenuButton(shared_ptr<Player> player, int i);
|
||||
virtual EnchantmentInstance* predictEnchantment(shared_ptr<Player> player, int i);
|
||||
void removed(shared_ptr<Player> player);
|
||||
virtual bool stillValid(shared_ptr<Player> player);
|
||||
virtual shared_ptr<ItemInstance> quickMoveStack(shared_ptr<Player> player, int slotIndex);
|
||||
|
|
|
|||
|
|
@ -1270,6 +1270,7 @@ void Player::readAdditionalSaveData(CompoundTag *entityTag)
|
|||
sleepCounter = entityTag->getShort(L"SleepTimer");
|
||||
|
||||
experienceProgress = entityTag->getFloat(L"XpP");
|
||||
enchantmentSeed = entityTag->getInt(L"enchSeed");
|
||||
experienceLevel = entityTag->getInt(L"XpLevel");
|
||||
totalExperience = entityTag->getInt(L"XpTotal");
|
||||
setScore(entityTag->getInt(L"Score"));
|
||||
|
|
@ -1308,6 +1309,7 @@ void Player::addAdditonalSaveData(CompoundTag *entityTag)
|
|||
entityTag->putShort(L"SleepTimer", static_cast<short>(sleepCounter));
|
||||
|
||||
entityTag->putFloat(L"XpP", experienceProgress);
|
||||
entityTag->putInt(L"enchSeed", enchantmentSeed);
|
||||
entityTag->putInt(L"XpLevel", experienceLevel);
|
||||
entityTag->putInt(L"XpTotal", totalExperience);
|
||||
entityTag->putInt(L"Score", getScore());
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ private:
|
|||
public:
|
||||
AbstractContainerMenu *inventoryMenu;
|
||||
AbstractContainerMenu *containerMenu;
|
||||
int enchantmentSeed = 0;
|
||||
|
||||
protected:
|
||||
FoodData foodData;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public:
|
|||
virtual void addListener(net_minecraft_world::ContainerListener *listener);
|
||||
virtual void removeListener(net_minecraft_world::ContainerListener *listener);
|
||||
virtual shared_ptr<ItemInstance> getItem(unsigned int slot);
|
||||
virtual ItemInstanceArray* getItems() { return items; }
|
||||
virtual shared_ptr<ItemInstance> removeItem(unsigned int slot, int count);
|
||||
virtual shared_ptr<ItemInstance> removeItemNoUpdate(int slot);
|
||||
virtual void setItem(unsigned int slot, shared_ptr<ItemInstance> item);
|
||||
|
|
|
|||
Loading…
Reference in a new issue