Skip to content
This repository was archived by the owner on Aug 8, 2025. It is now read-only.

Commit d7e7891

Browse files
authored
Merge branch 'SlimefunReloadingProject:main' into main
2 parents 9c3a665 + 080ef87 commit d7e7891

File tree

8 files changed

+281
-6
lines changed

8 files changed

+281
-6
lines changed

src/main/java/org/lins/mmmjjkx/rykenslimefuncustomizer/factories/SimpleMachineFactory.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities.ProduceCollector;
1212
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
1313
import org.bukkit.inventory.ItemStack;
14-
import org.lins.mmmjjkx.rykenslimefuncustomizer.objects.customs.machine.sf.AdvancedAnimalGrowthAccelerator;
15-
import org.lins.mmmjjkx.rykenslimefuncustomizer.objects.customs.machine.sf.AdvancedCropGrowthAccelerator;
16-
import org.lins.mmmjjkx.rykenslimefuncustomizer.objects.customs.machine.sf.AdvancedTreeGrowthAccelerator;
14+
import org.lins.mmmjjkx.rykenslimefuncustomizer.objects.customs.machine.sf.*;
1715
import org.lins.mmmjjkx.rykenslimefuncustomizer.objects.machine.SimpleMachineType;
1816

1917
public class SimpleMachineFactory {
@@ -51,16 +49,16 @@ public static SlimefunItem create(
5149
case AUTO_ENCHANTER -> new AutoEnchanter(group, slimefunItemStack, recipeType, recipe);
5250
case AUTO_DISENCHANTER -> new AutoDisenchanter(group, slimefunItemStack, recipeType, recipe);
5351
case AUTO_DRIER -> new AutoDrier(group, slimefunItemStack, recipeType, recipe);
54-
case AUTO_BREWER -> new AutoBrewer(group, slimefunItemStack, recipeType, recipe);
52+
case AUTO_BREWER -> new AdvancedAutoBrewer(group, slimefunItemStack, recipeType, recipe, speed);
5553
case REFINERY -> new Refinery(group, slimefunItemStack, recipeType, recipe);
56-
case PRODUCE_COLLECTOR -> new ProduceCollector(group, slimefunItemStack, recipeType, recipe);
54+
case PRODUCE_COLLECTOR -> new AdvancedProduceCollector(group, slimefunItemStack, recipeType, recipe, speed);
5755
case TREE_GROWTH_ACCELERATOR -> new AdvancedTreeGrowthAccelerator(
5856
group, slimefunItemStack, recipeType, recipe, capacity, radius, consumption);
5957
case ANIMAL_GROWTH_ACCELERATOR -> new AdvancedAnimalGrowthAccelerator(
6058
group, slimefunItemStack, recipeType, recipe, capacity, radius, consumption);
6159
case CROP_GROWTH_ACCELERATOR -> new AdvancedCropGrowthAccelerator(
6260
group, slimefunItemStack, recipeType, recipe, capacity, radius, consumption, speed);
63-
case AUTO_ANVIL -> new AutoAnvil(group, repairFactor, slimefunItemStack, recipeType, recipe);
61+
case AUTO_ANVIL -> new AdvancedAutoAnvil(group, repairFactor, slimefunItemStack, recipeType, recipe, speed);
6462
};
6563

6664
if (instance instanceof AContainer aContainer) {

src/main/java/org/lins/mmmjjkx/rykenslimefuncustomizer/objects/customs/machine/CustomMachine.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public void onPlayerPlace(@NotNull BlockPlaceEvent e) {
7878
@Override
7979
public void onPlayerBreak(
8080
@NotNull BlockBreakEvent e, @NotNull ItemStack item, @NotNull List<ItemStack> drops) {
81+
MachineOperation operation = getMachineProcessor().getOperation(e.getBlock());
82+
if (operation != null) {
83+
getMachineProcessor().endOperation(e.getBlock());
84+
}
85+
8186
CustomMachine.this.eval.evalFunction("onBreak", e, item, drops);
8287
}
8388
});

src/main/java/org/lins/mmmjjkx/rykenslimefuncustomizer/objects/customs/machine/CustomNoEnergyMachine.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public void onPlayerPlace(@NotNull BlockPlaceEvent e) {
9393
@Override
9494
public void onPlayerBreak(
9595
@NotNull BlockBreakEvent e, @NotNull ItemStack item, @NotNull List<ItemStack> drops) {
96+
MachineOperation operation = getMachineProcessor().getOperation(e.getBlock());
97+
if (operation != null) {
98+
getMachineProcessor().endOperation(e.getBlock());
99+
}
100+
96101
CustomNoEnergyMachine.this.eval.evalFunction("onBreak", e, item, drops);
97102
}
98103
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.lins.mmmjjkx.rykenslimefuncustomizer.objects.customs.machine.sf;
2+
3+
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
4+
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
5+
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
6+
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
7+
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoAnvil;
8+
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
9+
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
10+
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
11+
import org.bukkit.inventory.ItemStack;
12+
import org.bukkit.inventory.meta.Damageable;
13+
import org.bukkit.inventory.meta.ItemMeta;
14+
15+
public class AdvancedAutoAnvil extends AutoAnvil {
16+
private final int repairFactor;
17+
private final int speed;
18+
19+
public AdvancedAutoAnvil(ItemGroup itemGroup, int repairFactor, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, int speed) {
20+
super(itemGroup, repairFactor, item, recipeType, recipe);
21+
22+
this.repairFactor = repairFactor;
23+
this.speed = speed;
24+
}
25+
26+
protected MachineRecipe findNextRecipe(BlockMenu menu) {
27+
for(int slot : this.getInputSlots()) {
28+
ItemStack ductTape = menu.getItemInSlot(slot == this.getInputSlots()[0] ? this.getInputSlots()[1] : this.getInputSlots()[0]);
29+
ItemStack item = menu.getItemInSlot(slot);
30+
if (item != null && item.getType().getMaxDurability() > 0 && ((Damageable)item.getItemMeta()).getDamage() > 0) {
31+
if (SlimefunUtils.isItemSimilar(ductTape, SlimefunItems.DUCT_TAPE, true, false)) {
32+
ItemStack repairedItem = this.repair(item);
33+
if (!menu.fits(repairedItem, this.getOutputSlots())) {
34+
return null;
35+
}
36+
37+
for(int inputSlot : this.getInputSlots()) {
38+
menu.consumeItem(inputSlot);
39+
}
40+
41+
return new MachineRecipe(30 / this.speed, new ItemStack[]{ductTape, item}, new ItemStack[]{repairedItem});
42+
}
43+
break;
44+
}
45+
}
46+
47+
return null;
48+
}
49+
50+
private ItemStack repair(ItemStack item) {
51+
ItemStack repaired = item.clone();
52+
ItemMeta meta = repaired.getItemMeta();
53+
short maxDurability = item.getType().getMaxDurability();
54+
int repairPercentage = 100 / this.repairFactor;
55+
short durability = (short)(((Damageable)meta).getDamage() - maxDurability / repairPercentage);
56+
if (durability < 0) {
57+
durability = 0;
58+
}
59+
60+
((Damageable)meta).setDamage(durability);
61+
repaired.setItemMeta(meta);
62+
return repaired;
63+
}
64+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package org.lins.mmmjjkx.rykenslimefuncustomizer.objects.customs.machine.sf;
2+
3+
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
4+
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
5+
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
6+
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoBrewer;
7+
import io.github.thebusybiscuit.slimefun4.libraries.dough.inventory.InvUtils;
8+
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
9+
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
10+
import org.bukkit.Material;
11+
import org.bukkit.inventory.ItemStack;
12+
import org.bukkit.inventory.meta.PotionMeta;
13+
import org.bukkit.potion.PotionData;
14+
import org.bukkit.potion.PotionType;
15+
16+
import javax.annotation.Nonnull;
17+
import javax.annotation.Nullable;
18+
import javax.annotation.ParametersAreNonnullByDefault;
19+
import java.util.EnumMap;
20+
import java.util.Map;
21+
22+
public class AdvancedAutoBrewer extends AutoBrewer {
23+
private static final Map<Material, PotionType> potionRecipes = new EnumMap<>(Material.class);
24+
private static final Map<PotionType, PotionType> fermentations = new EnumMap<>(PotionType.class);
25+
26+
private final int speed;
27+
28+
public AdvancedAutoBrewer(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, int speed) {
29+
super(itemGroup, item, recipeType, recipe);
30+
31+
this.speed = speed;
32+
}
33+
34+
@Nullable
35+
protected MachineRecipe findNextRecipe(BlockMenu menu) {
36+
ItemStack input1 = menu.getItemInSlot(this.getInputSlots()[0]);
37+
ItemStack input2 = menu.getItemInSlot(this.getInputSlots()[1]);
38+
if (input1 != null && input2 != null) {
39+
if (!this.isPotion(input1.getType()) && !this.isPotion(input2.getType())) {
40+
return null;
41+
} else {
42+
boolean isPotionInFirstSlot = this.isPotion(input1.getType());
43+
ItemStack ingredient = isPotionInFirstSlot ? input2 : input1;
44+
if (ingredient.hasItemMeta()) {
45+
return null;
46+
} else {
47+
ItemStack potionItem = isPotionInFirstSlot ? input1 : input2;
48+
PotionMeta potion = (PotionMeta)potionItem.getItemMeta();
49+
ItemStack output = this.brew(ingredient.getType(), potionItem.getType(), potion);
50+
if (output == null) {
51+
return null;
52+
} else {
53+
output.setItemMeta(potion);
54+
if (!InvUtils.fits(menu.toInventory(), output, this.getOutputSlots())) {
55+
return null;
56+
} else {
57+
for(int slot : this.getInputSlots()) {
58+
menu.consumeItem(slot);
59+
}
60+
61+
return new MachineRecipe(30 / speed, new ItemStack[]{input1, input2}, new ItemStack[]{output});
62+
}
63+
}
64+
}
65+
}
66+
} else {
67+
return null;
68+
}
69+
}
70+
71+
@ParametersAreNonnullByDefault
72+
@Nullable
73+
private ItemStack brew(Material input, Material potionType, PotionMeta potion) {
74+
PotionData data = potion.getBasePotionData();
75+
PotionType type = data.getType();
76+
if (type == PotionType.WATER) {
77+
if (input == Material.FERMENTED_SPIDER_EYE) {
78+
potion.setBasePotionData(new PotionData(PotionType.WEAKNESS, false, false));
79+
return new ItemStack(potionType);
80+
}
81+
82+
if (input == Material.NETHER_WART) {
83+
potion.setBasePotionData(new PotionData(PotionType.AWKWARD, false, false));
84+
return new ItemStack(potionType);
85+
}
86+
87+
if (potionType == Material.POTION && input == Material.GUNPOWDER) {
88+
return new ItemStack(Material.SPLASH_POTION);
89+
}
90+
91+
if (potionType == Material.SPLASH_POTION && input == Material.DRAGON_BREATH) {
92+
return new ItemStack(Material.LINGERING_POTION);
93+
}
94+
} else if (input == Material.FERMENTED_SPIDER_EYE) {
95+
PotionType fermented = fermentations.get(type);
96+
if (fermented != null) {
97+
potion.setBasePotionData(new PotionData(fermented, data.isExtended(), data.isUpgraded()));
98+
return new ItemStack(potionType);
99+
}
100+
} else {
101+
if (input == Material.REDSTONE && type.isExtendable() && !data.isUpgraded()) {
102+
potion.setBasePotionData(new PotionData(type, true, false));
103+
return new ItemStack(potionType);
104+
}
105+
106+
if (input == Material.GLOWSTONE_DUST && type.isUpgradeable() && !data.isExtended()) {
107+
potion.setBasePotionData(new PotionData(type, false, true));
108+
return new ItemStack(potionType);
109+
}
110+
111+
if (type == PotionType.AWKWARD) {
112+
PotionType potionRecipe = potionRecipes.get(input);
113+
if (potionRecipe != null) {
114+
potion.setBasePotionData(new PotionData(potionRecipe, false, false));
115+
return new ItemStack(potionType);
116+
}
117+
}
118+
}
119+
120+
return null;
121+
}
122+
123+
private boolean isPotion(@Nonnull Material mat) {
124+
return mat == Material.POTION || mat == Material.SPLASH_POTION || mat == Material.LINGERING_POTION;
125+
}
126+
127+
static {
128+
potionRecipes.put(Material.SUGAR, PotionType.SPEED);
129+
potionRecipes.put(Material.RABBIT_FOOT, PotionType.JUMP);
130+
potionRecipes.put(Material.BLAZE_POWDER, PotionType.STRENGTH);
131+
potionRecipes.put(Material.GLISTERING_MELON_SLICE, PotionType.INSTANT_HEAL);
132+
potionRecipes.put(Material.SPIDER_EYE, PotionType.POISON);
133+
potionRecipes.put(Material.GHAST_TEAR, PotionType.REGEN);
134+
potionRecipes.put(Material.MAGMA_CREAM, PotionType.FIRE_RESISTANCE);
135+
potionRecipes.put(Material.PUFFERFISH, PotionType.WATER_BREATHING);
136+
potionRecipes.put(Material.GOLDEN_CARROT, PotionType.NIGHT_VISION);
137+
potionRecipes.put(Material.TURTLE_HELMET, PotionType.TURTLE_MASTER);
138+
potionRecipes.put(Material.PHANTOM_MEMBRANE, PotionType.SLOW_FALLING);
139+
fermentations.put(PotionType.SPEED, PotionType.SLOWNESS);
140+
fermentations.put(PotionType.JUMP, PotionType.SLOWNESS);
141+
fermentations.put(PotionType.INSTANT_HEAL, PotionType.INSTANT_DAMAGE);
142+
fermentations.put(PotionType.POISON, PotionType.INSTANT_DAMAGE);
143+
fermentations.put(PotionType.NIGHT_VISION, PotionType.INVISIBILITY);
144+
}
145+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.lins.mmmjjkx.rykenslimefuncustomizer.objects.customs.machine.sf;
2+
3+
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
4+
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
5+
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
6+
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities.AnimalProduce;
7+
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities.ProduceCollector;
8+
import org.bukkit.inventory.ItemStack;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
public class AdvancedProduceCollector extends ProduceCollector {
12+
private final int speed;
13+
14+
public AdvancedProduceCollector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, int speed) {
15+
super(itemGroup, item, recipeType, recipe);
16+
17+
this.speed = speed;
18+
}
19+
20+
@Override
21+
public void addProduce(@NotNull AnimalProduce produce) {
22+
produce.setTicks(produce.getTicks() / speed);
23+
super.addProduce(produce);
24+
}
25+
}

src/main/java/org/lins/mmmjjkx/rykenslimefuncustomizer/objects/machine/MachineInfo.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,38 @@
99
import org.jetbrains.annotations.Nullable;
1010
import org.lins.mmmjjkx.rykenslimefuncustomizer.objects.customs.machine.CustomMachine;
1111

12+
/**
13+
* This data class provides access to machine data for JavaScript integration.
14+
*
15+
* @param blockMenu the menu of the machine, may be null if the machine has no GUI.
16+
* @param data the persistent data of the machine.
17+
* @param machineItem the {@link SlimefunItem} instance of the machine.
18+
* @param block the physical {@link Block} instance of the machine.
19+
* @param processor the {@link MachineProcessor} handling the machine's logic.
20+
* @param operation the current {@link MachineOperation}, ALWAYS be null so far...
21+
* @param machine the {@link CustomMachine} instance defining the machine's behavior.
22+
* @author lijinhong11
23+
*
24+
* <h3>JavaScript Usage Example:</h3>
25+
* <pre>{@code
26+
* function tick(info) {
27+
* // May be null
28+
* var menu = info.blockMenu();
29+
* // Access Java fields in JavaScript should like this:
30+
* // var yourObjectName = info.<recordName>();
31+
* // For example:
32+
* // var block = info.block();
33+
*
34+
* if (menu !== null) {
35+
* // See Slimefun API for more details
36+
* var item = blockMenu.getItemInSlot(0);
37+
* }
38+
*
39+
* // Displayed name
40+
* var itemName = info.machineItem().getItemName();
41+
* }
42+
* }</pre>
43+
*/
1244
public record MachineInfo(
1345
@Nullable BlockMenu blockMenu,
1446
Config data,

src/main/resources/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ softdepend:
166166
- DisguiseCookies
167167
- MagicXpansion
168168
- Tofu-Addons
169+
- IDreamOfEasy
169170
# Other plugins
170171
- PlaceholderAPI
171172
- NBTAPI

0 commit comments

Comments
 (0)