Skip to content

Commit d0e5b4d

Browse files
Addition: Added in fuming potato books and all support required to apply both hot potato and fuming potato books.
Also added a DUNGEON_ITEM component that just adds a ModifiyRarity component with "DUNGEON ITEM"
1 parent db2df80 commit d0e5b4d

11 files changed

Lines changed: 116 additions & 45 deletions

File tree

commons/src/main/java/net/swofty/commons/item/ItemType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ public enum ItemType {
472472
NECRONS_HANDLE(Material.STICK, Rarity.EPIC),
473473
BIGFOOT_LASSO(Material.LEAD, Rarity.EPIC),
474474
BONZO_FRAGMENT(Material.RED_MUSHROOM, Rarity.RARE),
475+
FUMING_POTATO_BOOK(Material.BOOK, Rarity.EPIC),
475476

476477
/**
477478
* Mythological Ritual

commons/src/main/java/net/swofty/commons/item/PotatoType.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
@Getter
1111
public enum PotatoType {
1212
ARMOR(List.of("§7When applied to armor, grants §a+2" + ItemStatistic.DEFENSE.getSymbol(),
13-
"§aDefense §7and §c+4" + ItemStatistic.HEALTH.getSymbol() + " Health§7.",
14-
" "), Map.of(ItemStatistic.DEFENSE, 2.0, ItemStatistic.HEALTH, 4.0)),
13+
"§aDefense §7and §c+4" + ItemStatistic.HEALTH.getSymbol() + " Health§7."), Map.of(ItemStatistic.DEFENSE, 2.0, ItemStatistic.HEALTH, 4.0)),
1514
WEAPONS(List.of("§7When applied to weapons, grants",
16-
"§c+2" + ItemStatistic.STRENGTH.getSymbol() + " Strength §7and §c+2" + ItemStatistic.DAMAGE.getSymbol() + " Damage§7.",
17-
" "), Map.of(ItemStatistic.STRENGTH, 2.0, ItemStatistic.DAMAGE, 2.0)),
15+
"§c+2" + ItemStatistic.STRENGTH.getSymbol() + " Strength §7and §c+2" + ItemStatistic.DAMAGE.getSymbol() + " Damage§7."), Map.of(ItemStatistic.STRENGTH, 2.0, ItemStatistic.DAMAGE, 2.0)),
1816
;
1917

2018
public List<String> display;
@@ -27,6 +25,7 @@ public enum PotatoType {
2725

2826
public static List<String> allLores() {
2927
List<String> lores = new ArrayList<>(ARMOR.display);
28+
lores.add("");
3029
lores.addAll(WEAPONS.display);
3130
return lores;
3231
}

commons/src/main/java/net/swofty/commons/item/attribute/attributes/ItemAttributeHotPotatoBookData.java

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
import lombok.Getter;
55
import lombok.NoArgsConstructor;
66
import lombok.Setter;
7+
import net.swofty.commons.item.ItemType;
78
import net.swofty.commons.item.PotatoType;
89
import net.swofty.commons.item.attribute.ItemAttribute;
910
import net.swofty.commons.statistics.ItemStatistics;
1011
import org.jetbrains.annotations.Nullable;
1112

13+
import org.json.JSONArray;
1214
import org.json.JSONObject;
1315

16+
import java.util.HashMap;
17+
import java.util.Map;
18+
import java.util.stream.IntStream;
19+
1420
public class ItemAttributeHotPotatoBookData extends ItemAttribute<ItemAttributeHotPotatoBookData.HotPotatoBookData> {
1521

1622
@Override
@@ -28,41 +34,45 @@ public HotPotatoBookData loadFromString(String string) {
2834
HotPotatoBookData hotPotatoBookData = new HotPotatoBookData();
2935

3036
JSONObject obj = new JSONObject(string);
31-
32-
33-
String[] split = string.split(",");
34-
for (String s : split) {
35-
String[] split1 = s.split(":");
36-
switch (split1[0]) {
37-
case "potatoType":
38-
if (!split1[1].equals("null")) {
39-
hotPotatoBookData.setPotatoType(PotatoType.valueOf(split1[1]));
40-
} else {
41-
hotPotatoBookData.setPotatoType(null);
42-
}
43-
break;
44-
case "amount":
45-
hotPotatoBookData.setAmount(Integer.parseInt(split1[1]));
46-
break;
37+
38+
PotatoType potatoType = null;
39+
if (obj.has("potatoType")){
40+
potatoType = obj.getEnum(PotatoType.class, "potatoType");
41+
}
42+
43+
hotPotatoBookData.setPotatoType(potatoType);
44+
45+
if (obj.has("applied")) {
46+
var list = obj.getJSONArray("applied");
47+
48+
HashMap<ItemType, Integer> applied = new HashMap<>();
49+
for (int i = 0; i < list.length(); i++) {
50+
var value = list.getString(i);
51+
52+
var split = value.split(":");
53+
applied.put(ItemType.valueOf(split[0]), Integer.parseInt(split[1]));
4754
}
55+
56+
hotPotatoBookData.setAppliedItems(applied);
4857
}
58+
4959
return hotPotatoBookData;
5060
}
5161

5262
@Override
5363
public String saveIntoString() {
5464
JSONObject obj = new JSONObject();
5565

56-
if (getValue().hasPotatoBook()) {
66+
if (getValue().hasAppliedItem()) {
5767
obj.put("potatoType", getValue().getPotatoType());
5868
} else {
59-
obj.put("potatoType", null);
69+
obj.putOnce("potatoType", null);
6070
}
6171

6272
JSONArray array = new JSONArray();
6373

64-
for (Map.Entry<ItemType, Integer> appliedItem : getValue().getAppliedItems()) {
65-
array.put(appliedItem.getKey() + ":" + appliableItem.getValue())
74+
for (Map.Entry<ItemType, Integer> appliedItem : getValue().getAppliedItems().entrySet()) {
75+
array.put(appliedItem.getKey() + ":" + appliedItem.getValue());
6676
}
6777

6878
obj.put("applied", array);
@@ -79,14 +89,22 @@ public static class HotPotatoBookData {
7989

8090
public void addAmount(ItemType itemType, int amount) {
8191
if (!appliedItems.containsKey(itemType)){
82-
appliedItems.put(itemType, amount)
92+
appliedItems.put(itemType, amount);
8393
}else{
84-
appliedItems.put(itemType, appliableItems.get(itemType) + amount)
94+
appliedItems.put(itemType, appliedItems.get(itemType) + amount);
8595
}
8696
}
8797

88-
public bool hasAppliedItem(ItemType itemType){
98+
public int getAmount(ItemType type){
99+
return appliedItems.getOrDefault(type, 0);
100+
}
101+
102+
public boolean hasAppliedItem(ItemType itemType){
89103
return appliedItems.containsKey(itemType) && appliedItems.get(itemType) > 0;
90104
}
105+
106+
public boolean hasAppliedItem(){
107+
return appliedItems.values().stream().mapToInt(Integer::intValue).sum() > 0;
108+
}
91109
}
92110
}

configuration/items/enchantment.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ items:
99
- id: TRACKED_UNIQUE
1010
- id: ENCHANTED
1111
- id: HOT_POTATO_BOOK
12+
rarity: EPIC
1213
lore:
1314
- "§7This item can be applied to an item up to"
1415
- "§a10 §7times!"
@@ -21,4 +22,19 @@ items:
2122
- id: SELLABLE
2223
value: 38400
2324
- id: TRACKED_UNIQUE
24-
- id: ENCHANTED
25+
- id: ENCHANTED
26+
- id: FUMING_POTATO_BOOK
27+
rarity: EPIC
28+
lore:
29+
- "§7This book bypasses the §5 Hot Potato"
30+
- "§5Book §7 limit of §a10§7, allowing you to"
31+
- "§7upgrade an item up to §a15§7 times!"
32+
components:
33+
- id: ANVIL_COMBINABLE
34+
handler_id: HOT_POTATO_BOOK
35+
- id: LORE_UPDATE
36+
is_absolute: false
37+
handler_id: HOT_POTATO_BOOK
38+
- id: TRACKED_UNIQUE
39+
- id: ENCHANTED
40+
- id: DUNGEON_ITEM

configuration/items/weapons.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ items:
1414
- "SAPPHIRE:50000"
1515
- id: STANDARD_ITEM
1616
standard_item_type: SWORD
17-
- id: HOT_POTATO
18-
potato_type: WEAPONS
19-
appliable_items:
20-
- "HOT_POTATO_BOOK:10"
21-
- "FUMING_POTATO_BOOK:5"
2217

2318
- id: ASPECT_OF_THE_JERRY
2419
material: WOODEN_SWORD

type.generic/src/main/java/net/swofty/types/generic/item/ItemConfigParser.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public static ConfigurableSkyBlockItem parseItem(Map<String, Object> config) {
3838

3939
List<String> lore = (List<String>) config.get("lore");
4040
Map<String, Double> statistics = new HashMap<>();
41+
42+
if (id.startsWith("HOT")){
43+
System.out.println(id);
44+
}
45+
4146
if (config.containsKey("default_statistics")) {
4247
// Convert all the objects to doubles, noting they may be integers
4348
for (Map.Entry<String, Object> entry : ((Map<String, Object>) config.get("default_statistics")).entrySet()) {
@@ -137,6 +142,9 @@ yield new EnchantableComponent(
137142
String display = (String) config.get("display");
138143
yield new ExtraRarityComponent(display);
139144
}
145+
case "DUNGEON_ITEM" -> {
146+
yield new ExtraRarityComponent("DUNGEON ITEM");
147+
}
140148
case "EXTRA_UNDER_NAME" -> {
141149
if (config.containsKey("displays")) {
142150
List<String> displays = (List<String>) config.get("displays");
@@ -158,6 +166,23 @@ yield new EnchantableComponent(
158166
}
159167
case "HOT_POTATO" -> {
160168
String type = (String) config.get("potato_type");
169+
170+
if (config.containsKey("appliable_items")) {
171+
var appliableItems = (List<String>) config.get("appliable_items");
172+
HashMap<ItemType, Integer> appliable = new HashMap<>();
173+
174+
for (var item : appliableItems) {
175+
var split = item.split(":");
176+
177+
if (split.length != 2)
178+
continue;
179+
180+
appliable.put(ItemType.valueOf(split[0]), Integer.parseInt(split[1]));
181+
}
182+
183+
yield new HotPotatoableComponent(PotatoType.valueOf(type), appliable);
184+
}
185+
161186
yield new HotPotatoableComponent(PotatoType.valueOf(type));
162187
}
163188
case "INTERACTABLE" -> {

type.generic/src/main/java/net/swofty/types/generic/item/ItemLore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private boolean addPossiblePropertyInt(ItemStatistic statistic, double overallVa
301301

302302
double hpbValue = 0;
303303
ItemAttributeHotPotatoBookData.HotPotatoBookData hotPotatoBookData = item.getAttributeHandler().getHotPotatoBookData();
304-
if (hotPotatoBookData.hasPotatoBook()) {
304+
if (hotPotatoBookData.hasAppliedItem()) {
305305
for (Map.Entry<ItemStatistic, Double> entry : hotPotatoBookData.getPotatoType().stats.entrySet()) {
306306
ItemStatistic stat = entry.getKey();
307307
Double value = entry.getValue();
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
package net.swofty.types.generic.item.components;
22

33
import lombok.Getter;
4+
import net.swofty.commons.item.ItemType;
45
import net.swofty.commons.item.PotatoType;
56
import net.swofty.types.generic.item.SkyBlockItemComponent;
67

8+
import java.util.HashMap;
9+
import java.util.Map;
10+
711
@Getter
812
public class HotPotatoableComponent extends SkyBlockItemComponent {
913
private final PotatoType potatoType;
1014

11-
private AppliableItem[] appliableItems;
15+
private final Map<ItemType, Integer> applicableItems;
1216

1317
public HotPotatoableComponent(PotatoType type) {
1418
this.potatoType = type;
1519

16-
appliableItems = {new AppliableItem(ItemType.HOT_POTATO_BOOK, 10), new AppliableItem(ItemType.FUMING_POTATO_BOOK, 5)};
20+
applicableItems = Map.of(ItemType.HOT_POTATO_BOOK, 10, ItemType.FUMING_POTATO_BOOK, 5);// new ApplicableItem[]{new ApplicableItem(ItemType.HOT_POTATO_BOOK, 10), new ApplicableItem(ItemType.FUMING_POTATO_BOOK, 5)};
21+
}
22+
23+
public HotPotatoableComponent(PotatoType type, Map<ItemType, Integer> applicableItems){
24+
this.potatoType = type;
25+
this.applicableItems = applicableItems;
1726
}
1827

19-
public record AppliableItem(ItemType itemType, int max)
28+
public boolean canApply(ItemType type){
29+
return applicableItems.containsKey(type);
30+
}
31+
32+
public int getMax(ItemType type){
33+
return applicableItems.getOrDefault(type, 0);
34+
}
2035
}

type.generic/src/main/java/net/swofty/types/generic/item/handlers/anvilcombine/AnvilCombineRegistry.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,22 @@ public class AnvilCombineRegistry {
2424
HotPotatoableComponent hotPotatoable = upgradeItem.getComponent(HotPotatoableComponent.class);
2525
PotatoType potatoType = hotPotatoable.getPotatoType();
2626

27+
var type = sacrificeItem.getAttributeHandler().getPotentialType();
28+
2729
ItemAttributeHotPotatoBookData.HotPotatoBookData upgradeData = upgradeItem.getAttributeHandler().getHotPotatoBookData();
28-
upgradeData.addAmount(1);
30+
upgradeData.addAmount(type, 1);
2931
upgradeData.setPotatoType(potatoType);
3032
upgradeItem.getAttributeHandler().setHotPotatoBookData(upgradeData);
3133
},
3234
(player, upgradeItem, sacrificeItem) -> {
3335
if (upgradeItem.hasComponent(HotPotatoableComponent.class)) {
36+
System.out.println(upgradeItem.getAttributeHandler().getPotentialType());
37+
38+
var type = sacrificeItem.getAttributeHandler().getPotentialType();
39+
3440
HotPotatoableComponent hotPotatoable = upgradeItem.getComponent(HotPotatoableComponent.class);
3541
ItemAttributeHotPotatoBookData.HotPotatoBookData upgradeData = upgradeItem.getAttributeHandler().getHotPotatoBookData();
36-
return upgradeData.getAmount() < 10;
42+
return hotPotatoable.canApply(type) && upgradeData.getAmount(type) < hotPotatoable.getMax(type);
3743
}
3844
return false;
3945
},

type.generic/src/main/java/net/swofty/types/generic/item/handlers/lore/LoreRegistry.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ public class LoreRegistry {
7070
"§eClick to open!"
7171
), (item, player) -> "§aSkyBlock Menu §7(Click)"));
7272
register("HOT_POTATO_BOOK", new LoreConfig((item, player) -> {
73-
List<String> lore = PotatoType.allLores();
74-
lore.add("§7This item can be applied to an item up to");
75-
lore.add("§a10 §7times!");
76-
77-
return lore;
73+
return PotatoType.allLores();
7874
}, null));
7975
}
8076

0 commit comments

Comments
 (0)