Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,17 @@
<version>1.21.x-EXPERIMENTAL</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>paper-repo</id>
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>

<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>


<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
Expand Down Expand Up @@ -54,7 +49,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.6.0</version>
<configuration>
<relocations>
<relocation>
Expand Down Expand Up @@ -87,16 +82,16 @@

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.github.TheBusyBiscuit</groupId>
<groupId>com.github.Slimefun</groupId>
<artifactId>Slimefun4</artifactId>
<version>3ea21da</version>
<version>experimental-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand All @@ -109,15 +104,15 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
Expand Down
100 changes: 79 additions & 21 deletions src/main/java/io/ncbpfluffybear/slimecustomizer/SlimeCustomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,27 +263,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

SCMenu menu = new SCMenu("&6Category Namespace Guide");
menu.setSize(54);
int slot = 0;
for (ItemGroup group : Slimefun.getRegistry().getAllItemGroups()) {
ItemStack catItem = group.getItem(p).clone();
ItemMeta catMeta = catItem.getItemMeta();
List<String> catLore = catMeta.getLore();

catLore.set(catLore.size() - 1, Utils.color(
"&6ID: " + group.getKey().getNamespace() + ":" + group.getKey().getKey())
); // Replaces the "Click to Open" line
catMeta.setLore(catLore);
catItem.setItemMeta(catMeta);
menu.replaceExistingItem(slot, catItem);
menu.addMenuClickHandler(slot, ChestMenuUtils.getEmptyClickHandler());
slot++;
}
// --- FIXED: Use pagination logic instead of dumping everything into one GUI ---
List<ItemGroup> allGroups = new ArrayList<>(Slimefun.getRegistry().getAllItemGroups());
openCategoriesMenu(p, allGroups, 1);
// ----------------------------------------------------------------------------

menu.setPlayerInventoryClickable(false);
menu.setBackgroundNonClickable(true);
menu.open(p);
} else {
Utils.send(sender, "&eAll commands can be found at &9" + Links.COMMANDS);
}
Expand Down Expand Up @@ -355,6 +339,80 @@ private void populateMenu(SCMenu menu, List<Pair<String, ItemStack>> items, int

}

/**
* Handles the pagination for the categories menu.
* Prevents IndexOutOfBoundsException when there are too many Slimefun addons.
*
* @param p The player
* @param groups The list of all item groups
* @param page The current page number
*/
private void openCategoriesMenu(Player p, List<ItemGroup> groups, int page) {
SCMenu menu = new SCMenu("&6Category Namespace Guide (Page " + page + ")");
menu.setSize(54);

int itemsPerPage = 45;
int startIndex = (page - 1) * itemsPerPage;
int endIndex = Math.min(startIndex + itemsPerPage, groups.size());

int slot = 0;

for (int i = startIndex; i < endIndex; i++) {
ItemGroup group = groups.get(i);
ItemStack catItem = group.getItem(p).clone();
ItemMeta catMeta = catItem.getItemMeta();

if (catMeta != null) {
List<String> catLore = catMeta.getLore();
if (catLore == null) {
catLore = new ArrayList<>();
}

String namespaceInfo = Utils.color("&6ID: " + group.getKey().getNamespace() + ":" + group.getKey().getKey());

if (!catLore.isEmpty()) {
catLore.set(catLore.size() - 1, namespaceInfo);
} else {
catLore.add(namespaceInfo);
}
catMeta.setLore(catLore);
catItem.setItemMeta(catMeta);
}

menu.replaceExistingItem(slot, catItem);
menu.addMenuClickHandler(slot, ChestMenuUtils.getEmptyClickHandler());
slot++;
}

// Navigation Buttons
if (page > 1) {
menu.replaceExistingItem(46, CustomItemStack.create(Material.LIME_STAINED_GLASS_PANE, "&aPrevious Page"));
menu.addMenuClickHandler(46, (pl, s, is, action) -> {
openCategoriesMenu(p, groups, page - 1);
return false;
});
}

if (endIndex < groups.size()) {
menu.replaceExistingItem(52, CustomItemStack.create(Material.LIME_STAINED_GLASS_PANE, "&aNext Page"));
menu.addMenuClickHandler(52, (pl, s, is, action) -> {
openCategoriesMenu(p, groups, page + 1);
return false;
});
}

// Fill background for non-navigation slots in the bottom row
for (int i = 45; i < 54; i++) {
if (i != 46 && i != 52) {
menu.replaceExistingItem(i, ChestMenuUtils.getBackground());
}
}

menu.setPlayerInventoryClickable(false);
menu.setBackgroundNonClickable(true);
menu.open(p);
}

