Skip to content

Commit f041bd5

Browse files
committed
refactor: add and use a new class for prime components (Component.java)
1 parent 651c372 commit f041bd5

File tree

3 files changed

+72
-35
lines changed

3 files changed

+72
-35
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package me.voper.slimeframe.implementation.items.components;
2+
3+
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
4+
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
5+
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
6+
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.UnplaceableBlock;
7+
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
8+
import me.voper.slimeframe.implementation.groups.Groups;
9+
import me.voper.slimeframe.utils.Keys;
10+
import me.voper.slimeframe.utils.Utils;
11+
import net.md_5.bungee.api.ChatColor;
12+
import org.bukkit.Material;
13+
import org.bukkit.entity.Player;
14+
import org.bukkit.inventory.ItemStack;
15+
16+
import javax.annotation.Nonnull;
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
import java.util.stream.Stream;
20+
21+
public class Component extends UnplaceableBlock implements RecipeDisplayItem {
22+
23+
public static final RecipeType RECIPE_TYPE = new RecipeType(Keys.createKey("prime_component_reward"), new CustomItemStack(Material.DIAMOND, ChatColor.AQUA + "This item is dropped by the relics below:"));
24+
25+
private final List<ItemStack> relics = new ArrayList<>();
26+
27+
public Component(SlimefunItemStack item) {
28+
super(Groups.PRIME_COMPONENTS, item, RECIPE_TYPE, Utils.NULL_ITEMS_ARRAY);
29+
}
30+
31+
public void setRelics(List<ItemStack> relics) {
32+
this.relics.addAll(relics);
33+
}
34+
35+
@Nonnull
36+
@Override
37+
public List<ItemStack> getDisplayRecipes() {
38+
return relics.stream().flatMap(relic -> Stream.of(relic, null)).toList();
39+
}
40+
41+
@Nonnull
42+
@Override
43+
public String getRecipeSectionLabel(@Nonnull Player p) {
44+
return "&7\u21E9 Dropped by \u21E9";
45+
}
46+
}

src/main/java/me/voper/slimeframe/implementation/items/components/PrimeComponents.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
package me.voper.slimeframe.implementation.items.components;
22

33
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
4-
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
5-
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.UnplaceableBlock;
6-
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
74
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
85
import lombok.Getter;
96
import lombok.Setter;
107
import lombok.experimental.Accessors;
118
import me.voper.slimeframe.SlimeFrame;
129
import me.voper.slimeframe.implementation.SFrameStacks;
1310
import me.voper.slimeframe.implementation.SFrameTheme;
14-
import me.voper.slimeframe.implementation.groups.Groups;
1511
import me.voper.slimeframe.implementation.items.relics.RelicItemStack;
1612
import me.voper.slimeframe.utils.Colors;
1713
import me.voper.slimeframe.utils.HeadTextures;
18-
import me.voper.slimeframe.utils.Keys;
19-
import me.voper.slimeframe.utils.Utils;
2014
import net.md_5.bungee.api.ChatColor;
21-
import org.bukkit.Material;
2215
import org.bukkit.inventory.ItemStack;
2316

