#include "../Platform/stdafx.h" #include "../Headers/net.minecraft.stats.h" #include "../Headers/net.minecraft.world.entity.player.h" #include "../Headers/net.minecraft.world.entity.h" #include "../Headers/net.minecraft.world.item.crafting.h" #include "../Headers/net.minecraft.world.level.h" #include "../Headers/net.minecraft.world.item.h" #include "../Util/JavaMath.h" #include "FurnaceResultSlot.h" FurnaceResultSlot::FurnaceResultSlot(std::shared_ptr player, std::shared_ptr container, int slot, int x, int y) : Slot(container, slot, x, y) { this->player = player; removeCount = 0; } bool FurnaceResultSlot::mayPlace(std::shared_ptr item) { return false; } std::shared_ptr FurnaceResultSlot::remove(int c) { if (hasItem()) { removeCount += std::min(c, getItem()->count); } return Slot::remove(c); } void FurnaceResultSlot::onTake(std::shared_ptr player, std::shared_ptr carried) { checkTakeAchievements(carried); Slot::onTake(player, carried); } void FurnaceResultSlot::onQuickCraft(std::shared_ptr picked, int count) { removeCount += count; checkTakeAchievements(picked); } bool FurnaceResultSlot::mayCombine(std::shared_ptr second) { return false; } void FurnaceResultSlot::checkTakeAchievements( std::shared_ptr carried) { carried->onCraftedBy(player->level, player, removeCount); // spawn xp right on top of the player if (!player->level->isClientSide) { int amount = removeCount; float value = FurnaceRecipes::getInstance()->getRecipeValue(carried->id); if (value == 0) { amount = 0; } else if (value < 1) { int baseValue = floor((float)amount * value); if (baseValue < ceil((float)amount * value) && (float)Math::random() < (((float)amount * value) - baseValue)) { baseValue++; } amount = baseValue; } while (amount > 0) { int newCount = ExperienceOrb::getExperienceValue(amount); amount -= newCount; player->level->addEntity(std::shared_ptr( new ExperienceOrb(player->level, player->x, player->y + .5, player->z + .5, newCount))); } } #ifdef _DURANGO if (!player->level->isClientSide && removeCount > 0) { player->awardStat( GenericStats::itemsSmelted(carried->id), GenericStats::param_itemsSmelted( carried->id, carried->getAuxValue(), removeCount)); } #else if (carried->id == Item::ironIngot_Id) player->awardStat(GenericStats::acquireIron(), GenericStats::param_acquireIron()); if (carried->id == Item::fish_cooked_Id) player->awardStat(GenericStats::cookFish(), GenericStats::param_cookFish()); #endif removeCount = 0; }