private ItemStack getItemOrNull(List<Pair<String, ItemStack>> items, int index) {
ItemStack item;
try {
Expand Down Expand Up @@ -399,4 +457,4 @@ public static SlimeCustomizer getInstance() {
return instance;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.LinkedHashMap;
import java.util.List;


/**
* The {@link CustomMachine} class is a generified
* {@link AContainer}.
Expand All @@ -34,17 +33,21 @@ public class CustomMachine extends AContainer implements RecipeDisplayItem {
private final ItemStack progressItem;
private final int energyConsumption;
private final int energyBuffer;

// Changed to double to support decimal multipliers
private final double speed;
private final LinkedHashMap<Pair<ItemStack[], ItemStack[]>, Integer> customRecipes;

public CustomMachine(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe,
String id, Material progressItem, int energyConsumption, int energyBuffer,
String id, Material progressItem, int energyConsumption, int energyBuffer, double speed,
LinkedHashMap<Pair<ItemStack[], ItemStack[]>, Integer> customRecipes) {
super(category, item, recipeType, recipe);

this.id = id;
this.progressItem = new ItemStack(progressItem);
this.energyConsumption = energyConsumption;
this.energyBuffer = energyBuffer;
this.speed = speed;
this.customRecipes = customRecipes;

getMachineProcessor().setProgressBar(getProgressBar());
Expand All @@ -70,19 +73,31 @@ public int getEnergyConsumption() {

@Override
public int getSpeed() {
// We return 1 here because we handle the speed calculation
// directly in the recipe registration below.
return 1;
}

// Helper method to get the raw multiplier if needed
public double getSpeedMultiplier() {
return speed;
}

@Override
protected void registerDefaultRecipes() {
if (customRecipes == null) {
return;
}

customRecipes.forEach((recipe, time) ->
registerRecipe(time, recipe.getFirstValue().clone(), recipe.getSecondValue().clone())
);

if (customRecipes == null) return;

customRecipes.forEach((recipe, time) -> {
// Calculate new time: Base Time / Speed Multiplier
// Example: 10s / 2.0 = 5s (Faster)
// Example: 10s / 0.5 = 20s (Slower)
int finalTime = (int) (time / speed);

// Ensure time is at least 1 second
if (finalTime < 1) finalTime = 1;

registerRecipe(finalTime, recipe.getFirstValue().clone(), recipe.getSecondValue().clone());
});
}

@Override
Expand Down Expand Up @@ -111,4 +126,4 @@ public List<ItemStack> getDisplayRecipes() {
public String getMachineIdentifier() {
return id;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.ncbpfluffybear.slimecustomizer.objects;

import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import org.bukkit.inventory.ItemStack;

/**
Expand All @@ -15,10 +15,19 @@
public class CustomSCItem extends SlimefunItem {

public CustomSCItem(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack output) {
super(category, item, recipeType, recipe, output);
// Force the template item to 1 to satisfy Slimefun's registry checks.
super(category, fixStackSize(item), recipeType, recipe, output);
}

public CustomSCItem(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
// Clone the item to preserve the original stack size (e.g., 6) for the recipe output,
// while the main item gets sanitized to 1 by the primary constructor.
this(category, item, recipeType, recipe, item.clone().item());
}

// Quick fix: Slimefun warns if the base item stack size is > 1.
private static SlimefunItemStack fixStackSize(SlimefunItemStack item) {
item.setAmount(1);
return item;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import org.bukkit.inventory.ItemStack;

/**
Expand All @@ -16,10 +15,20 @@
public class NPCustomSCItem extends SlimefunItem implements SCNotPlaceable {

public NPCustomSCItem(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack output) {
super(category, item, recipeType, recipe, output);
// Force the template item to 1 to satisfy Slimefun's registry checks.
// The actual desired amount is handled via the 'output' parameter.
super(category, fixStackSize(item), recipeType, recipe, output);
}

public NPCustomSCItem(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
// Clone the item to preserve the original stack size (e.g., 6) for the recipe output,
// while the main item gets sanitized to 1 by the primary constructor.
this(category, item, recipeType, recipe, item.clone().item());
}
}

// Quick fix: Slimefun warns if the base item stack size is > 1.
private static SlimefunItemStack fixStackSize(SlimefunItemStack item) {
item.setAmount(1);
return item;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import io.github.thebusybiscuit.slimefun4.libraries.commons.lang.Validate;
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand Down
Loading