Skip to content

Commit 8b64f09

Browse files
committed
feat(machines): add Putrifier
1 parent 17b6e22 commit 8b64f09

File tree

1 file changed

+186
-0
lines changed
  • src/main/java/me/voper/slimeframe/implementation/items/machines

1 file changed

+186
-0
lines changed
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
package me.voper.slimeframe.implementation.items.machines;
2+
3+
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
4+
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
5+
import io.github.thebusybiscuit.slimefun4.libraries.dough.inventory.InvUtils;
6+
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
7+
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
8+
import lombok.Setter;
9+
import lombok.experimental.Accessors;
10+
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
11+
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
12+
import me.voper.slimeframe.implementation.groups.Groups;
13+
import me.voper.slimeframe.implementation.items.abstracts.AbstractProcessorMachine;
14+
import me.voper.slimeframe.implementation.items.multiblocks.Foundry;
15+
import me.voper.slimeframe.utils.MachineUtils;
16+
import me.voper.slimeframe.utils.RandomItemStacks;
17+
import org.bukkit.Material;
18+
import org.bukkit.inventory.ItemStack;
19+
import org.bukkit.inventory.meta.SuspiciousStewMeta;
20+
import org.bukkit.potion.PotionEffect;
21+
import org.bukkit.potion.PotionEffectType;
22+
23+
import javax.annotation.Nonnull;
24+
import java.util.ArrayList;
25+
import java.util.HashMap;
26+
import java.util.List;
27+
import java.util.Map;
28+
import java.util.stream.Stream;
29+
30+
@Accessors(chain = true)
31+
public class Putrifier extends AbstractProcessorMachine implements RecipeDisplayItem {
32+
33+
private static final RandomItemStacks<ItemStack> SUSPICIOUS_STEWS = new RandomItemStacks<>();
34+
35+
@Setter
36+
private int production = 1;
37+
38+
public Putrifier(SlimefunItemStack item, ItemStack[] recipe) {
39+
super(Groups.MACHINES, item, Foundry.RECIPE_TYPE, recipe);
40+
}
41+
42+
@Override
43+
protected MachineRecipe findNextRecipe(@Nonnull BlockMenu menu) {
44+
// Creates a slot-ItemStack map according to the input slots
45+
Map<Integer, ItemStack> inv = new HashMap<>();
46+
47+
for (int slot : getInputSlots()) {
48+
ItemStack item = menu.getItemInSlot(slot);
49+
50+
if (item != null) {
51+
inv.put(slot, ItemStackWrapper.wrap(item));
52+
}
53+
}
54+
55+
// If the output slots are full, return null
56+
int maxedSlots = 0;
57+
for (int slot : getOutputSlots()) {
58+
ItemStack item = menu.getItemInSlot(slot);
59+
if (item != null && item.getAmount() == item.getMaxStackSize()) {
60+
maxedSlots += 1;
61+
}
62+
}
63+
if (maxedSlots == getOutputSlots().length) { return null; }
64+
65+
// For each recipe, we must check if the input actually matches the recipe input
66+
Map<Integer, Integer> found = new HashMap<>();
67+
for (MachineRecipe recipe : recipes) {
68+
for (ItemStack input : recipe.getInput()) {
69+
for (int slot : getInputSlots()) {
70+
// It also checks the amount of both items
71+
if (SlimefunUtils.isItemSimilar(inv.get(slot), input, true)) {
72+
found.put(slot, input.getAmount());
73+
break;
74+
}
75+
}
76+
}
77+
78+
if (found.size() == recipe.getInput().length) {
79+
80+
for (ItemStack stack : recipe.getInput()) {
81+
if (stack.getType() == Material.MUSHROOM_STEW) {
82+
recipe = suspiciousStewRecipe();
83+
break;
84+
}
85+
}
86+
87+
if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) {
88+
MachineUtils.replaceExistingItemViewer(menu, getStatusSlot(), MachineUtils.NO_SPACE);
89+
return null;
90+
}
91+
92+
for (Map.Entry<Integer, Integer> entry : found.entrySet()) {
93+
menu.consumeItem(entry.getKey(), entry.getValue());
94+
}
95+
96+
return recipe;
97+
} else {
98+
found.clear();
99+
}
100+
}
101+
102+
return null;
103+
}
104+
105+
private MachineRecipe suspiciousStewRecipe() {
106+
return new MachineRecipe(5, new ItemStack[]{new ItemStack(Material.MUSHROOM_STEW)}, new ItemStack[]{SUSPICIOUS_STEWS.getRandom()});
107+
}
108+
109+
@Override
110+
public void postRegister() {
111+
registerRecipe(5, new ItemStack(Material.SPIDER_EYE, 3), new ItemStack(Material.FERMENTED_SPIDER_EYE, production));
112+
registerRecipe(5, new ItemStack(Material.POTATO, 5), new ItemStack(Material.POISONOUS_POTATO, production));
113+
registerRecipe(5, new ItemStack(Material.BAKED_POTATO, 5), new ItemStack(Material.POISONOUS_POTATO, production));
114+
registerRecipe(2, new ItemStack(Material.BEEF), new ItemStack(Material.ROTTEN_FLESH, production));
115+
registerRecipe(2, new ItemStack(Material.COOKED_BEEF), new ItemStack(Material.ROTTEN_FLESH, production));
116+
registerRecipe(2, new ItemStack(Material.PORKCHOP), new ItemStack(Material.ROTTEN_FLESH, production));
117+
registerRecipe(2, new ItemStack(Material.COOKED_PORKCHOP), new ItemStack(Material.ROTTEN_FLESH, production));
118+
registerRecipe(2, new ItemStack(Material.CHICKEN), new ItemStack(Material.ROTTEN_FLESH, production));
119+
registerRecipe(2, new ItemStack(Material.COOKED_CHICKEN), new ItemStack(Material.ROTTEN_FLESH, production));
120+
registerRecipe(2, new ItemStack(Material.RABBIT), new ItemStack(Material.ROTTEN_FLESH, production));
121+
registerRecipe(2, new ItemStack(Material.COOKED_RABBIT), new ItemStack(Material.ROTTEN_FLESH, production));
122+
registerRecipe(2, new ItemStack(Material.MUTTON), new ItemStack(Material.ROTTEN_FLESH, production));
123+
registerRecipe(2, new ItemStack(Material.COOKED_MUTTON), new ItemStack(Material.ROTTEN_FLESH, production));
124+
registerRecipe(2, new ItemStack(Material.COD), new ItemStack(Material.ROTTEN_FLESH, production));
125+
registerRecipe(2, new ItemStack(Material.COOKED_COD), new ItemStack(Material.ROTTEN_FLESH, production));
126+
registerRecipe(2, new ItemStack(Material.SALMON), new ItemStack(Material.ROTTEN_FLESH, production));
127+
registerRecipe(2, new ItemStack(Material.COOKED_SALMON), new ItemStack(Material.ROTTEN_FLESH, production));
128+
registerRecipe(2, new ItemStack(Material.TROPICAL_FISH), new ItemStack(Material.ROTTEN_FLESH, production));
129+
registerRecipe(2, new ItemStack(Material.PUFFERFISH), new ItemStack(Material.ROTTEN_FLESH, production));
130+
// TODO: Update the recipes system
131+
registerRecipe(5, new ItemStack(Material.MUSHROOM_STEW), new ItemStack(Material.SUSPICIOUS_STEW));
132+
}
133+
134+
@Override
135+
protected ItemStack getProgressBar() {
136+
return new ItemStack(Material.SUSPICIOUS_STEW);
137+
}
138+
139+
@Nonnull
140+
@Override
141+
public List<ItemStack> getDisplayRecipes() {
142+
final List<ItemStack> displayRecipes = new ArrayList<>(
143+
recipes.subList(0, recipes.size() - 2).stream()
144+
.flatMap(r -> Stream.of(r.getInput()[0], r.getOutput()[0]))
145+
.toList());
146+
147+
SUSPICIOUS_STEWS.getItems().forEach(item -> {
148+
displayRecipes.add(new ItemStack(Material.MUSHROOM_STEW));
149+
displayRecipes.add(item);
150+
});
151+
152+
return displayRecipes;
153+
}
154+
155+
static {
156+
// Saturation
157+
createSuspiciousStew(PotionEffectType.SATURATION, 10, 1);
158+
// Night vision 5s
159+
createSuspiciousStew(PotionEffectType.NIGHT_VISION, 5, 1);
160+
// Fire resistance 4s
161+
createSuspiciousStew(PotionEffectType.FIRE_RESISTANCE, 4, 1);
162+
// Blindness 8s
163+
createSuspiciousStew(PotionEffectType.BLINDNESS, 8, 1);
164+
// Weakness 9s
165+
createSuspiciousStew(PotionEffectType.WEAKNESS, 9, 1);
166+
// Regeneration 8s
167+
createSuspiciousStew(PotionEffectType.REGENERATION, 8, 1);
168+
// Jump boost 6s
169+
createSuspiciousStew(PotionEffectType.JUMP, 6, 1);
170+
// Poison 12s
171+
createSuspiciousStew(PotionEffectType.POISON, 12, 1);
172+
// Wither 8s
173+
createSuspiciousStew(PotionEffectType.WITHER, 8, 1);
174+
}
175+
176+
private static void createSuspiciousStew(PotionEffectType type, int duration, int amplifier) {
177+
ItemStack stew = new ItemStack(Material.SUSPICIOUS_STEW);
178+
SuspiciousStewMeta meta = (SuspiciousStewMeta) stew.getItemMeta();
179+
if (meta != null) {
180+
meta.addCustomEffect(new PotionEffect(type, duration, amplifier), true);
181+
stew.setItemMeta(meta);
182+
}
183+
SUSPICIOUS_STEWS.add(stew);
184+
}
185+
186+
}

0 commit comments

Comments
 (0)