aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/BrewingStandTileEntity.cpp
diff options
context:
space:
mode:
authordaoge <3523206925@qq.com>2026-03-03 03:04:10 +0800
committerGitHub <noreply@github.com>2026-03-03 03:04:10 +0800
commitb3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch)
tree267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/BrewingStandTileEntity.cpp
parent84c31a2331f7a0ec85b9d438992e244f60e5020f (diff)
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict * feat: TU19 (Dec 2014) Features & Content (#32) * December 2014 files * Working release build * Fix compilation issues * Add sound to Windows64Media * Add DLC content and force Tutorial DLC * Revert "Add DLC content and force Tutorial DLC" This reverts commit 97a43994725008e35fceb984d5549df9c8cea470. * Disable broken light packing * Disable breakpoint during DLC texture map load Allows DLC loading but the DLC textures are still broken * Fix post build not working * ... * fix vs2022 build * fix cmake build --------- Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/BrewingStandTileEntity.cpp')
-rw-r--r--Minecraft.World/BrewingStandTileEntity.cpp373
1 files changed, 217 insertions, 156 deletions
diff --git a/Minecraft.World/BrewingStandTileEntity.cpp b/Minecraft.World/BrewingStandTileEntity.cpp
index 20cb3737..00170d7b 100644
--- a/Minecraft.World/BrewingStandTileEntity.cpp
+++ b/Minecraft.World/BrewingStandTileEntity.cpp
@@ -2,16 +2,22 @@
#include "com.mojang.nbt.h"
#include "BrewingStandTileEntity.h"
#include "SharedConstants.h"
+#include "net.minecraft.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.item.alchemy.h"
+int slotsForUp [] = { BrewingStandTileEntity::INGREDIENT_SLOT };
+int slotsForOtherFaces [] = { 0, 1, 2 };
+intArray BrewingStandTileEntity::SLOTS_FOR_UP = intArray(slotsForUp, 1);
+intArray BrewingStandTileEntity::SLOTS_FOR_OTHER_FACES = intArray(slotsForOtherFaces, 3);
BrewingStandTileEntity::BrewingStandTileEntity()
{
brewTime = 0;
items = ItemInstanceArray(4);
+ name = L"";
}
BrewingStandTileEntity::~BrewingStandTileEntity()
@@ -19,9 +25,24 @@ BrewingStandTileEntity::~BrewingStandTileEntity()
delete [] items.data;
}
-int BrewingStandTileEntity::getName()
+wstring BrewingStandTileEntity::getName()
{
- return IDS_TILE_BREWINGSTAND;
+ return hasCustomName() ? name : app.GetString(IDS_TILE_BREWINGSTAND);
+}
+
+wstring BrewingStandTileEntity::getCustomName()
+{
+ return hasCustomName() ? name : L"";
+}
+
+bool BrewingStandTileEntity::hasCustomName()
+{
+ return !name.empty();
+}
+
+void BrewingStandTileEntity::setCustomName(const wstring &name)
+{
+ this->name = name;
}
unsigned int BrewingStandTileEntity::getContainerSize()
@@ -31,41 +52,41 @@ unsigned int BrewingStandTileEntity::getContainerSize()
void BrewingStandTileEntity::tick()
{
- if (brewTime > 0)
+ if (brewTime > 0)
{
- brewTime--;
+ brewTime--;
- if (brewTime == 0)
+ if (brewTime == 0)
{
- // apply ingredients to all potions
- doBrew();
- setChanged();
- }
+ // apply ingredients to all potions
+ doBrew();
+ setChanged();
+ }
else if (!isBrewable())
{
- brewTime = 0;
- setChanged();
- }
+ brewTime = 0;
+ setChanged();
+ }
else if (ingredientId != items[INGREDIENT_SLOT]->id)
{
- brewTime = 0;
- setChanged();
- }
- }
+ brewTime = 0;
+ setChanged();
+ }
+ }
else if (isBrewable())
{
- brewTime = SharedConstants::TICKS_PER_SECOND * PotionBrewing::BREWING_TIME_SECONDS;
- ingredientId = items[INGREDIENT_SLOT]->id;
- }
+ brewTime = SharedConstants::TICKS_PER_SECOND * PotionBrewing::BREWING_TIME_SECONDS;
+ ingredientId = items[INGREDIENT_SLOT]->id;
+ }
- int newCount = getPotionBits();
- if (newCount != lastPotionCount)
+ int newCount = getPotionBits();
+ if (newCount != lastPotionCount)
{
- lastPotionCount = newCount;
- level->setData(x, y, z, newCount);
- }
+ lastPotionCount = newCount;
+ level->setData(x, y, z, newCount, Tile::UPDATE_CLIENTS);
+ }
- TileEntity::tick();
+ TileEntity::tick();
}
int BrewingStandTileEntity::getBrewTime()
@@ -75,34 +96,34 @@ int BrewingStandTileEntity::getBrewTime()
bool BrewingStandTileEntity::isBrewable()
{
- if (items[INGREDIENT_SLOT] == NULL || items[INGREDIENT_SLOT]->count <= 0)
+ if (items[INGREDIENT_SLOT] == NULL || items[INGREDIENT_SLOT]->count <= 0)
{
- return false;
- }
- shared_ptr<ItemInstance> ingredient = items[INGREDIENT_SLOT];
- if (PotionBrewing::SIMPLIFIED_BREWING)
+ return false;
+ }
+ shared_ptr<ItemInstance> ingredient = items[INGREDIENT_SLOT];
+ if (PotionBrewing::SIMPLIFIED_BREWING)
{
- if (!Item::items[ingredient->id]->hasPotionBrewingFormula())
+ if (!Item::items[ingredient->id]->hasPotionBrewingFormula())
{
- return false;
- }
+ return false;
+ }
- bool oneResult = false;
- for (int dest = 0; dest < 3; dest++)
+ bool oneResult = false;
+ for (int dest = 0; dest < 3; dest++)
{
- if (items[dest] != NULL && items[dest]->id == Item::potion_Id)
+ if (items[dest] != NULL && items[dest]->id == Item::potion_Id)
{
- int currentBrew = items[dest]->getAuxValue();
- int newBrew = NORMALISE_POTION_AUXVAL( applyIngredient(currentBrew, ingredient) );
+ int currentBrew = items[dest]->getAuxValue();
+ int newBrew = NORMALISE_POTION_AUXVAL( applyIngredient(currentBrew, ingredient) );
- if (!PotionItem::isThrowable(currentBrew) && PotionItem::isThrowable(newBrew))
+ if (!PotionItem::isThrowable(currentBrew) && PotionItem::isThrowable(newBrew))
{
- oneResult = true;
- break;
- }
+ oneResult = true;
+ break;
+ }
- vector<MobEffectInstance *> *currentEffects = Item::potion->getMobEffects(currentBrew);
- vector<MobEffectInstance *> *newEffects = Item::potion->getMobEffects(newBrew);
+ vector<MobEffectInstance *> *currentEffects = Item::potion->getMobEffects(currentBrew);
+ vector<MobEffectInstance *> *newEffects = Item::potion->getMobEffects(newBrew);
// 4J - this code replaces an expression "currentEffects.equals(newEffects)" in the java.
// TODO - find out whether actually checking pointers to MobEffectInstance classes for equality
@@ -119,72 +140,72 @@ bool BrewingStandTileEntity::isBrewable()
}
}
- if ((currentBrew > 0 && currentEffects == newEffects) ||
+ if ((currentBrew > 0 && currentEffects == newEffects) ||
(currentEffects != NULL && (equals || newEffects == NULL)))
{
- }
+ }
else if (currentBrew != newBrew)
{
- oneResult = true;
- break;
- }
- }
- }
- return oneResult;
-
- }
+ oneResult = true;
+ break;
+ }
+ }
+ }
+ return oneResult;
+
+ }
else
{
- if (!Item::items[ingredient->id]->hasPotionBrewingFormula() && ingredient->id != Item::bucket_water_Id && ingredient->id != Item::netherStalkSeeds_Id)
+ if (!Item::items[ingredient->id]->hasPotionBrewingFormula() && ingredient->id != Item::bucket_water_Id && ingredient->id != Item::netherwart_seeds_Id)
{
- return false;
- }
- bool isWater = ingredient->id == Item::bucket_water_Id;
+ return false;
+ }
+ bool isWater = ingredient->id == Item::bucket_water_Id;
- // at least one destination potion must have a result
- bool oneResult = false;
- for (int dest = 0; dest < 3; dest++)
+ // at least one destination potion must have a result
+ bool oneResult = false;
+ for (int dest = 0; dest < 3; dest++)
{
- if (items[dest] != NULL && items[dest]->id == Item::potion_Id)
+ if (items[dest] != NULL && items[dest]->id == Item::potion_Id)
{
- int currentBrew = items[dest]->getAuxValue();
- int newBrew = NORMALISE_POTION_AUXVAL( applyIngredient(currentBrew, ingredient) );
- if (currentBrew != newBrew)
+ int currentBrew = items[dest]->getAuxValue();
+ int newBrew = NORMALISE_POTION_AUXVAL( applyIngredient(currentBrew, ingredient) );
+ if (currentBrew != newBrew)
{
- oneResult = true;
- break;
- }
- }
+ oneResult = true;
+ break;
+ }
+ }
else if (isWater && items[dest] != NULL && items[dest]->id == Item::glassBottle_Id)
{
- oneResult = true;
- break;
- }
- }
- return oneResult;
- }
+ oneResult = true;
+ break;
+ }
+ }
+ return oneResult;
+ }
}
void BrewingStandTileEntity::doBrew()
{
- if (!isBrewable())
+ if (!isBrewable())
{
- return;
- }
+ return;
+ }
- shared_ptr<ItemInstance> ingredient = items[INGREDIENT_SLOT];
+ shared_ptr<ItemInstance> ingredient = items[INGREDIENT_SLOT];
- if (PotionBrewing::SIMPLIFIED_BREWING)
+ if (PotionBrewing::SIMPLIFIED_BREWING)
{
- for (int dest = 0; dest < 3; dest++)
+ for (int dest = 0; dest < 3; dest++)
{
- if (items[dest] != NULL && items[dest]->id == Item::potion_Id)
+ if (items[dest] != NULL && items[dest]->id == Item::potion_Id)
{
- int currentBrew = items[dest]->getAuxValue();
- int newBrew = NORMALISE_POTION_AUXVAL( applyIngredient(currentBrew, ingredient) );
+ int currentBrew = items[dest]->getAuxValue();
+ int newBrew = NORMALISE_POTION_AUXVAL( applyIngredient(currentBrew, ingredient) );
- vector<MobEffectInstance *> *currentEffects = Item::potion->getMobEffects(currentBrew);
- vector<MobEffectInstance *> *newEffects = Item::potion->getMobEffects(newBrew);
+ vector<MobEffectInstance *> *currentEffects = Item::potion->getMobEffects(currentBrew);
+ vector<MobEffectInstance *> *newEffects = Item::potion->getMobEffects(newBrew);
// 4J - this code replaces an expression "currentEffects.equals(newEffects)" in the java.
// TODO - find out whether actually checking pointers to MobEffectInstance classes for equality
@@ -201,55 +222,55 @@ void BrewingStandTileEntity::doBrew()
}
}
- if ((currentBrew > 0 && currentEffects == newEffects) ||
+ if ((currentBrew > 0 && currentEffects == newEffects) ||
(currentEffects != NULL && (equals || newEffects == NULL)))
{
- if (!PotionItem::isThrowable(currentBrew) && PotionItem::isThrowable(newBrew))
+ if (!PotionItem::isThrowable(currentBrew) && PotionItem::isThrowable(newBrew))
{
- items[dest]->setAuxValue(newBrew);
- }
+ items[dest]->setAuxValue(newBrew);
+ }
- }
+ }
else if (currentBrew != newBrew)
{
- items[dest]->setAuxValue(newBrew);
- }
+ items[dest]->setAuxValue(newBrew);
+ }
- }
- }
+ }
+ }
- }
+ }
else
{
- bool isWater = ingredient->id == Item::bucket_water_Id;
+ bool isWater = ingredient->id == Item::bucket_water_Id;
- for (int dest = 0; dest < 3; dest++)
+ for (int dest = 0; dest < 3; dest++)
{
- if (items[dest] != NULL && items[dest]->id == Item::potion_Id)
+ if (items[dest] != NULL && items[dest]->id == Item::potion_Id)
{
- int currentBrew = items[dest]->getAuxValue();
- int newBrew = NORMALISE_POTION_AUXVAL( applyIngredient(currentBrew, ingredient) );
- items[dest]->setAuxValue(newBrew);
- }
+ int currentBrew = items[dest]->getAuxValue();
+ int newBrew = NORMALISE_POTION_AUXVAL( applyIngredient(currentBrew, ingredient) );
+ items[dest]->setAuxValue(newBrew);
+ }
else if (isWater && items[dest] != NULL && items[dest]->id == Item::glassBottle_Id)
{
- items[dest] = shared_ptr<ItemInstance>(new ItemInstance(Item::potion));
- }
- }
- }
+ items[dest] = shared_ptr<ItemInstance>(new ItemInstance(Item::potion));
+ }
+ }
+ }
- if (Item::items[ingredient->id]->hasCraftingRemainingItem())
+ if (Item::items[ingredient->id]->hasCraftingRemainingItem())
{
- items[INGREDIENT_SLOT] = shared_ptr<ItemInstance>(new ItemInstance(Item::items[ingredient->id]->getCraftingRemainingItem()));
- }
+ items[INGREDIENT_SLOT] = shared_ptr<ItemInstance>(new ItemInstance(Item::items[ingredient->id]->getCraftingRemainingItem()));
+ }
else
{
- items[INGREDIENT_SLOT]->count--;
- if (items[INGREDIENT_SLOT]->count <= 0)
+ items[INGREDIENT_SLOT]->count--;
+ if (items[INGREDIENT_SLOT]->count <= 0)
{
- items[INGREDIENT_SLOT] = nullptr;
- }
- }
+ items[INGREDIENT_SLOT] = nullptr;
+ }
+ }
}
int BrewingStandTileEntity::applyIngredient(int currentBrew, shared_ptr<ItemInstance> ingredient)
@@ -266,7 +287,7 @@ int BrewingStandTileEntity::applyIngredient(int currentBrew, shared_ptr<ItemInst
{
return PotionBrewing::applyBrew(currentBrew, PotionBrewing::MOD_WATER);
}
- if (ingredient->id == Item::netherStalkSeeds_Id)
+ if (ingredient->id == Item::netherwart_seeds_Id)
{
return PotionBrewing::stirr(currentBrew);
}
@@ -278,42 +299,44 @@ int BrewingStandTileEntity::applyIngredient(int currentBrew, shared_ptr<ItemInst
}
return currentBrew;
}
-
+
void BrewingStandTileEntity::load(CompoundTag *base)
{
- TileEntity::load(base);
+ TileEntity::load(base);
- ListTag<CompoundTag> *inventoryList = (ListTag<CompoundTag> *) base->getList(L"Items");
+ ListTag<CompoundTag> *inventoryList = (ListTag<CompoundTag> *) base->getList(L"Items");
delete [] items.data;
- items = ItemInstanceArray(getContainerSize());
- for (int i = 0; i < inventoryList->size(); i++)
+ items = ItemInstanceArray(getContainerSize());
+ for (int i = 0; i < inventoryList->size(); i++)
{
- CompoundTag *tag = inventoryList->get(i);
- int slot = tag->getByte(L"Slot");
- if (slot >= 0 && slot < items.length) items[slot] = ItemInstance::fromTag(tag);
- }
+ CompoundTag *tag = inventoryList->get(i);
+ int slot = tag->getByte(L"Slot");
+ if (slot >= 0 && slot < items.length) items[slot] = ItemInstance::fromTag(tag);
+ }
- brewTime = base->getShort(L"BrewTime");
+ brewTime = base->getShort(L"BrewTime");
+ if (base->contains(L"CustomName")) name = base->getString(L"CustomName");
}
void BrewingStandTileEntity::save(CompoundTag *base)
{
- TileEntity::save(base);
+ TileEntity::save(base);
- base->putShort(L"BrewTime", (short) (brewTime));
- ListTag<CompoundTag> *listTag = new ListTag<CompoundTag>();
+ base->putShort(L"BrewTime", (short) (brewTime));
+ ListTag<CompoundTag> *listTag = new ListTag<CompoundTag>();
- for (int i = 0; i < items.length; i++)
+ for (int i = 0; i < items.length; i++)
{
- if (items[i] != NULL)
+ if (items[i] != NULL)
{
- CompoundTag *tag = new CompoundTag();
- tag->putByte(L"Slot", (byte) i);
- items[i]->save(tag);
- listTag->add(tag);
- }
- }
- base->put(L"Items", listTag);
+ CompoundTag *tag = new CompoundTag();
+ tag->putByte(L"Slot", (byte) i);
+ items[i]->save(tag);
+ listTag->add(tag);
+ }
+ }
+ base->put(L"Items", listTag);
+ if (hasCustomName()) base->putString(L"CustomName", name);
}
shared_ptr<ItemInstance> BrewingStandTileEntity::getItem(unsigned int slot)
@@ -354,7 +377,7 @@ shared_ptr<ItemInstance> BrewingStandTileEntity::removeItem(unsigned int slot, i
}
return nullptr;
}
-
+
shared_ptr<ItemInstance> BrewingStandTileEntity::removeItemNoUpdate(int slot)
{
if (slot >= 0 && slot < items.length)
@@ -368,22 +391,23 @@ shared_ptr<ItemInstance> BrewingStandTileEntity::removeItemNoUpdate(int slot)
void BrewingStandTileEntity::setItem(unsigned int slot, shared_ptr<ItemInstance> item)
{
- if (slot >= 0 && slot < items.length)
+ if (slot >= 0 && slot < items.length)
{
- items[slot] = item;
- }
+ items[slot] = item;
+ }
}
int BrewingStandTileEntity::getMaxStackSize()
{
- return 1;
+ // this value is not used for the potion slots
+ return 64;
}
bool BrewingStandTileEntity::stillValid(shared_ptr<Player> player)
{
- if (level->getTileEntity(x, y, z) != shared_from_this()) return false;
- if (player->distanceToSqr(x + 0.5, y + 0.5, z + 0.5) > 8 * 8) return false;
- return true;
+ if (level->getTileEntity(x, y, z) != shared_from_this()) return false;
+ if (player->distanceToSqr(x + 0.5, y + 0.5, z + 0.5) > 8 * 8) return false;
+ return true;
}
void BrewingStandTileEntity::startOpen()
@@ -394,22 +418,59 @@ void BrewingStandTileEntity::stopOpen()
{
}
+bool BrewingStandTileEntity::canPlaceItem(int slot, shared_ptr<ItemInstance> item)
+{
+ if (slot == INGREDIENT_SLOT)
+ {
+ if (PotionBrewing::SIMPLIFIED_BREWING)
+ {
+ return Item::items[item->id]->hasPotionBrewingFormula();
+ }
+ else
+ {
+ return Item::items[item->id]->hasPotionBrewingFormula() || item->id == Item::netherwart_seeds_Id || item->id == Item::bucket_water_Id;
+ }
+ }
+
+ return item->id == Item::potion_Id || item->id == Item::glassBottle_Id;
+}
+
void BrewingStandTileEntity::setBrewTime(int value)
{
- this->brewTime = value;
+ brewTime = value;
}
int BrewingStandTileEntity::getPotionBits()
{
- int newCount = 0;
- for (int potion = 0; potion < 3; potion++)
+ int newCount = 0;
+ for (int potion = 0; potion < 3; potion++)
{
- if (items[potion] != NULL)
+ if (items[potion] != NULL)
{
- newCount |= (1 << potion);
- }
- }
- return newCount;
+ newCount |= (1 << potion);
+ }
+ }
+ return newCount;
+}
+
+intArray BrewingStandTileEntity::getSlotsForFace(int face)
+{
+ if (face == Facing::UP)
+ {
+ return SLOTS_FOR_UP;
+ }
+
+ return SLOTS_FOR_OTHER_FACES;
+}
+
+bool BrewingStandTileEntity::canPlaceItemThroughFace(int slot, shared_ptr<ItemInstance> item, int face)
+{
+ return canPlaceItem(slot, item);
+}
+
+bool BrewingStandTileEntity::canTakeItemThroughFace(int slot, shared_ptr<ItemInstance> item, int face)
+{
+ return true;
}
// 4J Added
@@ -419,8 +480,8 @@ shared_ptr<TileEntity> BrewingStandTileEntity::clone()
TileEntity::clone(result);
result->brewTime = brewTime;
- result->lastPotionCount = lastPotionCount;
- result->ingredientId = ingredientId;
+ result->lastPotionCount = lastPotionCount;
+ result->ingredientId = ingredientId;
for (unsigned int i = 0; i < items.length; i++)
{