From b691c43c44ff180d10e7d4a9afc83b98551ff586 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 12:16:08 +0800 Subject: Initial commit --- Minecraft.World/Slot.cpp | 163 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 Minecraft.World/Slot.cpp (limited to 'Minecraft.World/Slot.cpp') diff --git a/Minecraft.World/Slot.cpp b/Minecraft.World/Slot.cpp new file mode 100644 index 00000000..30fd9125 --- /dev/null +++ b/Minecraft.World/Slot.cpp @@ -0,0 +1,163 @@ +#include "stdafx.h" + +#include "Container.h" +#include "net.minecraft.world.item.h" +#include "net.minecraft.world.item.crafting.h" +#include "Slot.h" + +Slot::Slot(shared_ptr container, int slot, int x, int y) : container( container ), slot( slot ) +{ + this->x = x; + this->y = y; + + this->index = 0; +} + +void Slot::onQuickCraft(shared_ptr picked, shared_ptr original) +{ + if (picked == NULL || original == NULL) + { + return; + } + if (picked->id != original->id) + { + return; + } + int count = original->count - picked->count; + if (count > 0) + { + onQuickCraft(picked, count); + } +} + + +void Slot::onQuickCraft(shared_ptr picked, int count) +{ +} + +void Slot::checkTakeAchievements(shared_ptr picked) +{ +} + +void Slot::swap(Slot *other) +{ + shared_ptr item1 = container->getItem(slot); + shared_ptr item2 = other->container->getItem(other->slot); + + if (item1 != NULL && item1->count > other->getMaxStackSize()) + { + if (item2 != NULL) return; + item2 = item1->remove(item1->count - other->getMaxStackSize()); + } + if (item2 != NULL && item2->count > getMaxStackSize()) + { + if (item1 != NULL) return; + item1 = item2->remove(item2->count - getMaxStackSize()); + } + other->container->setItem(other->slot, item1); + + container->setItem(slot, item2); + setChanged(); +} + +void Slot::onTake(shared_ptr player, shared_ptr carried) +{ + setChanged(); +} + +bool Slot::mayPlace(shared_ptr item) +{ + return true; +} + +shared_ptr Slot::getItem() +{ + return container->getItem(slot); +} + +bool Slot::hasItem() +{ + return getItem() != NULL; +} + +void Slot::set(shared_ptr item) +{ + container->setItem(slot, item); + setChanged(); +} + +void Slot::setChanged() +{ + container->setChanged(); +} + +int Slot::getMaxStackSize() +{ + return container->getMaxStackSize(); +} + +Icon *Slot::getNoItemIcon() +{ + return NULL; +} + +shared_ptr Slot::remove(int c) +{ + return container->removeItem(slot, c); +} + +bool Slot::isAt(shared_ptr c, int s) +{ + return c == container && s == slot; +} + +bool Slot::mayPickup(shared_ptr player) +{ + return true; +} + +bool Slot::mayCombine(shared_ptr second) +{ + shared_ptr first = getItem(); + + if(first == NULL || second == NULL) return false; + + ArmorItem *thisItem = dynamic_cast(first->getItem()); + if(thisItem) + { + bool thisIsDyableArmor = thisItem->getMaterial() == ArmorItem::ArmorMaterial::CLOTH; + bool itemIsDye = second->id == Item::dye_powder_Id; + return thisIsDyableArmor && itemIsDye; + } + // 4J Stu - This condition taken from Recipes::getItemFor to repair items, but added the damaged check to skip when the result is pointless + else if (first != NULL && second != NULL && first->id == second->id && first->count == 1 && second->count == 1 && Item::items[first->id]->canBeDepleted() && (first->isDamaged() || second->isDamaged()) ) + { + // 4J Stu - Don't allow combinining enchanted items, the enchantment will be lost. They can use the anvil for this + return !first->isEnchanted() && !second->isEnchanted(); + } + return false; +} + +shared_ptr Slot::combine(shared_ptr item) +{ + shared_ptr result = nullptr; + shared_ptr first = getItem(); + + shared_ptr craftSlots = shared_ptr( new CraftingContainer(NULL, 2, 2) ); + craftSlots->setItem(0, item); + craftSlots->setItem(1, first); + + ArmorItem *thisItem = dynamic_cast(first->getItem()); + if(thisItem) + { + result = ArmorDyeRecipe::assembleDyedArmor(craftSlots); + } + else + { + result = Recipes::getInstance()->getItemFor(craftSlots, NULL); + } + + craftSlots->setItem(0, nullptr); + craftSlots->setItem(1, nullptr); + return result; +} -- cgit v1.2.3