1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#include "stdafx.h"
#include "net.minecraft.stats.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.item.crafting.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.item.h"
#include "JavaMath.h"
#include "FurnaceResultSlot.h"
FurnaceResultSlot::FurnaceResultSlot(shared_ptr<Player> player, shared_ptr<Container> container, int slot, int x, int y) : Slot( container, slot, x, y )
{
this->player = player;
removeCount = 0;
}
bool FurnaceResultSlot::mayPlace(shared_ptr<ItemInstance> item)
{
return false;
}
shared_ptr<ItemInstance> FurnaceResultSlot::remove(int c)
{
if (hasItem())
{
removeCount += min(c, getItem()->count);
}
return Slot::remove(c);
}
void FurnaceResultSlot::onTake(shared_ptr<Player> player, shared_ptr<ItemInstance> carried)
{
checkTakeAchievements(carried);
Slot::onTake(player, carried);
}
void FurnaceResultSlot::onQuickCraft(shared_ptr<ItemInstance> picked, int count)
{
removeCount += count;
checkTakeAchievements(picked);
}
bool FurnaceResultSlot::mayCombine(shared_ptr<ItemInstance> second)
{
return false;
}
void FurnaceResultSlot::checkTakeAchievements(shared_ptr<ItemInstance> 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(shared_ptr<ExperienceOrb>( 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;
}
|