40
40
class ItemCombineRecipe implements AnvilRecipe{
41
41
public function __construct (
42
42
private RecipeIngredient $ input ,
43
- private RecipeIngredient $ material ,
44
- private Item $ result
43
+ private RecipeIngredient $ material
45
44
){ }
46
45
47
46
public function getInput () : RecipeIngredient {
@@ -52,22 +51,14 @@ public function getMaterial() : RecipeIngredient{
52
51
return $ this ->material ;
53
52
}
54
53
55
- public function getResult () : Item {
56
- return clone $ this ->result ;
57
- }
58
-
59
- public function getXpCost () : int {
60
- return 2 ;
61
- }
62
-
63
54
public function getResultFor (Item $ input , Item $ material ) : ?AnvilCraftResult {
64
- if ($ input -> equals ( $ this ->input ->getItem ()) && $ material -> equals ( $ this ->material ->getItem () )){
65
- $ result = $ this -> getResult ( );
55
+ if ($ this ->input ->accepts ( $ input ) && $ this ->material ->accepts ( $ material )){
56
+ $ result = ( clone $ input );
66
57
$ xpCost = 0 ;
67
- if ($ input instanceof Durable && $ material instanceof Durable){
68
- $ damage = $ input ->getDamage ();
58
+ if ($ result instanceof Durable && $ material instanceof Durable){
59
+ $ damage = $ result ->getDamage ();
69
60
if ($ damage !== 0 ){
70
- $ baseMaxDurability = $ input ->getMaxDurability ();
61
+ $ baseMaxDurability = $ result ->getMaxDurability ();
71
62
$ baseDurability = $ baseMaxDurability - $ damage ;
72
63
$ materialDurability = $ material ->getMaxDurability () - $ material ->getDamage ();
73
64
$ addDurability = (int ) ($ baseMaxDurability * 12 / 100 );
@@ -78,11 +69,6 @@ public function getResultFor(Item $input, Item $material) : ?AnvilCraftResult{
78
69
$ xpCost = 2 ;
79
70
}
80
71
81
- // setting base enchantments to result
82
- foreach ($ input ->getEnchantments () as $ enchantment ){
83
- $ result ->addEnchantment ($ enchantment );
84
- }
85
-
86
72
// combining enchantments
87
73
foreach ($ material ->getEnchantments () as $ instance ){
88
74
$ enchantment = $ instance ->getType ();
@@ -131,7 +117,7 @@ public function getResultFor(Item $input, Item $material) : ?AnvilCraftResult{
131
117
);
132
118
}
133
119
134
- return new AnvilCraftResult ($ xpCost , $ result );
120
+ return new AnvilCraftResult ($ xpCost , $ result, null );
135
121
}
136
122
137
123
return null ;
0 commit comments