the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "Container.h"
3#include "net.minecraft.stats.h"
4#include "net.minecraft.world.entity.player.h"
5#include "net.minecraft.world.item.h"
6#include "net.minecraft.world.level.tile.h"
7#include "ResultSlot.h"
8
9ResultSlot::ResultSlot(Player *player, shared_ptr<Container> craftSlots, shared_ptr<Container> container, int id, int x, int y) : Slot( container, id, x, y )
10{
11 this->player = player;
12 this->craftSlots = craftSlots;
13 removeCount = 0;
14}
15
16bool ResultSlot::mayPlace(shared_ptr<ItemInstance> item)
17{
18 return false;
19}
20
21shared_ptr<ItemInstance> ResultSlot::remove(int c)
22{
23 if (hasItem())
24 {
25 removeCount += min(c, getItem()->count);
26 }
27 return Slot::remove(c);
28}
29
30void ResultSlot::onQuickCraft(shared_ptr<ItemInstance> picked, int count)
31{
32 removeCount += count;
33 checkTakeAchievements(picked);
34}
35
36void ResultSlot::checkTakeAchievements(shared_ptr<ItemInstance> carried)
37{
38 carried->onCraftedBy(player->level, dynamic_pointer_cast<Player>( player->shared_from_this() ), removeCount);
39 removeCount = 0;
40
41 if (carried->id == Tile::workBench_Id) player->awardStat(GenericStats::buildWorkbench(), GenericStats::param_buildWorkbench());
42 else if (carried->id == Item::pickAxe_wood_Id) player->awardStat(GenericStats::buildPickaxe(), GenericStats::param_buildPickaxe());
43 else if (carried->id == Tile::furnace_Id) player->awardStat(GenericStats::buildFurnace(), GenericStats::param_buildFurnace());
44 else if (carried->id == Item::hoe_wood_Id) player->awardStat(GenericStats::buildHoe(), GenericStats::param_buildHoe());
45 else if (carried->id == Item::bread_Id) player->awardStat(GenericStats::makeBread(), GenericStats::param_makeBread());
46 else if (carried->id == Item::cake_Id) player->awardStat(GenericStats::bakeCake(), GenericStats::param_bakeCake());
47 else if (carried->id == Item::pickAxe_stone_Id) player->awardStat(GenericStats::buildBetterPickaxe(), GenericStats::param_buildBetterPickaxe());
48 else if (carried->id == Item::sword_wood_Id) player->awardStat(GenericStats::buildSword(), GenericStats::param_buildSword());
49 //else if (carried->id == Tile::enchantTable_Id) player->awardStat(GenericStats::enchantments(), GenericStats::param_achievement(eAward_));
50 else if (carried->id == Tile::bookshelf_Id) player->awardStat(GenericStats::bookcase(), GenericStats::param_bookcase());
51
52 // 4J : WESTY : Added new acheivements.
53 else if (carried->id == Tile::dispenser_Id) player->awardStat(GenericStats::dispenseWithThis(), GenericStats::param_dispenseWithThis());
54}
55
56void ResultSlot::onTake(shared_ptr<Player> player, shared_ptr<ItemInstance> carried)
57{
58 checkTakeAchievements(carried);
59
60 for (unsigned int i = 0; i < craftSlots->getContainerSize(); i++)
61 {
62 shared_ptr<ItemInstance> item = craftSlots->getItem(i);
63 if (item != NULL)
64 {
65 craftSlots->removeItem(i, 1);
66
67 if (item->getItem()->hasCraftingRemainingItem())
68 {
69 shared_ptr<ItemInstance> craftResult = shared_ptr<ItemInstance>(new ItemInstance(item->getItem()->getCraftingRemainingItem()));
70
71 /*
72 * Try to place this in the player's inventory (See we.java for new method)
73 */
74 if (item->getItem()->shouldMoveCraftingResultToInventory(item) && player->inventory->add(craftResult))
75 {
76 continue;
77 }
78
79 // If this slot is now empty, place it there (current behavior)
80 if (craftSlots->getItem(i) == NULL)
81 {
82 craftSlots->setItem(i, craftResult);
83 }
84 else
85 {
86 // Finally, if nothing else, just drop the item
87 player->drop(craftResult);
88 }
89 }
90
91 }
92 }
93}
94
95bool ResultSlot::mayCombine(shared_ptr<ItemInstance> second)
96{
97 return false;
98}