Something went wrong. Try again.
the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
Something went wrong. Try again.
25 kB · 923 lines
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923#include "stdafx.h"#include "..\Minecraft.Client\Minecraft.h"#include "net.minecraft.world.effect.h"#include "JavaMath.h"#include "SharedConstants.h"#include "PotionBrewing.h"
const int PotionBrewing::DEFAULT_APPEARANCES[] ={ IDS_POTION_PREFIX_MUNDANE, IDS_POTION_PREFIX_UNINTERESTING, IDS_POTION_PREFIX_BLAND, IDS_POTION_PREFIX_CLEAR, IDS_POTION_PREFIX_MILKY, IDS_POTION_PREFIX_DIFFUSE, IDS_POTION_PREFIX_ARTLESS, IDS_POTION_PREFIX_THIN, IDS_POTION_PREFIX_AWKWARD, IDS_POTION_PREFIX_FLAT, IDS_POTION_PREFIX_BULKY, IDS_POTION_PREFIX_BUNGLING, IDS_POTION_PREFIX_BUTTERED, IDS_POTION_PREFIX_SMOOTH, IDS_POTION_PREFIX_SUAVE, IDS_POTION_PREFIX_DEBONAIR, IDS_POTION_PREFIX_THICK, IDS_POTION_PREFIX_ELEGANT, IDS_POTION_PREFIX_FANCY, IDS_POTION_PREFIX_CHARMING, IDS_POTION_PREFIX_DASHING, IDS_POTION_PREFIX_REFINED, IDS_POTION_PREFIX_CORDIAL, IDS_POTION_PREFIX_SPARKLING, IDS_POTION_PREFIX_POTENT, IDS_POTION_PREFIX_FOUL, IDS_POTION_PREFIX_ODORLESS, IDS_POTION_PREFIX_RANK, IDS_POTION_PREFIX_HARSH, IDS_POTION_PREFIX_ACRID, IDS_POTION_PREFIX_GROSS, IDS_POTION_PREFIX_STINKY,};
// bit 4 is the "enabler," lit by nether seeds
// bits 0-3 are effect identifiers // 0001 - regeneration // 0010 - move speed // 0011 - fire resist // 0100 - poison // 0101 - heal // 0110 - night vision // 0111 - invisibility // 1000 - weakness // 1001 - damage boost // 1010 - move slow // 1011 - // 1100 - harm // 1101 - // 1110 - // 1111 -
/* 4J-JEV: Fix for #81196, * Bit 13 is always set in functional potions. * Therefore if bit 13 is on, don't use netherwart! * Added "&!13" which requires that bit 13 be turned off. */const wstring PotionBrewing::MOD_NETHERWART = L"+4&!13"; // L"+4"
#if _SIMPLIFIED_BREWINGconst wstring PotionBrewing::MOD_WATER = L"";const wstring PotionBrewing::MOD_SUGAR = L"-0+1-2-3&4-4+13";const wstring PotionBrewing::MOD_GHASTTEARS = L"+0-1-2-3&4-4+13";const wstring PotionBrewing::MOD_SPIDEREYE = L"-0-1+2-3&4-4+13";const wstring PotionBrewing::MOD_FERMENTEDEYE = L"-0+3-4+13";const wstring PotionBrewing::MOD_SPECKLEDMELON = L"+0-1+2-3&4-4+13";const wstring PotionBrewing::MOD_BLAZEPOWDER = L"+0-1-2+3&4-4+13";const wstring PotionBrewing::MOD_GOLDENCARROT = L"-0+1+2-3+13&4-4";const wstring PotionBrewing::MOD_MAGMACREAM = L"+0+1-2-3&4-4+13";const wstring PotionBrewing::MOD_REDSTONE = L"-5+6-7"; // redstone increases durationconst wstring PotionBrewing::MOD_GLOWSTONE = L"+5-6-7"; // glowstone increases amplification// 4J Stu - Don't require bit 13 to be set. We don't use it in the creative menu. Side effect is you can make a (virtually useless) Splash Mundane potion with water bottle and gunpowderconst wstring PotionBrewing::MOD_GUNPOWDER = L"+14";//&13-13"; // gunpowder makes them throwable! // gunpowder requires 13 and sets 14#elseconst wstring PotionBrewing::MOD_WATER = L"-1-3-5-7-9-11-13";const wstring PotionBrewing::MOD_SUGAR = L"+0";const wstring PotionBrewing::MOD_GHASTTEARS = L"+11";const wstring PotionBrewing::MOD_SPIDEREYE = L"+10+7+5";const wstring PotionBrewing::MOD_FERMENTEDEYE = L"+14+9";const wstring PotionBrewing::MOD_SPECKLEDMELON = L"";const wstring PotionBrewing::MOD_BLAZEPOWDER = L"+14";const wstring PotionBrewing::MOD_MAGMACREAM = L"+14+6+1";const wstring PotionBrewing::MOD_REDSTONE = L""; // redstone increases durationconst wstring PotionBrewing::MOD_GLOWSTONE = L""; // glowstone increases amplificationconst wstring PotionBrewing::MOD_GUNPOWDER = L""; // gunpowder makes them throwable! // gunpowder requires 13 and sets 14#endif
PotionBrewing::intStringMap PotionBrewing::potionEffectDuration;PotionBrewing::intStringMap PotionBrewing::potionEffectAmplifier;
unordered_map<int, int> PotionBrewing::cachedColors;
void PotionBrewing::staticCtor(){#if _SIMPLIFIED_BREWING potionEffectDuration.insert(intStringMap::value_type( MobEffect::regeneration->getId(), L"0 & !1 & !2 & !3 & 0+6" )); potionEffectDuration.insert(intStringMap::value_type( MobEffect::movementSpeed->getId(), L"!0 & 1 & !2 & !3 & 1+6" )); potionEffectDuration.insert(intStringMap::value_type( MobEffect::fireResistance->getId(), L"0 & 1 & !2 & !3 & 0+6" )); potionEffectDuration.insert(intStringMap::value_type( MobEffect::heal->getId(), L"0 & !1 & 2 & !3" )); potionEffectDuration.insert(intStringMap::value_type( MobEffect::poison->getId(), L"!0 & !1 & 2 & !3 & 2+6" )); potionEffectDuration.insert(intStringMap::value_type( MobEffect::weakness->getId(), L"!0 & !1 & !2 & 3 & 3+6" )); potionEffectDuration.insert(intStringMap::value_type( MobEffect::harm->getId(), L"!0 & !1 & 2 & 3" )); potionEffectDuration.insert(intStringMap::value_type( MobEffect::movementSlowdown->getId(), L"!0 & 1 & !2 & 3 & 3+6" )); potionEffectDuration.insert(intStringMap::value_type( MobEffect::damageBoost->getId(), L"0 & !1 & !2 & 3 & 3+6" )); potionEffectDuration.insert(intStringMap::value_type( MobEffect::nightVision->getId(), L"!0 & 1 & 2 & !3 & 2+6" )); potionEffectDuration.insert(intStringMap::value_type( MobEffect::invisibility->getId(), L"!0 & 1 & 2 & 3 & 2+6" ));
// glowstone increases amplification potionEffectAmplifier.insert(intStringMap::value_type( MobEffect::movementSpeed->getId(), L"5" )); potionEffectAmplifier.insert(intStringMap::value_type( MobEffect::digSpeed->getId(), L"5" )); potionEffectAmplifier.insert(intStringMap::value_type( MobEffect::damageBoost->getId(), L"5" )); potionEffectAmplifier.insert(intStringMap::value_type( MobEffect::regeneration->getId(), L"5" )); potionEffectAmplifier.insert(intStringMap::value_type( MobEffect::harm->getId(), L"5" )); potionEffectAmplifier.insert(intStringMap::value_type( MobEffect::heal->getId(), L"5" )); potionEffectAmplifier.insert(intStringMap::value_type( MobEffect::damageResistance->getId(), L"5" )); potionEffectAmplifier.insert(intStringMap::value_type( MobEffect::poison->getId(), L"5" ));#else potionEffectDuration.put(movementSpeed.getId(), "!10 & !4 & 5*2+0 & >1 | !7 & !4 & 5*2+0 & >1"); potionEffectDuration.put(movementSlowdown.getId(), "10 & 7 & !4 & 7+5+1-0"); potionEffectDuration.put(digSpeed.getId(), "2 & 12+2+6-1-7 & <8"); potionEffectDuration.put(digSlowdown.getId(), "!2 & !1*2-9 & 14-5"); potionEffectDuration.put(damageBoost.getId(), "9 & 3 & 9+4+5 & <11"); potionEffectDuration.put(weakness.getId(), "=1>5>7>9+3-7-2-11 & !9 & !0"); potionEffectDuration.put(heal.getId(), "11 & <6"); potionEffectDuration.put(harm.getId(), "!11 & 1 & 10 & !7"); potionEffectDuration.put(jump.getId(), "8 & 2+0 & <5"); potionEffectDuration.put(confusion.getId(), "8*2-!7+4-11 & !2 | 13 & 11 & 2*3-1-5"); potionEffectDuration.put(regeneration.getId(), "!14 & 13*3-!0-!5-8"); potionEffectDuration.put(damageResistance.getId(), "10 & 4 & 10+5+6 & <9"); potionEffectDuration.put(fireResistance.getId(), "14 & !5 & 6-!1 & 14+13+12"); potionEffectDuration.put(waterBreathing.getId(), "0+1+12 & !6 & 10 & !11 & !13"); potionEffectDuration.put(invisibility.getId(), "2+5+13-0-4 & !7 & !1 & >5"); potionEffectDuration.put(blindness.getId(), "9 & !1 & !5 & !3 & =3"); potionEffectDuration.put(nightVision.getId(), "8*2-!7 & 5 & !0 & >3"); potionEffectDuration.put(hunger.getId(), ">4>6>8-3-8+2"); potionEffectDuration.put(poison.getId(), "12+9 & !13 & !0");
potionEffectAmplifier.put(movementSpeed.getId(), "7+!3-!1"); potionEffectAmplifier.put(digSpeed.getId(), "1+0-!11"); potionEffectAmplifier.put(damageBoost.getId(), "2+7-!12"); potionEffectAmplifier.put(heal.getId(), "11+!0-!1-!14"); potionEffectAmplifier.put(harm.getId(), "!11-!14+!0-!1"); potionEffectAmplifier.put(damageResistance.getId(), "12-!2"); potionEffectAmplifier.put(poison.getId(), "14>5");#endif}
bool PotionBrewing::isWrappedLit(int brew, int position){ return (brew & (1 << (position % NUM_BITS))) != 0;}
bool PotionBrewing::isLit(int brew, int position){ return (brew & (1 << position)) != 0;}
int PotionBrewing::isBit(int brew, int position){ return isLit(brew, position) ? 1 : 0;}
int PotionBrewing::isNotBit(int brew, int position){ return isLit(brew, position) ? 0 : 1;}
int PotionBrewing::getAppearanceValue(int brew){ return valueOf(brew, 5, 4, 3, 2, 1);}
int PotionBrewing::getColorValue(vector<MobEffectInstance *> *effects){ ColourTable *colourTable = Minecraft::GetInstance()->getColourTable();
int baseColor = colourTable->getColor( eMinecraftColour_Potion_BaseColour );
if (effects == NULL || effects->empty()) { return baseColor; }
float red = 0; float green = 0; float blue = 0; float count = 0;
//for (MobEffectInstance effect : effects){ for(AUTO_VAR(it, effects->begin()); it != effects->end(); ++it) { MobEffectInstance *effect = *it; int potionColor = colourTable->getColor( MobEffect::effects[effect->getId()]->getColor() );
for (int potency = 0; potency <= effect->getAmplifier(); potency++) { red += (float) ((potionColor >> 16) & 0xff) / 255.0f; green += (float) ((potionColor >> 8) & 0xff) / 255.0f; blue += (float) ((potionColor >> 0) & 0xff) / 255.0f; count++; } }
red = (red / count) * 255.0f; green = (green / count) * 255.0f; blue = (blue / count) * 255.0f;
return ((int) red) << 16 | ((int) green) << 8 | ((int) blue);}
bool PotionBrewing::areAllEffectsAmbient(vector<MobEffectInstance *> *effects){ for(AUTO_VAR(it, effects->begin()); it != effects->end(); ++it) { MobEffectInstance *effect = *it; if (!effect->isAmbient()) return false; }
return true;}
int PotionBrewing::getColorValue(int brew, bool includeDisabledEffects){ if (!includeDisabledEffects) { AUTO_VAR(colIt, cachedColors.find(brew)); if (colIt != cachedColors.end()) { return colIt->second;//cachedColors.get(brew); } vector<MobEffectInstance *> *effects = getEffects(brew, false); int color = getColorValue(effects); if(effects != NULL) { for(AUTO_VAR(it, effects->begin()); it != effects->end(); ++it) { MobEffectInstance *effect = *it; delete effect; } delete effects; } cachedColors.insert( std::pair<int,int>(brew, color) ); return color; }
return getColorValue(getEffects(brew, includeDisabledEffects));}
int PotionBrewing::getSmellValue(int brew){ return valueOf(brew, 12, 11, 6, 4, 0);}
int PotionBrewing::getAppearanceName(int brew){ int value = getAppearanceValue(brew); return DEFAULT_APPEARANCES[value];}
int PotionBrewing::constructParsedValue(bool isNot, bool hasMultiplier, bool isNeg, int countCompare, int valuePart, int multiplierPart, int brew){ int value = 0; if (isNot) { value = isNotBit(brew, valuePart); }#if !(_SIMPLIFIED_BREWING) else if (countCompare != NO_COUNT) // Never true for simplified brewing { if (countCompare == EQUAL_COUNT && countOnes(brew) == valuePart) { value = 1; } else if (countCompare == GREATER_COUNT && countOnes(brew) > valuePart) { value = 1; } else if (countCompare == LESS_COUNT && countOnes(brew) < valuePart) { value = 1; } }#endif else { value = isBit(brew, valuePart); }#if !(_SIMPLIFIED_BREWING) if (hasMultiplier) // Always false for simplified brewing { value *= multiplierPart; }#endif if (isNeg) { value *= -1; } return value;}
int PotionBrewing::countOnes(int brew){ int c = 0; for (; brew > 0; c++) { brew &= brew - 1; } return c;}
#if _SIMPLIFIED_BREWING// 4J Stu - Trimmed this function to remove all the unused features for simplified brewingint PotionBrewing::parseEffectFormulaValue(const wstring &definition, int start, int end, int brew){ if (start >= definition.length() || end < 0 || start >= end) { return 0; }
// split by and int andIndex = (int)definition.find_first_of(L'&', start); if (andIndex >= 0 && andIndex < end) { int leftSide = parseEffectFormulaValue(definition, start, andIndex - 1, brew); if (leftSide <= 0) { return 0; }
int rightSide = parseEffectFormulaValue(definition, andIndex + 1, end, brew); if (rightSide <= 0) { return 0; }
if (leftSide > rightSide) { return leftSide; } return rightSide; }
bool hasMultiplier = false; bool hasValue = false; bool isNot = false; bool isNeg = false; int bitCount = NO_COUNT; int valuePart = 0; int multiplierPart = 0; int result = 0; for (int i = start; i < end; i++) {
char current = definition.at(i); if (current >= L'0' && current <= L'9') { valuePart *= 10; valuePart += (int) (current - L'0'); hasValue = true; } else if (current == L'!') { if (hasValue) { result += constructParsedValue(isNot, hasMultiplier, isNeg, bitCount, valuePart, multiplierPart, brew); hasValue = isNeg = isNot = false; valuePart = 0; }
isNot = true; } else if (current == L'-') { if (hasValue) { result += constructParsedValue(isNot, hasMultiplier, isNeg, bitCount, valuePart, multiplierPart, brew); hasValue = isNeg = isNot = false; valuePart = 0; }
isNeg = true; } else if (current == L'+') { if (hasValue) { result += constructParsedValue(isNot, hasMultiplier, isNeg, bitCount, valuePart, multiplierPart, brew); hasValue = isNeg = isNot = false; valuePart = 0; } } } if (hasValue) { result += constructParsedValue(isNot, hasMultiplier, isNeg, bitCount, valuePart, multiplierPart, brew); }
return result;}#elseint PotionBrewing::parseEffectFormulaValue(const wstring &definition, int start, int end, int brew){ if (start >= definition.length() || end < 0 || start >= end) { return 0; }
// split by or int orIndex = definition.find_first_of(L'|', start); if (orIndex >= 0 && orIndex < end) { int leftSide = parseEffectFormulaValue(definition, start, orIndex - 1, brew); if (leftSide > 0) { return leftSide; }
int rightSide = parseEffectFormulaValue(definition, orIndex + 1, end, brew); if (rightSide > 0) { return rightSide; } return 0; } // split by and int andIndex = definition.find_first_of(L'&', start); if (andIndex >= 0 && andIndex < end) { int leftSide = parseEffectFormulaValue(definition, start, andIndex - 1, brew); if (leftSide <= 0) { return 0; }
int rightSide = parseEffectFormulaValue(definition, andIndex + 1, end, brew); if (rightSide <= 0) { return 0; }
if (leftSide > rightSide) { return leftSide; } return rightSide; }
bool isMultiplier = false; bool hasMultiplier = false; bool hasValue = false; bool isNot = false; bool isNeg = false; int bitCount = NO_COUNT; int valuePart = 0; int multiplierPart = 0; int result = 0; for (int i = start; i < end; i++) {
char current = definition.at(i); if (current >= L'0' && current <= L'9') { if (isMultiplier) { multiplierPart = (int) (current - L'0'); hasMultiplier = true; } else { valuePart *= 10; valuePart += (int) (current - L'0'); hasValue = true; } } else if (current == L'*') { isMultiplier = true; } else if (current == L'!') { if (hasValue) { result += constructParsedValue(isNot, hasMultiplier, isNeg, bitCount, valuePart, multiplierPart, brew); hasValue = hasMultiplier = isMultiplier = isNeg = isNot = false; valuePart = multiplierPart = 0; bitCount = NO_COUNT; }
isNot = true; } else if (current == L'-') { if (hasValue) { result += constructParsedValue(isNot, hasMultiplier, isNeg, bitCount, valuePart, multiplierPart, brew); hasValue = hasMultiplier = isMultiplier = isNeg = isNot = false; valuePart = multiplierPart = 0; bitCount = NO_COUNT; }
isNeg = true; } else if (current == L'=' || current == L'<' || current == L'>') { if (hasValue) { result += constructParsedValue(isNot, hasMultiplier, isNeg, bitCount, valuePart, multiplierPart, brew); hasValue = hasMultiplier = isMultiplier = isNeg = isNot = false; valuePart = multiplierPart = 0; bitCount = NO_COUNT; }
if (current == L'=') { bitCount = EQUAL_COUNT; } else if (current == L'<') { bitCount = LESS_COUNT; } else if (current == L'>') { bitCount = GREATER_COUNT; } } else if (current == L'+') { if (hasValue) { result += constructParsedValue(isNot, hasMultiplier, isNeg, bitCount, valuePart, multiplierPart, brew); hasValue = hasMultiplier = isMultiplier = isNeg = isNot = false; valuePart = multiplierPart = 0; bitCount = NO_COUNT; } } } if (hasValue) { result += constructParsedValue(isNot, hasMultiplier, isNeg, bitCount, valuePart, multiplierPart, brew); }
return result;}#endif
vector<MobEffectInstance *> *PotionBrewing::getEffects(int brew, bool includeDisabledEffects){ vector<MobEffectInstance *> *list = NULL;
//for (MobEffect effect : MobEffect.effects) for(unsigned int i = 0; i < MobEffect::NUM_EFFECTS; ++i) { MobEffect *effect = MobEffect::effects[i]; if (effect == NULL || (effect->isDisabled() && !includeDisabledEffects)) { continue; } //wstring durationString = potionEffectDuration.get(effect->getId()); AUTO_VAR(effIt, potionEffectDuration.find(effect->getId())); if ( effIt == potionEffectDuration.end() ) { continue; } wstring durationString = effIt->second;
int duration = parseEffectFormulaValue(durationString, 0, (int)durationString.length(), brew); if (duration > 0) { int amplifier = 0; AUTO_VAR(ampIt, potionEffectAmplifier.find(effect->getId())); if (ampIt != potionEffectAmplifier.end()) { wstring amplifierString = ampIt->second; amplifier = parseEffectFormulaValue(amplifierString, 0, (int)amplifierString.length(), brew); if (amplifier < 0) { amplifier = 0; } }
if (effect->isInstantenous()) { duration = 1; } else { // 3, 8, 13, 18.. minutes duration = (SharedConstants::TICKS_PER_SECOND * 60) * (duration * 3 + (duration - 1) * 2); duration >>= amplifier; duration = (int) Math::round((double) duration * effect->getDurationModifier());
if ((brew & THROWABLE_MASK) != 0) { duration = (int) Math::round((double) duration * .75 + .5); } }
if (list == NULL) { list = new vector<MobEffectInstance *>(); } MobEffectInstance *instance = new MobEffectInstance(effect->getId(), duration, amplifier); if ((brew & THROWABLE_MASK) != 0) instance->setSplash(true); list->push_back(instance); } }
return list;}
#if !(_SIMPLIFIED_BREWING)int PotionBrewing::boil(int brew){ if ((brew & 1) == 0) { return brew; }
// save highest bit int savedBit = NUM_BITS - 1; while ((brew & (1 << savedBit)) == 0 && savedBit >= 0) { savedBit--; } // it's not possible to boil if there are no "empty slots" in front of // the last bit if (savedBit < 2 || (brew & (1 << (savedBit - 1))) != 0) { return brew; } if (savedBit >= 0) { brew &= ~(1 << savedBit); }
brew <<= 1;
if (savedBit >= 0) { brew |= (1 << savedBit); brew |= (1 << (savedBit - 1)); }
return brew & BREW_MASK;}
int PotionBrewing::shake(int brew){
// save highest bit int savedBit = NUM_BITS - 1; while ((brew & (1 << savedBit)) == 0 && savedBit >= 0) { savedBit--; } if (savedBit >= 0) { brew &= ~(1 << savedBit); }
int currentResult = 0; int nextResult = brew;
while (nextResult != currentResult) { nextResult = brew; currentResult = 0; // evaluate each bit for (int bit = 0; bit < NUM_BITS; bit++) {
bool on = isWrappedLit(brew, bit); if (on) { if (!isWrappedLit(brew, bit + 1) && isWrappedLit(brew, bit + 2)) { on = false; } else if (!isWrappedLit(brew, bit - 1) && isWrappedLit(brew, bit - 2)) { on = false; } } else { // turn on if both neighbors are on on = isWrappedLit(brew, bit - 1) && isWrappedLit(brew, bit + 1); } if (on) { currentResult |= (1 << bit); } } brew = currentResult; }
if (savedBit >= 0) { currentResult |= (1 << savedBit); }
return currentResult & BREW_MASK;}
int PotionBrewing::stirr(int brew){ if ((brew & 1) != 0) { brew = boil(brew); } return shake(brew);}#endif
int PotionBrewing::applyBrewBit(int currentBrew, int bit, bool isNeg, bool isNot, bool isRequired){ if (isRequired) { // 4J-JEV: I wanted to be able to specify that a // bit is required to be false. if (isLit(currentBrew, bit) == isNot) { return 0; } } else if (isNeg) { currentBrew &= ~(1 << bit); } else if (isNot) { if ((currentBrew & (1 << bit)) == 0) { currentBrew |= (1 << bit); } else { currentBrew &= ~(1 << bit); } } else { currentBrew |= (1 << bit); } return currentBrew;}
int PotionBrewing::applyBrew(int currentBrew, const wstring &formula){
int start = 0; int end = (int)formula.length();
bool hasValue = false; bool isNot = false; bool isNeg = false; bool isRequired = false; int valuePart = 0; for (int i = start; i < end; i++) { char current = formula.at(i); if (current >= L'0' && current <= L'9') { valuePart *= 10; valuePart += (int) (current - L'0'); hasValue = true; } else if (current == L'!') { if (hasValue) { currentBrew = applyBrewBit(currentBrew, valuePart, isNeg, isNot, isRequired); hasValue = isNeg = isNot = isRequired = false; valuePart = 0; }
isNot = true; } else if (current == L'-') { if (hasValue) { currentBrew = applyBrewBit(currentBrew, valuePart, isNeg, isNot, isRequired); hasValue = isNeg = isNot = isRequired = false; valuePart = 0; }
isNeg = true; } else if (current == L'+') { if (hasValue) { currentBrew = applyBrewBit(currentBrew, valuePart, isNeg, isNot, isRequired); hasValue = isNeg = isNot = isRequired = false; valuePart = 0; } } else if (current == L'&') { if (hasValue) { currentBrew = applyBrewBit(currentBrew, valuePart, isNeg, isNot, isRequired); hasValue = isNeg = isNot = isRequired = false; valuePart = 0; } isRequired = true; } } if (hasValue) { currentBrew = applyBrewBit(currentBrew, valuePart, isNeg, isNot, isRequired); }
return currentBrew & BREW_MASK;}
int PotionBrewing::setBit(int brew, int position, bool onOff){ if (onOff) { return brew | (1 << position); } return brew & ~(1 << position);}
int PotionBrewing::valueOf(int brew, int p1, int p2, int p3, int p4){ return ((isLit(brew, p1) ? 0x08 : 0) | (isLit(brew, p2) ? 0x04 : 0) | (isLit(brew, p3) ? 0x02 : 0) | (isLit(brew, p4) ? 0x01 : 0));}
int PotionBrewing::valueOf(int brew, int p1, int p2, int p3, int p4, int p5){ return (isLit(brew, p1) ? 0x10 : 0) | (isLit(brew, p2) ? 0x08 : 0) | (isLit(brew, p3) ? 0x04 : 0) | (isLit(brew, p4) ? 0x02 : 0) | (isLit(brew, p5) ? 0x01 : 0);}
wstring PotionBrewing::toString(int brew){ wstring string;
int bit = NUM_BITS - 1; while (bit >= 0) { if ((brew & (1 << bit)) != 0) { string.append(L"O"); } else { string.append(L"x"); } bit--; }
return string;}
//void main(String[] args)//{
// HashMap<String, Integer> existingCombinations = new HashMap<String, Integer>();// HashMap<String, Integer> distinctCombinations = new HashMap<String, Integer>();// int noEffects = 0;// for (int brew = 0; brew <= BREW_MASK; brew++) {// List<MobEffectInstance> effects = PotionBrewing.getEffects(brew, true);// if (effects != null) {
// {// StringBuilder builder = new StringBuilder();// for (MobEffectInstance effect : effects) {// builder.append(effect.toString());// builder.append(" ");// }// String string = builder.toString();// Integer count = existingCombinations.get(string);// if (count != null) {// count++;// } else {// count = 1;// }// existingCombinations.put(string, count);// }// {// StringBuilder builder = new StringBuilder();// for (MobEffectInstance effect : effects) {// builder.append(effect.getDescriptionId());// builder.append(" ");// }// String string = builder.toString();// Integer count = distinctCombinations.get(string);// if (count != null) {// count++;// } else {// count = 1;// }// distinctCombinations.put(string, count);// }// } else {// noEffects++;// }// }
// for (String combination : existingCombinations.keySet()) {// Integer count = existingCombinations.get(combination);// if (count > 20) {// System.out.println(combination + ": " + count);// }// }
// System.out.println("Combination with no effects: " + noEffects + " (" + ((double) noEffects / BREW_MASK * 100.0) + " %)");// System.out.println("Unique combinations: " + existingCombinations.size());// System.out.println("Distinct combinations: " + distinctCombinations.size());//}