2417
import javax.annotation.Nonnull;
@@ -35,7 +28,6 @@
3528
@ParametersAreNonnullByDefault
3629
public class PrimeComponents {
3730

38-
public static final RecipeType RECIPE_TYPE = new RecipeType(Keys.createKey("prime_component_reward"), new CustomItemStack(Material.DIAMOND, ChatColor.AQUA + "This item is dropped by the following relics:"));
3931
public static final Map<SlimefunItemStack, PrimeComponents> COMPONENTS_MAP = new HashMap<>();
4032

4133
// Machines & Generators components
@@ -152,36 +144,36 @@ public static void registerAll(SlimeFrame plugin) {
152144
}
153145

154146
private static void register(PrimeComponents components, SlimeFrame plugin) throws IllegalAccessException {
155-
UnplaceableBlock coreModuleSF = new UnplaceableBlock(Groups.PRIME_COMPONENTS, components.getCoreModule(), RECIPE_TYPE, Utils.NULL_ITEMS_ARRAY);
156-
UnplaceableBlock powerCellSF = new UnplaceableBlock(Groups.PRIME_COMPONENTS, components.getPowerCell(), RECIPE_TYPE, Utils.NULL_ITEMS_ARRAY);
157-
UnplaceableBlock controlUnitSF = new UnplaceableBlock(Groups.PRIME_COMPONENTS, components.getControlUnit(), RECIPE_TYPE, Utils.NULL_ITEMS_ARRAY);
147+
Component coreModuleSF = new Component(components.getCoreModule());
148+
Component powerCellSF = new Component(components.getPowerCell());
149+
Component controlUnitSF = new Component(components.getControlUnit());
158150

159-
List<ItemStack> recipeCoreModule = new ArrayList<>(9);
160-
List<ItemStack> recipePowerCell = new ArrayList<>(9);
161-
List<ItemStack> recipeControlUnit = new ArrayList<>(9);
151+
List<ItemStack> relicsCoreModule = new ArrayList<>();
152+
List<ItemStack> relicsPowerCell = new ArrayList<>();
153+
List<ItemStack> relicsControlUnit = new ArrayList<>();
162154

163155
for (Field field: SFrameStacks.class.getDeclaredFields()) {
164156
if (field.getType() != RelicItemStack.class) continue;
165157
RelicItemStack relic = (RelicItemStack) field.get(null);
166158

167159
for (SlimefunItemStack common: relic.getCommonDrops()) {
168160
if (!SlimefunUtils.isItemSimilar(components.getControlUnit(), common, true)) continue;
169-
recipeControlUnit.add(relic);
161+
relicsControlUnit.add(relic);
170162
}
171163

172164
for (SlimefunItemStack uncommon: relic.getUncommonDrops()) {
173165
if (!SlimefunUtils.isItemSimilar(components.getPowerCell(), uncommon, true)) continue;
174-
recipePowerCell.add(relic);
166+
relicsPowerCell.add(relic);
175167
}
176168

177169
if (SlimefunUtils.isItemSimilar(components.getCoreModule(), relic.getRareDrop(), true)) {
178-
recipeCoreModule.add(relic);
170+
relicsCoreModule.add(relic);
179171
}
180172
}
181173

182-
coreModuleSF.setRecipe(recipeCoreModule.toArray(new ItemStack[9]));
183-
powerCellSF.setRecipe(recipePowerCell.toArray(new ItemStack[9]));
184-
controlUnitSF.setRecipe(recipeControlUnit.toArray(new ItemStack[9]));
174+
coreModuleSF.setRelics(relicsCoreModule);
175+
powerCellSF.setRelics(relicsPowerCell);
176+
controlUnitSF.setRelics(relicsControlUnit);
185177

186178
coreModuleSF.register(plugin);
187179
powerCellSF.register(plugin);

src/main/java/me/voper/slimeframe/implementation/items/components/UtilsComponents.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package me.voper.slimeframe.implementation.items.components;
22

33
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
4-
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.UnplaceableBlock;
54
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
65
import lombok.Getter;
76
import lombok.Setter;
87
import lombok.experimental.Accessors;
98
import me.voper.slimeframe.SlimeFrame;
109
import me.voper.slimeframe.implementation.SFrameStacks;
1110
import me.voper.slimeframe.implementation.SFrameTheme;
12-
import me.voper.slimeframe.implementation.groups.Groups;
1311
import me.voper.slimeframe.implementation.items.relics.RelicItemStack;
1412
import me.voper.slimeframe.utils.Colors;
1513
import me.voper.slimeframe.utils.HeadTextures;
16-
import me.voper.slimeframe.utils.Utils;
1714
import net.md_5.bungee.api.ChatColor;
1815
import org.bukkit.inventory.ItemStack;
1916

17+
import javax.annotation.ParametersAreNonnullByDefault;
2018
import java.lang.reflect.Field;
2119
import java.util.ArrayList;
2220
import java.util.HashMap;
@@ -26,6 +24,7 @@
2624
@Getter
2725
@Setter
2826
@Accessors(chain = true)
27+
@ParametersAreNonnullByDefault
2928
public class UtilsComponents {
3029

3130
public static final Map<SlimefunItemStack, UtilsComponents> COMPONENTS_MAP = new HashMap<>();
@@ -140,36 +139,36 @@ public static void registerAll(SlimeFrame plugin) {
140139
}
141140

142141
private static void register(UtilsComponents components, SlimeFrame plugin) throws IllegalAccessException {
143-
UnplaceableBlock neuralNex = new UnplaceableBlock(Groups.PRIME_COMPONENTS, components.getNeuralNexusCore(), PrimeComponents.RECIPE_TYPE, Utils.NULL_ITEMS_ARRAY);
144-
UnplaceableBlock temporalCog = new UnplaceableBlock(Groups.PRIME_COMPONENTS, components.getTemporalCogwheel(), PrimeComponents.RECIPE_TYPE, Utils.NULL_ITEMS_ARRAY);
145-
UnplaceableBlock voidShard = new UnplaceableBlock(Groups.PRIME_COMPONENTS, components.getVoidShardEssence(), PrimeComponents.RECIPE_TYPE, Utils.NULL_ITEMS_ARRAY);
142+
Component neuralNex = new Component(components.getNeuralNexusCore());
143+
Component temporalCog = new Component(components.getTemporalCogwheel());
144+
Component voidShard = new Component(components.getVoidShardEssence());
146145

147-
List<ItemStack> recipeNeuralNex = new ArrayList<>(9);
148-
List<ItemStack> recipeTempCog = new ArrayList<>(9);
149-
List<ItemStack> recipeVoidShard = new ArrayList<>(9);
146+
List<ItemStack> relicsNeuralNex = new ArrayList<>();
147+
List<ItemStack> relicsTempCog = new ArrayList<>();
148+
List<ItemStack> relicsVoidShard = new ArrayList<>();
150149

151150
for (Field field: SFrameStacks.class.getDeclaredFields()) {
152151
if (field.getType() != RelicItemStack.class) continue;
153152
RelicItemStack relic = (RelicItemStack) field.get(null);
154153

155154
for (SlimefunItemStack common: relic.getCommonDrops()) {
156155
if (!SlimefunUtils.isItemSimilar(components.getVoidShardEssence(), common, true)) continue;
157-
recipeVoidShard.add(relic);
156+
relicsVoidShard.add(relic);
158157
}
159158

160159
for (SlimefunItemStack uncommon: relic.getUncommonDrops()) {
161160
if (!SlimefunUtils.isItemSimilar(components.getTemporalCogwheel(), uncommon, true)) continue;
162-
recipeTempCog.add(relic);
161+
relicsTempCog.add(relic);
163162
}
164163

165164
if (SlimefunUtils.isItemSimilar(components.getNeuralNexusCore(), relic.getRareDrop(), true)) {
166-
recipeNeuralNex.add(relic);
165+
relicsNeuralNex.add(relic);
167166
}
168167
}
169168

170-
neuralNex.setRecipe(recipeNeuralNex.toArray(new ItemStack[9]));
171-
temporalCog.setRecipe(recipeTempCog.toArray(new ItemStack[9]));
172-
voidShard.setRecipe(recipeVoidShard.toArray(new ItemStack[9]));
169+
neuralNex.setRelics(relicsNeuralNex);
170+
temporalCog.setRelics(relicsTempCog);
171+
voidShard.setRelics(relicsVoidShard);
173172

174173
neuralNex.register(plugin);
175174
temporalCog.register(plugin);

0 commit comments

Comments
 (0)