Skip to content

Commit b2a43b1

Browse files
Merge pull request #491 from FreakyFreakyNerd/master
Implemented fuming potato books and support for dungeon item rarity type.
2 parents 1661332 + a02db1c commit b2a43b1

10 files changed

Lines changed: 135 additions & 39 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: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +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;
14+
import org.json.JSONObject;
15+
16+
import java.util.HashMap;
17+
import java.util.Map;
18+
import java.util.stream.IntStream;
19+
1220
public class ItemAttributeHotPotatoBookData extends ItemAttribute<ItemAttributeHotPotatoBookData.HotPotatoBookData> {
1321

1422
@Override
@@ -24,35 +32,51 @@ public HotPotatoBookData getDefaultValue(@Nullable ItemStatistics defaultStatist
2432
@Override
2533
public HotPotatoBookData loadFromString(String string) {
2634
HotPotatoBookData hotPotatoBookData = new HotPotatoBookData();
27-
String[] split = string.split(",");
28-
for (String s : split) {
29-
String[] split1 = s.split(":");
30-
switch (split1[0]) {
31-
case "potatoType":
32-
if (!split1[1].equals("null")) {
33-
hotPotatoBookData.setPotatoType(PotatoType.valueOf(split1[1]));
34-
} else {
35-
hotPotatoBookData.setPotatoType(null);
36-
}
37-
break;
38-
case "amount":
39-
hotPotatoBookData.setAmount(Integer.parseInt(split1[1]));
40-
break;
35+
36+
JSONObject obj = new JSONObject(string);
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]));
4154
}
55+
56+
hotPotatoBookData.setAppliedItems(applied);
4257
}
58+
4359
return hotPotatoBookData;
4460
}
4561

4662
@Override
4763
public String saveIntoString() {
48-
StringBuilder stringBuilder = new StringBuilder();
49-
if (getValue().hasPotatoBook()) {
50-
stringBuilder.append("potatoType:").append(getValue().getPotatoType()).append(",");
64+
JSONObject obj = new JSONObject();
65+
66+
if (getValue().hasAppliedItem()) {
67+
obj.put("potatoType", getValue().getPotatoType());
5168
} else {
52-
stringBuilder.append("potatoType:null,");
69+
obj.putOnce("potatoType", null);
5370
}
54-
stringBuilder.append("amount:").append(getValue().getAmount());
55-
return stringBuilder.toString();
71+
72+
JSONArray array = new JSONArray();
73+
74+
for (Map.Entry<ItemType, Integer> appliedItem : getValue().getAppliedItems().entrySet()) {
75+
array.put(appliedItem.getKey() + ":" + appliedItem.getValue());
76+
}
77+
78+
obj.put("applied", array);
79+
return obj.toString();
5680
}
5781

5882
@AllArgsConstructor
@@ -61,14 +85,26 @@ public String saveIntoString() {
6185
@Setter
6286
public static class HotPotatoBookData {
6387
private PotatoType potatoType = null;
64-
private int amount = 0;
88+
private HashMap<ItemType, Integer> appliedItems = new HashMap<>();
89+
90+
public void addAmount(ItemType itemType, int amount) {
91+
if (!appliedItems.containsKey(itemType)){
92+
appliedItems.put(itemType, amount);
93+
}else{
94+
appliedItems.put(itemType, appliedItems.get(itemType) + amount);
95+
}
96+
}
97+
98+
public int getAmount(ItemType type){
99+
return appliedItems.getOrDefault(type, 0);
100+
}
65101

66-
public void addAmount(int amount) {
67-
this.amount += amount;
102+
public boolean hasAppliedItem(ItemType itemType){
103+
return appliedItems.containsKey(itemType) && appliedItems.get(itemType) > 0;
68104
}
69105

70-
public boolean hasPotatoBook() {
71-
return amount > 0;
106+
public boolean hasAppliedItem(){
107+
return appliedItems.values().stream().mapToInt(Integer::intValue).sum() > 0;
72108
}
73109
}
74110
}

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

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ 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+
4142
if (config.containsKey("default_statistics")) {
4243
// Convert all the objects to doubles, noting they may be integers
4344
for (Map.Entry<String, Object> entry : ((Map<String, Object>) config.get("default_statistics")).entrySet()) {
@@ -137,6 +138,9 @@ yield new EnchantableComponent(
137138
String display = (String) config.get("display");
138139
yield new ExtraRarityComponent(display);
139140
}
141+
case "DUNGEON_ITEM" -> {
142+
yield new ExtraRarityComponent("DUNGEON ITEM");
143+
}
140144
case "EXTRA_UNDER_NAME" -> {
141145
if (config.containsKey("displays")) {
142146
List<String> displays = (List<String>) config.get("displays");
@@ -158,6 +162,23 @@ yield new EnchantableComponent(
158162
}
159163
case "HOT_POTATO" -> {
160164
String type = (String) config.get("potato_type");
165+
166+
if (config.containsKey("appliable_items")) {
167+
var appliableItems = (List<String>) config.get("appliable_items");
168+
HashMap<ItemType, Integer> appliable = new HashMap<>();
169+
170+
for (var item : appliableItems) {
171+
var split = item.split(":");
172+
173+
if (split.length != 2)
174+
continue;
175+
176+
appliable.put(ItemType.valueOf(split[0]), Integer.parseInt(split[1]));
177+
}
178+
179+
yield new HotPotatoableComponent(PotatoType.valueOf(type), appliable);
180+
}
181+
161182
yield new HotPotatoableComponent(PotatoType.valueOf(type));
162183
}
163184
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +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

15+
private final Map<ItemType, Integer> applicableItems;
16+
1117
public HotPotatoableComponent(PotatoType type) {
1218
this.potatoType = type;
19+
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;
26+
}
27+
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);
1334
}
1435
}

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

type.generic/src/main/java/net/swofty/types/generic/user/statistics/PlayerStatistics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private ItemStatistics getReforgeStatistics(SkyBlockItem item, ItemStatistics st
283283

284284
private ItemStatistics getHotPotatoBookStatistics(SkyBlockItem item, ItemStatistics statistics) {
285285
ItemAttributeHotPotatoBookData.HotPotatoBookData hotPotatoBookData = item.getAttributeHandler().getHotPotatoBookData();
286-
if (hotPotatoBookData.hasPotatoBook()) {
286+
if (hotPotatoBookData.hasAppliedItem()) {
287287
ItemStatistics.Builder toAdd = ItemStatistics.builder();
288288
PotatoType potatoType = hotPotatoBookData.getPotatoType();
289289

0 commit comments

Comments
 (0)