-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfire_aspect_smelting.sc
138 lines (132 loc) · 3.33 KB
/
fire_aspect_smelting.sc
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
__config() -> {
'stay_loaded' -> true,
};
get_smelt_result(item) -> (
for(item_list(),
recipe = recipe_data(_, 'smelting');
if(recipe != null,
for(recipe,
if(_:1:0:0:0 == item,return(_:0:0););
);
);
);
return(null);
);
triangulate_drop(low, high, mode) -> (
// Generate a random value between 0 and 1
rand = rand(1);
// Calculate the width of the distribution
width = high - low;
// If mode is provided and lies within the range, adjust the width
if(low <= mode <= high,
if(rand < (mode - low) / width,(
return(round(low + (width * rand) ^ 0.5));
), //else
return(round(high - (width * (1 - rand)) ^ 0.5));
);
);
// Otherwise, use a linear interpolation
return(round(low + rand * (high - low)));
);
global_fortune_chances = {
'deepslate_iron_ore'->{
'min'-> 1,
0-> [1,1],
1-> [2,1.33],
2-> [3,1.75],
3-> [4,2.2],
},
'deepslate_copper_ore'->{
'min'-> 2,
0-> [5,3.5],
1-> [10,4.67],
2-> [15,6.125],
3-> [20,7.7],
},
'deepslate_gold_ore'->{
'min'-> 1,
0-> [1,1],
1-> [2,1.33],
2-> [3,1.75],
3-> [4,2.2],
},
'iron_ore'->{
'min'-> 1,
0-> [1,1],
1-> [2,1.33],
2-> [3,1.75],
3-> [4,2.2],
},
'copper_ore'->{
'min'-> 2,
0-> [5,3.5],
1-> [10,4.67],
2-> [15,6.125],
3-> [20,7.7],
},
'gold_ore'->{
'min'-> 1,
0-> [1,1],
1-> [2,1.33],
2-> [3,1.75],
3-> [4,2.2],
}
};
__on_player_breaks_block(player, block) -> (
held_item = player ~ 'holds';
if(held_item != null && str(held_item:0)~'sword' == null && player ~ 'gamemode' != 'creative',
has_fire_aspect = __has_fire_aspect(held_item:2);
if(has_fire_aspect == 1,(
if(bool(rand(2)),
if(get_smelt_result(block) != null,(
count = 1;
if(global_fortune_chances:str(block) != null,
chances = global_fortune_chances:str(block);
fortune_lvl = __has_fortune(held_item:2);
if(fortune_lvl == null, fortune_lvl = 0);
count = triangulate_drop(chances:'min',chances:fortune_lvl:0,chances:fortune_lvl:1)
);
spawn('item',pos(block)+[0.5,0,0.5],nbt('{Item:{id:'+get_smelt_result(block)+',Count:'+count+'}}'));
set(pos(block),'air');
return('cancel');
), //else
return();
);
);
),//else if
has_fire_aspect >= 2,
if(get_smelt_result(block) != null,
count = 1;
if(global_fortune_chances:str(block) != null,
chances = global_fortune_chances:str(block);
fortune_lvl = __has_fortune(held_item:2);
if(fortune_lvl == null, fortune_lvl = 0);
count = triangulate_drop(chances:'min',chances:fortune_lvl:0,chances:fortune_lvl:1)
);
spawn('item',pos(block)+[0.5,0,0.5],nbt('{Item:{id:'+get_smelt_result(block)+',Count:'+count+'}}'));
set(pos(block),'air');
return('cancel');
);
);
);
);
__has_fire_aspect(nbt) -> (
enchants_list = parse_nbt(nbt):'Enchantments';
if(enchants_list != null,
first(enchants_list,
_:'id' == 'minecraft:fire_aspect';
):'lvl',
//else
0
);
);
__has_fortune(nbt) -> (
enchants_list = parse_nbt(nbt):'Enchantments';
if(enchants_list != null,
first(enchants_list,
_:'id' == 'minecraft:fortune';
):'lvl',
//else
0
);
);