the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 94 lines 2.5 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.stats.h" 3#include "net.minecraft.world.entity.player.h" 4#include "net.minecraft.world.entity.h" 5#include "net.minecraft.world.item.crafting.h" 6#include "net.minecraft.world.level.h" 7#include "net.minecraft.world.item.h" 8#include "JavaMath.h" 9#include "FurnaceResultSlot.h" 10 11 12FurnaceResultSlot::FurnaceResultSlot(shared_ptr<Player> player, shared_ptr<Container> container, int slot, int x, int y) : Slot( container, slot, x, y ) 13{ 14 this->player = player; 15 removeCount = 0; 16} 17 18bool FurnaceResultSlot::mayPlace(shared_ptr<ItemInstance> item) 19{ 20 return false; 21} 22 23shared_ptr<ItemInstance> FurnaceResultSlot::remove(int c) 24{ 25 if (hasItem()) 26 { 27 removeCount += min(c, getItem()->count); 28 } 29 return Slot::remove(c); 30} 31 32void FurnaceResultSlot::onTake(shared_ptr<Player> player, shared_ptr<ItemInstance> carried) 33{ 34 checkTakeAchievements(carried); 35 Slot::onTake(player, carried); 36} 37 38void FurnaceResultSlot::onQuickCraft(shared_ptr<ItemInstance> picked, int count) 39{ 40 removeCount += count; 41 checkTakeAchievements(picked); 42} 43 44bool FurnaceResultSlot::mayCombine(shared_ptr<ItemInstance> second) 45{ 46 return false; 47} 48 49void FurnaceResultSlot::checkTakeAchievements(shared_ptr<ItemInstance> carried) 50{ 51 carried->onCraftedBy(player->level, player, removeCount); 52 // spawn xp right on top of the player 53 if (!player->level->isClientSide) 54 { 55 int amount = removeCount; 56 float value = FurnaceRecipes::getInstance()->getRecipeValue(carried->id); 57 58 if (value == 0) 59 { 60 amount = 0; 61 } 62 else if (value < 1) 63 { 64 int baseValue = floor((float) amount * value); 65 if (baseValue < ceil((float) amount * value) && (float) Math::random() < (((float) amount * value) - baseValue)) 66 { 67 baseValue++; 68 } 69 amount = baseValue; 70 } 71 72 while (amount > 0) 73 { 74 int newCount = ExperienceOrb::getExperienceValue(amount); 75 amount -= newCount; 76 player->level->addEntity(shared_ptr<ExperienceOrb>( new ExperienceOrb(player->level, player->x, player->y + .5, player->z + .5, newCount) )); 77 } 78 } 79 80#ifdef _DURANGO 81 if (!player->level->isClientSide && removeCount > 0) 82 { 83 player->awardStat( 84 GenericStats::itemsSmelted(carried->id), 85 GenericStats::param_itemsSmelted(carried->id, carried->getAuxValue(), removeCount) 86 ); 87 } 88#else 89 if (carried->id == Item::ironIngot_Id) player->awardStat(GenericStats::acquireIron(), GenericStats::param_acquireIron()); 90 if (carried->id == Item::fish_cooked_Id) player->awardStat(GenericStats::cookFish(), GenericStats::param_cookFish()); 91#endif 92 93 removeCount = 0; 94}