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

Commit 080ef87

Browse files
committed
修复部分简单机器speed不生效的问题
1 parent c6a4cdd commit 080ef87

File tree

6 files changed

+249
-6
lines changed

6 files changed

+249
-6
lines changed

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

Lines changed: 5 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,17 +49,18 @@ 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
};
63+
6564
if (instance instanceof AContainer aContainer) {
6665
aContainer.setCapacity(capacity);
6766
aContainer.setEnergyConsumption(consumption);

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
@@ -90,6 +90,11 @@ public void onPlayerPlace(@NotNull BlockPlaceEvent e) {
9090
@Override
9191
public void onPlayerBreak(
9292
@NotNull BlockBreakEvent e, @NotNull ItemStack item, @NotNull List<ItemStack> drops) {
93+
MachineOperation operation = getMachineProcessor().getOperation(e.getBlock());
94+
if (operation != null) {
95+
getMachineProcessor().endOperation(e.getBlock());
96+
}
97+
9398
CustomNoEnergyMachine.this.eval.evalFunction("onBreak", e, item, drops);
9499
}
95100
});
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+
}

0 commit comments

Comments
 (0)