mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-24 10:53:41 +00:00
# Conflicts: # Minecraft.Client/Network/PlayerChunkMap.cpp # Minecraft.Client/Network/PlayerList.cpp # Minecraft.Client/Network/ServerChunkCache.cpp # Minecraft.Client/Platform/Common/Consoles_App.cpp # Minecraft.Client/Platform/Common/DLC/DLCManager.cpp # Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp # Minecraft.Client/Platform/Common/GameRules/LevelRuleset.cpp # Minecraft.Client/Platform/Common/Tutorial/Tutorial.cpp # Minecraft.Client/Platform/Common/Tutorial/TutorialTask.cpp # Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.cpp # Minecraft.Client/Platform/Common/UI/UIComponent_Panorama.cpp # Minecraft.Client/Platform/Common/UI/UIController.cpp # Minecraft.Client/Platform/Common/UI/UIController.h # Minecraft.Client/Platform/Extrax64Stubs.cpp # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Input.h # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Storage.h # Minecraft.Client/Player/EntityTracker.cpp # Minecraft.Client/Player/ServerPlayer.cpp # Minecraft.Client/Rendering/EntityRenderers/PlayerRenderer.cpp # Minecraft.Client/Textures/Packs/DLCTexturePack.cpp # Minecraft.Client/Textures/Stitching/StitchedTexture.cpp # Minecraft.Client/Textures/Stitching/TextureMap.cpp # Minecraft.Client/Textures/Textures.cpp # Minecraft.World/Blocks/NotGateTile.cpp # Minecraft.World/Blocks/PressurePlateTile.cpp # Minecraft.World/Blocks/TileEntities/PotionBrewing.cpp # Minecraft.World/Enchantments/EnchantmentHelper.cpp # Minecraft.World/Entities/HangingEntity.cpp # Minecraft.World/Entities/LeashFenceKnotEntity.cpp # Minecraft.World/Entities/LivingEntity.cpp # Minecraft.World/Entities/Mobs/Boat.cpp # Minecraft.World/Entities/Mobs/Minecart.cpp # Minecraft.World/Entities/Mobs/Witch.cpp # Minecraft.World/Entities/SyncedEntityData.cpp # Minecraft.World/Items/LeashItem.cpp # Minecraft.World/Items/PotionItem.cpp # Minecraft.World/Level/BaseMobSpawner.cpp # Minecraft.World/Level/CustomLevelSource.cpp # Minecraft.World/Level/Level.cpp # Minecraft.World/Level/Storage/DirectoryLevelStorage.cpp # Minecraft.World/Level/Storage/McRegionLevelStorage.cpp # Minecraft.World/Level/Storage/RegionFileCache.cpp # Minecraft.World/Player/Player.cpp # Minecraft.World/WorldGen/Biomes/BiomeCache.cpp # Minecraft.World/WorldGen/Features/RandomScatteredLargeFeature.cpp # Minecraft.World/WorldGen/Layers/BiomeOverrideLayer.cpp
222 lines
8.4 KiB
C++
222 lines
8.4 KiB
C++
#include "../Platform/stdafx.h"
|
|
#include "../Headers/net.minecraft.world.entity.player.h"
|
|
#include "../Headers/net.minecraft.world.level.tile.entity.h"
|
|
#include "../Headers/net.minecraft.world.item.h"
|
|
#include "../Headers/net.minecraft.world.item.alchemy.h"
|
|
#include "../Headers/net.minecraft.stats.h"
|
|
#include "BrewingStandMenu.h"
|
|
|
|
BrewingStandMenu::BrewingStandMenu(
|
|
std::shared_ptr<Inventory> inventory,
|
|
std::shared_ptr<BrewingStandTileEntity> brewingStand) {
|
|
tc = 0;
|
|
|
|
this->brewingStand = brewingStand;
|
|
|
|
addSlot(new PotionSlot(std::dynamic_pointer_cast<Player>(
|
|
inventory->player->shared_from_this()),
|
|
brewingStand, 0, 56, 46));
|
|
addSlot(new PotionSlot(std::dynamic_pointer_cast<Player>(
|
|
inventory->player->shared_from_this()),
|
|
brewingStand, 1, 79, 53));
|
|
addSlot(new PotionSlot(std::dynamic_pointer_cast<Player>(
|
|
inventory->player->shared_from_this()),
|
|
brewingStand, 2, 102, 46));
|
|
ingredientSlot = addSlot(new IngredientsSlot(brewingStand, 3, 79, 17));
|
|
|
|
for (int y = 0; y < 3; y++) {
|
|
for (int x = 0; x < 9; x++) {
|
|
addSlot(
|
|
new Slot(inventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
|
|
}
|
|
}
|
|
for (int x = 0; x < 9; x++) {
|
|
addSlot(new Slot(inventory, x, 8 + x * 18, 142));
|
|
}
|
|
}
|
|
|
|
void BrewingStandMenu::addSlotListener(ContainerListener* listener) {
|
|
AbstractContainerMenu::addSlotListener(listener);
|
|
listener->setContainerData(this, 0, brewingStand->getBrewTime());
|
|
}
|
|
|
|
void BrewingStandMenu::broadcastChanges() {
|
|
AbstractContainerMenu::broadcastChanges();
|
|
|
|
// for (int i = 0; i < containerListeners->size(); i++)
|
|
for (auto it = containerListeners.begin();
|
|
it != containerListeners.end(); ++it) {
|
|
ContainerListener* listener = *it; // containerListeners.at(i);
|
|
if (tc != brewingStand->getBrewTime()) {
|
|
listener->setContainerData(this, 0, brewingStand->getBrewTime());
|
|
}
|
|
}
|
|
tc = brewingStand->getBrewTime();
|
|
}
|
|
|
|
void BrewingStandMenu::setData(int id, int value) {
|
|
if (id == 0) brewingStand->setBrewTime(value);
|
|
}
|
|
|
|
bool BrewingStandMenu::stillValid(std::shared_ptr<Player> player) {
|
|
return brewingStand->stillValid(player);
|
|
}
|
|
|
|
std::shared_ptr<ItemInstance> BrewingStandMenu::quickMoveStack(
|
|
std::shared_ptr<Player> player, int slotIndex) {
|
|
std::shared_ptr<ItemInstance> clicked = nullptr;
|
|
Slot* slot = slots.at(slotIndex);
|
|
Slot* IngredientSlot = slots.at(INGREDIENT_SLOT);
|
|
Slot* PotionSlot1 = slots.at(BOTTLE_SLOT_START);
|
|
Slot* PotionSlot2 = slots.at(BOTTLE_SLOT_START + 1);
|
|
Slot* PotionSlot3 = slots.at(BOTTLE_SLOT_START + 2);
|
|
|
|
if (slot != nullptr && slot->hasItem()) {
|
|
std::shared_ptr<ItemInstance> stack = slot->getItem();
|
|
clicked = stack->copy();
|
|
|
|
if ((slotIndex >= BOTTLE_SLOT_START && slotIndex <= BOTTLE_SLOT_END) ||
|
|
(slotIndex == INGREDIENT_SLOT)) {
|
|
if (!moveItemStackTo(stack, INV_SLOT_START, USE_ROW_SLOT_END,
|
|
true)) {
|
|
return nullptr;
|
|
}
|
|
slot->onQuickCraft(stack, clicked);
|
|
} else if (!ingredientSlot->hasItem() &&
|
|
ingredientSlot->mayPlace(stack)) {
|
|
if (!moveItemStackTo(stack, INGREDIENT_SLOT, INGREDIENT_SLOT + 1,
|
|
false)) {
|
|
return nullptr;
|
|
}
|
|
} else if (PotionSlot::mayPlaceItem(clicked)) {
|
|
if (!moveItemStackTo(stack, BOTTLE_SLOT_START, BOTTLE_SLOT_END + 1,
|
|
false)) {
|
|
return nullptr;
|
|
}
|
|
} else if (slotIndex >= INV_SLOT_START && slotIndex < INV_SLOT_END) {
|
|
// 4J-PB - if the item is an ingredient, quickmove it into the
|
|
// ingredient slot
|
|
if ((Item::items[stack->id]->hasPotionBrewingFormula() ||
|
|
(stack->id == Item::netherwart_seeds_Id)) &&
|
|
(!IngredientSlot->hasItem() ||
|
|
(stack->id == IngredientSlot->getItem()->id))) {
|
|
if (!moveItemStackTo(stack, INGREDIENT_SLOT,
|
|
INGREDIENT_SLOT + 1, false)) {
|
|
return nullptr;
|
|
}
|
|
}
|
|
// potion?
|
|
else if ((stack->id == Item::potion_Id) &&
|
|
(!PotionSlot1->hasItem() || !PotionSlot2->hasItem() ||
|
|
!PotionSlot3->hasItem())) {
|
|
if (!moveItemStackTo(stack, BOTTLE_SLOT_START,
|
|
BOTTLE_SLOT_END + 1, false)) {
|
|
return nullptr;
|
|
}
|
|
} else if (!moveItemStackTo(stack, USE_ROW_SLOT_START,
|
|
USE_ROW_SLOT_END, false)) {
|
|
return nullptr;
|
|
}
|
|
} else if (slotIndex >= USE_ROW_SLOT_START &&
|
|
slotIndex < USE_ROW_SLOT_END) {
|
|
// 4J-PB - if the item is an ingredient, quickmove it into the
|
|
// ingredient slot
|
|
if ((Item::items[stack->id]->hasPotionBrewingFormula() ||
|
|
(stack->id == Item::netherwart_seeds_Id)) &&
|
|
(!IngredientSlot->hasItem() ||
|
|
(stack->id == IngredientSlot->getItem()->id))) {
|
|
if (!moveItemStackTo(stack, INGREDIENT_SLOT,
|
|
INGREDIENT_SLOT + 1, false)) {
|
|
return nullptr;
|
|
}
|
|
}
|
|
// potion?
|
|
else if ((stack->id == Item::potion_Id) &&
|
|
(!PotionSlot1->hasItem() || !PotionSlot2->hasItem() ||
|
|
!PotionSlot3->hasItem())) {
|
|
if (!moveItemStackTo(stack, BOTTLE_SLOT_START,
|
|
BOTTLE_SLOT_END + 1, false)) {
|
|
return nullptr;
|
|
}
|
|
} else if (!moveItemStackTo(stack, INV_SLOT_START, INV_SLOT_END,
|
|
false)) {
|
|
return nullptr;
|
|
}
|
|
} else {
|
|
if (!moveItemStackTo(stack, INV_SLOT_START, USE_ROW_SLOT_END,
|
|
false)) {
|
|
return nullptr;
|
|
}
|
|
}
|
|
if (stack->count == 0) {
|
|
slot->set(nullptr);
|
|
} else {
|
|
slot->setChanged();
|
|
}
|
|
if (stack->count == clicked->count) {
|
|
return nullptr;
|
|
} else {
|
|
slot->onTake(player, stack);
|
|
}
|
|
}
|
|
return clicked;
|
|
}
|
|
|
|
BrewingStandMenu::PotionSlot::PotionSlot(std::shared_ptr<Player> player,
|
|
std::shared_ptr<Container> container,
|
|
int slot, int x, int y)
|
|
: Slot(container, slot, x, y) {
|
|
this->player = player;
|
|
}
|
|
|
|
bool BrewingStandMenu::PotionSlot::mayPlace(
|
|
std::shared_ptr<ItemInstance> item) {
|
|
return mayPlaceItem(item);
|
|
}
|
|
|
|
int BrewingStandMenu::PotionSlot::getMaxStackSize() { return 1; }
|
|
|
|
void BrewingStandMenu::PotionSlot::onTake(
|
|
std::shared_ptr<Player> player, std::shared_ptr<ItemInstance> carried) {
|
|
if (carried->id == Item::potion_Id && carried->getAuxValue() > 0)
|
|
this->player->awardStat(GenericStats::potion(),
|
|
GenericStats::param_potion());
|
|
Slot::onTake(player, carried);
|
|
}
|
|
|
|
bool BrewingStandMenu::PotionSlot::mayCombine(
|
|
std::shared_ptr<ItemInstance> second) {
|
|
return false;
|
|
}
|
|
|
|
bool BrewingStandMenu::PotionSlot::mayPlaceItem(
|
|
std::shared_ptr<ItemInstance> item) {
|
|
return item != nullptr &&
|
|
(item->id == Item::potion_Id || item->id == Item::glassBottle_Id);
|
|
}
|
|
|
|
BrewingStandMenu::IngredientsSlot::IngredientsSlot(
|
|
std::shared_ptr<Container> container, int slot, int x, int y)
|
|
: Slot(container, slot, x, y) {}
|
|
|
|
bool BrewingStandMenu::IngredientsSlot::mayPlace(
|
|
std::shared_ptr<ItemInstance> item) {
|
|
if (item != nullptr) {
|
|
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 false;
|
|
}
|
|
|
|
bool BrewingStandMenu::IngredientsSlot::mayCombine(
|
|
std::shared_ptr<ItemInstance> second) {
|
|
return false;
|
|
}
|
|
|
|
int BrewingStandMenu::IngredientsSlot::getMaxStackSize() { return 64; }
|