Skip to content

Commit 96dd1e8

Browse files
committed
fix: mark selector items using PDC
1 parent 2bef098 commit 96dd1e8

File tree

7 files changed

+175
-70
lines changed

7 files changed

+175
-70
lines changed

src/main/java/me/voper/slimeframe/implementation/items/abstracts/AbstractSelectorMachine.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) {
114114

115115
if (found.size() == recipe.getInput().length) {
116116

117-
ItemStack output = menu.getItemInSlot(getSelectorSlot()).clone();
117+
ItemStack output = getOutput(menu.getItemInSlot(getSelectorSlot()));
118118
output.setAmount(production * outputAmount);
119119
MachineRecipe machineRecipe = new MachineRecipe(recipe.getTicks() / 2, recipe.getInput(), new ItemStack[]{output});
120120

@@ -165,4 +165,7 @@ public int getSelectorSlot() {
165165
return MachineDesign.SELECTOR_MACHINE.selectorSlot();
166166
}
167167

168+
@Nonnull
169+
protected abstract ItemStack getOutput(@Nonnull ItemStack item);
170+
168171
}

src/main/java/me/voper/slimeframe/implementation/items/machines/ConcreteGenerator.java

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package me.voper.slimeframe.implementation.items.machines;
22

33
import java.util.ArrayList;
4+
import java.util.HashMap;
45
import java.util.List;
6+
import java.util.Map;
57

68
import javax.annotation.Nonnull;
79
import javax.annotation.ParametersAreNonnullByDefault;
@@ -25,26 +27,34 @@
2527
public class ConcreteGenerator extends AbstractSelectorMachine implements RecipeDisplayItem {
2628

2729
private static final String BLOCK_KEY = "concrete_selector";
28-
private static final List<ItemStack> CONCRETE_LIST = List.of(
30+
private static final Map<Material, ItemStack> OUTPUT_MAPPER;
31+
private static final List<ItemStack> CONCRETES = List.of(
2932
MachineUtils.SELECTOR,
30-
new ItemStack(Material.WHITE_CONCRETE),
31-
new ItemStack(Material.ORANGE_CONCRETE),
32-
new ItemStack(Material.MAGENTA_CONCRETE),
33-
new ItemStack(Material.LIGHT_BLUE_CONCRETE),
34-
new ItemStack(Material.YELLOW_CONCRETE),
35-
new ItemStack(Material.LIME_CONCRETE),
36-
new ItemStack(Material.PINK_CONCRETE),
37-
new ItemStack(Material.GRAY_CONCRETE),
38-
new ItemStack(Material.LIGHT_GRAY_CONCRETE),
39-
new ItemStack(Material.CYAN_CONCRETE),
40-
new ItemStack(Material.PURPLE_CONCRETE),
41-
new ItemStack(Material.BLUE_CONCRETE),
42-
new ItemStack(Material.BROWN_CONCRETE),
43-
new ItemStack(Material.GREEN_CONCRETE),
44-
new ItemStack(Material.RED_CONCRETE),
45-
new ItemStack(Material.BLACK_CONCRETE)
33+
MachineUtils.selectorItem(Material.WHITE_CONCRETE),
34+
MachineUtils.selectorItem(Material.ORANGE_CONCRETE),
35+
MachineUtils.selectorItem(Material.MAGENTA_CONCRETE),
36+
MachineUtils.selectorItem(Material.LIGHT_BLUE_CONCRETE),
37+
MachineUtils.selectorItem(Material.YELLOW_CONCRETE),
38+
MachineUtils.selectorItem(Material.LIME_CONCRETE),
39+
MachineUtils.selectorItem(Material.PINK_CONCRETE),
40+
MachineUtils.selectorItem(Material.GRAY_CONCRETE),
41+
MachineUtils.selectorItem(Material.LIGHT_GRAY_CONCRETE),
42+
MachineUtils.selectorItem(Material.CYAN_CONCRETE),
43+
MachineUtils.selectorItem(Material.PURPLE_CONCRETE),
44+
MachineUtils.selectorItem(Material.BLUE_CONCRETE),
45+
MachineUtils.selectorItem(Material.BROWN_CONCRETE),
46+
MachineUtils.selectorItem(Material.GREEN_CONCRETE),
47+
MachineUtils.selectorItem(Material.RED_CONCRETE),
48+
MachineUtils.selectorItem(Material.BLACK_CONCRETE)
4649
);
4750

51+
static {
52+
OUTPUT_MAPPER = new HashMap<>();
53+
CONCRETES.subList(1, CONCRETES.size()).forEach(item -> {
54+
OUTPUT_MAPPER.put(item.getType(), new ItemStack(item.getType()));
55+
});
56+
}
57+
4858
public ConcreteGenerator(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
4959
super(itemGroup, item, recipeType, recipe);
5060
this.outputAmount = 6;
@@ -63,7 +73,7 @@ public void postRegister() {
6373
@Nonnull
6474
@Override
6575
public List<ItemStack> selectionList() {
66-
return CONCRETE_LIST;
76+
return CONCRETES;
6777
}
6878

6979
@Nonnull
@@ -82,11 +92,17 @@ protected void onCraftConditionsNotMet(BlockMenu menu) {
8292
MachineUtils.replaceExistingItemViewer(menu, getStatusSlot(), new CustomItemStack(Material.BARRIER, ChatColor.RED + "Select a concrete to generate!"));
8393
}
8494

95+
@Nonnull
96+
@Override
97+
protected ItemStack getOutput(@Nonnull ItemStack item) {
98+
return OUTPUT_MAPPER.get(item.getType());
99+
}
100+
85101
@Nonnull
86102
@Override
87103
public List<ItemStack> getDisplayRecipes() {
88104
final List<ItemStack> displayRecipes = new ArrayList<>();
89-
for (ItemStack itemStack : CONCRETE_LIST) {
105+
for (ItemStack itemStack : CONCRETES) {
90106
if (!itemStack.getType().name().endsWith("_CONCRETE")) continue;
91107
displayRecipes.add(recipes.get(0).getInput()[0]);
92108
ItemStack clone = itemStack.clone();

src/main/java/me/voper/slimeframe/implementation/items/machines/DustGenerator.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package me.voper.slimeframe.implementation.items.machines;
22

33
import java.util.ArrayList;
4+
import java.util.HashMap;
45
import java.util.List;
6+
import java.util.Map;
57

68
import javax.annotation.Nonnull;
79

10+
import io.github.thebusybiscuit.slimefun4.libraries.dough.data.persistent.PersistentDataAPI;
11+
12+
import me.voper.slimeframe.utils.Keys;
13+
814
import org.bukkit.Material;
915
import org.bukkit.inventory.ItemStack;
1016

@@ -21,22 +27,36 @@
2127
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
2228
import net.md_5.bungee.api.ChatColor;
2329

30+
import org.bukkit.inventory.meta.ItemMeta;
31+
2432
public class DustGenerator extends AbstractSelectorMachine implements RecipeDisplayItem {
2533

2634
private static final String BLOCK_KEY = "dust_selector";
35+
private static final Map<String, ItemStack> OUTPUT_MAPPER;
2736
private static final List<ItemStack> DUSTS = new ArrayList<>(List.of(
2837
MachineUtils.SELECTOR,
29-
SlimefunItems.ALUMINUM_DUST,
30-
SlimefunItems.COPPER_DUST,
31-
SlimefunItems.GOLD_DUST,
32-
SlimefunItems.IRON_DUST,
33-
SlimefunItems.LEAD_DUST,
34-
SlimefunItems.MAGNESIUM_DUST,
35-
SlimefunItems.SILVER_DUST,
36-
SlimefunItems.TIN_DUST,
37-
SlimefunItems.ZINC_DUST
38+
MachineUtils.selectorItem(SlimefunItems.ALUMINUM_DUST),
39+
MachineUtils.selectorItem(SlimefunItems.COPPER_DUST),
40+
MachineUtils.selectorItem(SlimefunItems.GOLD_DUST),
41+
MachineUtils.selectorItem(SlimefunItems.IRON_DUST),
42+
MachineUtils.selectorItem(SlimefunItems.LEAD_DUST),
43+
MachineUtils.selectorItem(SlimefunItems.MAGNESIUM_DUST),
44+
MachineUtils.selectorItem(SlimefunItems.SILVER_DUST),
45+
MachineUtils.selectorItem(SlimefunItems.TIN_DUST),
46+
MachineUtils.selectorItem(SlimefunItems.ZINC_DUST)
3847
));
3948

49+
static {
50+
OUTPUT_MAPPER = new HashMap<>();
51+
DUSTS.subList(1, DUSTS.size()).forEach(item -> {
52+
ItemStack clone = item.clone();
53+
ItemMeta itemMeta = clone.getItemMeta();
54+
PersistentDataAPI.remove(itemMeta, Keys.createKey("mark_wf"));
55+
clone.setItemMeta(itemMeta);
56+
OUTPUT_MAPPER.put(item.getItemMeta().getDisplayName(), clone);
57+
});
58+
}
59+
4060
public DustGenerator(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
4161
super(itemGroup, item, recipeType, recipe);
4262
this.outputAmount = 2;
@@ -75,6 +95,12 @@ protected void onCraftConditionsNotMet(BlockMenu menu) {
7595
MachineUtils.replaceExistingItemViewer(menu, getStatusSlot(), new CustomItemStack(Material.BARRIER, ChatColor.RED + "Select a dust to generate!"));
7696
}
7797

98+
@Nonnull
99+
@Override
100+
protected ItemStack getOutput(@Nonnull ItemStack item) {
101+
return OUTPUT_MAPPER.get(item.getItemMeta().getDisplayName());
102+
}
103+
78104
@Nonnull
79105
@Override
80106
public List<ItemStack> getDisplayRecipes() {

src/main/java/me/voper/slimeframe/implementation/items/machines/GlassGenerator.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package me.voper.slimeframe.implementation.items.machines;
22

3-
import java.util.ArrayList;
4-
import java.util.Comparator;
5-
import java.util.List;
3+
import java.util.*;
64
import java.util.stream.Stream;
75

86
import javax.annotation.Nonnull;
@@ -26,15 +24,21 @@
2624
public class GlassGenerator extends AbstractSelectorMachine implements RecipeDisplayItem {
2725

2826
private static final String BLOCK_KEY = "glass_selector";
27+
private static final Map<Material, ItemStack> OUTPUT_MAPPER;
2928
private static final List<ItemStack> GLASSES = new ArrayList<>();
3029

3130
static {
3231
GLASSES.add(MachineUtils.SELECTOR);
3332
GLASSES.addAll(SlimefunTag.GLASS_BLOCKS.stream()
3433
.sorted(Comparator.comparing(Enum::name))
3534
.filter(m -> !m.name().contains("TINTED"))
36-
.map(ItemStack::new)
35+
.map(MachineUtils::selectorItem)
3736
.toList());
37+
38+
OUTPUT_MAPPER = new HashMap<>();
39+
GLASSES.subList(1, GLASSES.size()).forEach(item -> {
40+
OUTPUT_MAPPER.put(item.getType(), new ItemStack(item.getType()));
41+
});
3842
}
3943

4044
public GlassGenerator(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
@@ -74,6 +78,12 @@ protected void onCraftConditionsNotMet(BlockMenu menu) {
7478
MachineUtils.replaceExistingItemViewer(menu, getStatusSlot(), new CustomItemStack(Material.BARRIER, ChatColor.RED + "Select a glass to generate!"));
7579
}
7680

81+
@Nonnull
82+
@Override
83+
protected ItemStack getOutput(@Nonnull ItemStack item) {
84+
return OUTPUT_MAPPER.get(item.getType());
85+
}
86+
7787
@Nonnull
7888
@Override
7989
public List<ItemStack> getDisplayRecipes() {

src/main/java/me/voper/slimeframe/implementation/items/machines/TerracottaGenerator.java

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package me.voper.slimeframe.implementation.items.machines;
22

33
import java.util.ArrayList;
4+
import java.util.HashMap;
45
import java.util.List;
6+
import java.util.Map;
57

68
import javax.annotation.Nonnull;
79

@@ -23,27 +25,35 @@
2325
public class TerracottaGenerator extends AbstractSelectorMachine implements RecipeDisplayItem {
2426

2527
private static final String BLOCK_KEY = "terracota_selector";
26-
private static final List<ItemStack> TERRACOTTA_LIST = List.of(
28+
private static final Map<Material, ItemStack> OUTPUT_MAPPER;
29+
private static final List<ItemStack> TERRACOTTAS = List.of(
2730
MachineUtils.SELECTOR,
28-
new ItemStack(Material.TERRACOTTA),
29-
new ItemStack(Material.WHITE_TERRACOTTA),
30-
new ItemStack(Material.ORANGE_TERRACOTTA),
31-
new ItemStack(Material.MAGENTA_TERRACOTTA),
32-
new ItemStack(Material.LIGHT_BLUE_TERRACOTTA),
33-
new ItemStack(Material.YELLOW_TERRACOTTA),
34-
new ItemStack(Material.LIME_TERRACOTTA),
35-
new ItemStack(Material.PINK_TERRACOTTA),
36-
new ItemStack(Material.GRAY_TERRACOTTA),
37-
new ItemStack(Material.LIGHT_GRAY_TERRACOTTA),
38-
new ItemStack(Material.CYAN_TERRACOTTA),
39-
new ItemStack(Material.PURPLE_TERRACOTTA),
40-
new ItemStack(Material.BLUE_TERRACOTTA),
41-
new ItemStack(Material.BROWN_TERRACOTTA),
42-
new ItemStack(Material.GREEN_TERRACOTTA),
43-
new ItemStack(Material.RED_TERRACOTTA),
44-
new ItemStack(Material.BLACK_TERRACOTTA)
31+
MachineUtils.selectorItem(Material.TERRACOTTA),
32+
MachineUtils.selectorItem(Material.WHITE_TERRACOTTA),
33+
MachineUtils.selectorItem(Material.ORANGE_TERRACOTTA),
34+
MachineUtils.selectorItem(Material.MAGENTA_TERRACOTTA),
35+
MachineUtils.selectorItem(Material.LIGHT_BLUE_TERRACOTTA),
36+
MachineUtils.selectorItem(Material.YELLOW_TERRACOTTA),
37+
MachineUtils.selectorItem(Material.LIME_TERRACOTTA),
38+
MachineUtils.selectorItem(Material.PINK_TERRACOTTA),
39+
MachineUtils.selectorItem(Material.GRAY_TERRACOTTA),
40+
MachineUtils.selectorItem(Material.LIGHT_GRAY_TERRACOTTA),
41+
MachineUtils.selectorItem(Material.CYAN_TERRACOTTA),
42+
MachineUtils.selectorItem(Material.PURPLE_TERRACOTTA),
43+
MachineUtils.selectorItem(Material.BLUE_TERRACOTTA),
44+
MachineUtils.selectorItem(Material.BROWN_TERRACOTTA),
45+
MachineUtils.selectorItem(Material.GREEN_TERRACOTTA),
46+
MachineUtils.selectorItem(Material.RED_TERRACOTTA),
47+
MachineUtils.selectorItem(Material.BLACK_TERRACOTTA)
4548
);
4649

50+
static {
51+
OUTPUT_MAPPER = new HashMap<>();
52+
TERRACOTTAS.subList(1, TERRACOTTAS.size()).forEach(item -> {
53+
OUTPUT_MAPPER.put(item.getType(), new ItemStack(item.getType()));
54+
});
55+
}
56+
4757
public TerracottaGenerator(SlimefunItemStack item, ItemStack[] recipe) {
4858
super(Groups.MACHINES, item, Foundry.RECIPE_TYPE, recipe);
4959
this.outputAmount = 6;
@@ -62,7 +72,7 @@ public void postRegister() {
6272
@Nonnull
6373
@Override
6474
public List<ItemStack> selectionList() {
65-
return TERRACOTTA_LIST;
75+
return TERRACOTTAS;
6676
}
6777

6878
@Nonnull
@@ -73,19 +83,25 @@ public String getBlockKey() {
7383

7484
@Override
7585
protected boolean checkCraftConditions(BlockMenu menu) {
76-
return menu.getItemInSlot(getSelectorSlot()).getType().name().endsWith("_TERRACOTTA");
86+
return menu.getItemInSlot(getSelectorSlot()).getType().name().endsWith("TERRACOTTA");
7787
}
7888

7989
@Override
8090
protected void onCraftConditionsNotMet(BlockMenu menu) {
8191
MachineUtils.replaceExistingItemViewer(menu, getStatusSlot(), new CustomItemStack(Material.BARRIER, ChatColor.RED + "Select a terracotta to generate!"));
8292
}
8393

94+
@Nonnull
95+
@Override
96+
protected ItemStack getOutput(@Nonnull ItemStack item) {
97+
return OUTPUT_MAPPER.get(item.getType());
98+
}
99+
84100
@Nonnull
85101
@Override
86102
public List<ItemStack> getDisplayRecipes() {
87103
final List<ItemStack> displayRecipes = new ArrayList<>();
88-
for (ItemStack itemStack : TERRACOTTA_LIST) {
104+
for (ItemStack itemStack : TERRACOTTAS) {
89105
if (!itemStack.getType().name().endsWith("TERRACOTTA")) continue;
90106
displayRecipes.add(recipes.get(0).getInput()[0]);
91107
ItemStack clone = itemStack.clone();

0 commit comments

Comments
 (0)