Skip to content

Commit db2df80

Browse files
Starting to get back into this.
1 parent 1661332 commit db2df80

3 files changed

Lines changed: 39 additions & 10 deletions

File tree

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

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import net.swofty.commons.statistics.ItemStatistics;
1010
import org.jetbrains.annotations.Nullable;
1111

12+
import org.json.JSONObject;
13+
1214
public class ItemAttributeHotPotatoBookData extends ItemAttribute<ItemAttributeHotPotatoBookData.HotPotatoBookData> {
1315

1416
@Override
@@ -24,6 +26,10 @@ public HotPotatoBookData getDefaultValue(@Nullable ItemStatistics defaultStatist
2426
@Override
2527
public HotPotatoBookData loadFromString(String string) {
2628
HotPotatoBookData hotPotatoBookData = new HotPotatoBookData();
29+
30+
JSONObject obj = new JSONObject(string);
31+
32+
2733
String[] split = string.split(",");
2834
for (String s : split) {
2935
String[] split1 = s.split(":");
@@ -45,14 +51,22 @@ public HotPotatoBookData loadFromString(String string) {
4551

4652
@Override
4753
public String saveIntoString() {
48-
StringBuilder stringBuilder = new StringBuilder();
54+
JSONObject obj = new JSONObject();
55+
4956
if (getValue().hasPotatoBook()) {
50-
stringBuilder.append("potatoType:").append(getValue().getPotatoType()).append(",");
57+
obj.put("potatoType", getValue().getPotatoType());
5158
} else {
52-
stringBuilder.append("potatoType:null,");
59+
obj.put("potatoType", null);
5360
}
54-
stringBuilder.append("amount:").append(getValue().getAmount());
55-
return stringBuilder.toString();
61+
62+
JSONArray array = new JSONArray();
63+
64+
for (Map.Entry<ItemType, Integer> appliedItem : getValue().getAppliedItems()) {
65+
array.put(appliedItem.getKey() + ":" + appliableItem.getValue())
66+
}
67+
68+
obj.put("applied", array);
69+
return obj.toString();
5670
}
5771

5872
@AllArgsConstructor
@@ -61,14 +75,18 @@ public String saveIntoString() {
6175
@Setter
6276
public static class HotPotatoBookData {
6377
private PotatoType potatoType = null;
64-
private int amount = 0;
78+
private HashMap<ItemType, Integer> appliedItems = new HashMap<>();
6579

66-
public void addAmount(int amount) {
67-
this.amount += amount;
80+
public void addAmount(ItemType itemType, int amount) {
81+
if (!appliedItems.containsKey(itemType)){
82+
appliedItems.put(itemType, amount)
83+
}else{
84+
appliedItems.put(itemType, appliableItems.get(itemType) + amount)
85+
}
6886
}
6987

70-
public boolean hasPotatoBook() {
71-
return amount > 0;
88+
public bool hasAppliedItem(ItemType itemType){
89+
return appliedItems.containsKey(itemType) && appliedItems.get(itemType) > 0;
7290
}
7391
}
7492
}

configuration/items/weapons.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ 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"
1722

1823
- id: ASPECT_OF_THE_JERRY
1924
material: WOODEN_SWORD

type.generic/src/main/java/net/swofty/types/generic/item/components/HotPotatoableComponent.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
public class HotPotatoableComponent extends SkyBlockItemComponent {
99
private final PotatoType potatoType;
1010

11+
private AppliableItem[] appliableItems;
12+
1113
public HotPotatoableComponent(PotatoType type) {
1214
this.potatoType = type;
15+
16+
appliableItems = {new AppliableItem(ItemType.HOT_POTATO_BOOK, 10), new AppliableItem(ItemType.FUMING_POTATO_BOOK, 5)};
1317
}
18+
19+
public record AppliableItem(ItemType itemType, int max)
1420
}

0 commit comments

Comments
 (0)