exploded = new HashSet<>();
+ int supply = 0;
for (Location source : generators) {
long timestamp = SlimefunPlugin.getProfiler().newEntry();
Config config = BlockStorage.getLocationInfo(source);
SlimefunItem item = SlimefunItem.getByID(config.getString("id"));
- if (item != null) {
+ if (item instanceof EnergyNetProvider) {
try {
+ EnergyNetProvider provider = (EnergyNetProvider) item;
+ int energy = provider.getGeneratedOutput(source, config);
+
+ if (provider.getCapacity() > 0) {
+ generatorsWithCapacity.put(source, provider.getCapacity());
+ String charge = config.getString("energy-charge");
+
+ if (charge != null) {
+ energy += Integer.parseInt(charge);
+ }
+ }
+
+ if (provider.willExplode(source, config)) {
+ exploded.add(source);
+ BlockStorage.clearBlockInfo(source);
+
+ Slimefun.runSync(() -> {
+ source.getBlock().setType(Material.LAVA);
+ source.getWorld().createExplosion(source, 0F, false);
+ });
+ }
+ else {
+ supply += energy;
+ }
+ }
+ catch (Exception | LinkageError t) {
+ exploded.add(source);
+ new ErrorReport(t, source, item);
+ }
+
+ long time = SlimefunPlugin.getProfiler().closeEntry(source, item, timestamp);
+ timeCallback.accept(time);
+ }
+ else if (item != null) {
+ try {
+ // This will be removed very very soon
+ // It is only here for temporary backwards compatibility
GeneratorTicker generator = item.getEnergyTicker();
+ Integer capacity = SlimefunPlugin.getRegistry().getEnergyCapacities().get(item.getID());
+
+ if (capacity != null && capacity.intValue() > 0) {
+ generatorsWithCapacity.put(source, capacity);
+ }
+
if (generator != null) {
double energy = generator.generateEnergy(source, item, config);
@@ -267,12 +307,11 @@ public class EnergyNet extends Network {
}
generators.removeAll(exploded);
-
return supply;
}
- private double tickAllCapacitors() {
- double supply = 0;
+ private int tickAllCapacitors() {
+ int supply = 0;
for (Location capacitor : storage) {
supply += ChargableBlock.getCharge(capacitor);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java
index c3ce60dfc..410ed6b0e 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java
@@ -41,7 +41,7 @@ public class Research implements Keyed {
private final NamespacedKey key;
private final int id;
- private String name;
+ private final String name;
private boolean enabled = true;
private int cost;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java
new file mode 100644
index 000000000..fef03a78a
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java
@@ -0,0 +1,242 @@
+package io.github.thebusybiscuit.slimefun4.core.services;
+
+import javax.annotation.Nullable;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+
+import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
+import kong.unirest.HttpResponse;
+import kong.unirest.JsonNode;
+import kong.unirest.Unirest;
+import kong.unirest.UnirestException;
+import me.mrCookieSlime.Slimefun.api.Slimefun;
+import org.bukkit.plugin.Plugin;
+
+/**
+ * This Class represents a Metrics Service that sends data to https://bstats.org/
+ * This data is used to analyse the usage of this {@link Plugin}.
+ *
+ * You can find more info in the README file of this Project on GitHub.
+ * Note: To start the metrics you will need to be calling {@link #start()}
+ *
+ * @author WalshyDev
+ */
+public class MetricsService {
+
+ private static final String REPO_NAME = "MetricsModule";
+ private static final String GH_API = "https://api.github.com/repos/Slimefun/" + REPO_NAME;
+ private static final String GH_RELEASES = "https://github.com/Slimefun/" + REPO_NAME + "/releases/download";
+
+ private final SlimefunPlugin plugin;
+ private final File parentFolder;
+ private final File metricsModuleFile;
+
+ private URLClassLoader moduleClassLoader;
+ private String metricVersion = null;
+ private boolean hasDownloadedUpdate = false;
+
+ static {
+ Unirest.config()
+ .concurrency(2, 1)
+ .setDefaultHeader("User-Agent", "MetricsModule Auto-Updater")
+ .setDefaultHeader("Accept", "application/vnd.github.v3+json")
+ .enableCookieManagement(false)
+ .cookieSpec("ignoreCookies");
+ }
+
+ public MetricsService(SlimefunPlugin plugin) {
+ this.plugin = plugin;
+ this.parentFolder = new File(plugin.getDataFolder(), "cache" + File.separatorChar + "modules");
+
+ if (!parentFolder.exists()) {
+ parentFolder.mkdirs();
+ }
+
+ this.metricsModuleFile = new File(parentFolder, REPO_NAME + ".jar");
+ }
+
+ /**
+ * This method loads the metric module and starts the metrics collection.
+ */
+ public void start() {
+ if (!metricsModuleFile.exists()) {
+ plugin.getLogger().info(REPO_NAME + " does not exist, downloading...");
+
+ if (!download(getLatestVersion())) {
+ plugin.getLogger().warning("Failed to start metrics as the file could not be downloaded.");
+ return;
+ }
+ }
+
+ try {
+ // Load the jar file into a child class loader using the SF PluginClassLoader
+ // as a parent.
+ moduleClassLoader = URLClassLoader.newInstance(new URL[] { metricsModuleFile.toURI().toURL() },
+ plugin.getClass().getClassLoader());
+ Class> cl = moduleClassLoader.loadClass("dev.walshy.sfmetrics.MetricsModule");
+
+ metricVersion = cl.getPackage().getImplementationVersion();
+
+ // If it has not been newly downloaded, auto-updates are on AND there's a new version
+ // then cleanup, download and start
+ if (!hasDownloadedUpdate && hasAutoUpdates() && checkForUpdate(metricVersion)
+ ) {
+ plugin.getLogger().info("Cleaning up and re-loading Metrics.");
+ cleanUp();
+ start();
+ return;
+ }
+
+ // Finally, we're good to start this.
+ Method start = cl.getDeclaredMethod("start");
+ String version = cl.getPackage().getImplementationVersion();
+
+ // This is required to be sync due to bStats.
+ Slimefun.runSync(() -> {
+ try {
+ start.invoke(null);
+ plugin.getLogger().info("Metrics build #" + version + " started.");
+ } catch (Exception e) {
+ plugin.getLogger().log(Level.WARNING, "Failed to start metrics.", e);
+ }
+ });
+ } catch (Exception e) {
+ plugin.getLogger().log(Level.WARNING,
+ "Failed to load the metrics module. Maybe the jar is corrupt?", e);
+ }
+ }
+
+ /**
+ * This will close the child classloader and mark all the resources held under this no longer
+ * in use, they will be cleaned up the next GC run.
+ */
+ public void cleanUp() {
+ try {
+ if (this.moduleClassLoader != null) {
+ this.moduleClassLoader.close();
+ }
+ } catch (IOException e) {
+ plugin.getLogger().log(Level.WARNING,
+ "Could not clean up module class loader. Some memory may have been leaked.");
+ }
+ }
+
+ /**
+ * Checks for a new update and compares it against the current version.
+ * If there is a new version available then this returns true.
+ *
+ * @param currentVersion The current version which is being used.
+ * @return True if there is an update available.
+ */
+ public boolean checkForUpdate(String currentVersion) {
+ if (currentVersion == null || !PatternUtils.NUMERIC.matcher(currentVersion).matches()) {
+ return false;
+ }
+
+ int latest = getLatestVersion();
+
+ if (latest > Integer.parseInt(currentVersion)) {
+ return download(latest);
+ }
+
+ return false;
+ }
+
+ /**
+ * Gets the latest version available as an int.
+ * This is an internal method used by {@link #checkForUpdate(String)}.
+ * If it cannot get the version for whatever reason this will return 0, effectively always
+ * being behind.
+ *
+ * @return The latest version as an integer or -1 if it failed to fetch.
+ */
+ private int getLatestVersion() {
+ try {
+ HttpResponse response = Unirest.get(GH_API + "/releases/latest")
+ .asJson();
+ if (!response.isSuccess()) return -1;
+
+ JsonNode node = response.getBody();
+
+ if (node == null) return -1;
+
+ return node.getObject().getInt("tag_name");
+ } catch (UnirestException e) {
+ plugin.getLogger().log(Level.SEVERE, "Failed to fetch latest builds for SFMetrics");
+ return -1;
+ }
+ }
+
+ /**
+ * Downloads the version specified to Slimefun's data folder.
+ *
+ * @param version The version to download.
+ */
+ private boolean download(int version) {
+ File f = new File(parentFolder, "Metrics-" + version + ".jar");
+
+ try {
+ plugin.getLogger().log(Level.INFO, "# Starting download of MetricsModule build: #{0}", version);
+
+ AtomicInteger lastPercentPosted = new AtomicInteger();
+ HttpResponse response = Unirest.get(GH_RELEASES + "/" + version
+ + "/" + REPO_NAME + ".jar")
+ .downloadMonitor((b, fileName, bytesWritten, totalBytes) -> {
+ int percent = (int) (20 * (Math.round((((double) bytesWritten / totalBytes) * 100) / 20)));
+
+ if (percent != 0 && percent != lastPercentPosted.get()) {
+ plugin.getLogger().info("# Downloading... " + percent + "% " +
+ "(" + bytesWritten + "/" + totalBytes + " bytes)");
+ lastPercentPosted.set(percent);
+ }
+ })
+ .asFile(f.getPath());
+ if (response.isSuccess()) {
+ plugin.getLogger().log(Level.INFO, "Successfully downloaded {0} build: #{1}", new Object[] {REPO_NAME, version});
+
+ // Replace the metric file with the new one
+ Files.move(f.toPath(), metricsModuleFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
+
+ metricVersion = String.valueOf(version);
+ hasDownloadedUpdate = true;
+ return true;
+ }
+ } catch (UnirestException e) {
+ plugin.getLogger().log(Level.WARNING, "Failed to fetch the latest jar file from the" +
+ " builds page. Perhaps GitHub is down.");
+ } catch (IOException e) {
+ plugin.getLogger().log(Level.WARNING, "Failed to replace the old metric file with the " +
+ "new one. Please do this manually! Error: {0}", e.getMessage());
+ }
+ return false;
+ }
+
+ /**
+ * Returns the currently downloaded metrics version.
+ * This can change! It may be null or an
+ * older version before it has downloaded a newer one.
+ *
+ * @return The current version or null if not loaded.
+ */
+ @Nullable
+ public String getVersion() {
+ return metricVersion;
+ }
+
+ /**
+ * Returns if the current server has metrics auto-updates enabled.
+ *
+ * @return True if the current server has metrics auto-updates enabled.
+ */
+ public boolean hasAutoUpdates() {
+ return SlimefunPlugin.instance().getConfig().getBoolean("metrics.auto-update");
+ }
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/ContributionsConnector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/ContributionsConnector.java
index 5f50d2783..7aea16847 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/ContributionsConnector.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/ContributionsConnector.java
@@ -6,10 +6,9 @@ import java.util.List;
import java.util.Map;
import java.util.logging.Level;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-
+import kong.unirest.JsonNode;
+import kong.unirest.json.JSONArray;
+import kong.unirest.json.JSONObject;
import me.mrCookieSlime.Slimefun.api.Slimefun;
class ContributionsConnector extends GitHubConnector {
@@ -57,10 +56,10 @@ class ContributionsConnector extends GitHubConnector {
}
@Override
- public void onSuccess(JsonElement element) {
+ public void onSuccess(JsonNode element) {
finished = true;
- if (element.isJsonArray()) {
- computeContributors(element.getAsJsonArray());
+ if (element.isArray()) {
+ computeContributors(element.getArray());
}
else {
Slimefun.getLogger().log(Level.WARNING, "Received an unusual answer from GitHub, possibly a timeout? ({0})", element);
@@ -82,13 +81,13 @@ class ContributionsConnector extends GitHubConnector {
return "/contributors?per_page=100&page=" + page;
}
- private void computeContributors(JsonArray array) {
- for (int i = 0; i < array.size(); i++) {
- JsonObject object = array.get(i).getAsJsonObject();
+ private void computeContributors(JSONArray array) {
+ for (int i = 0; i < array.length(); i++) {
+ JSONObject object = array.getJSONObject(i);
- String name = object.get("login").getAsString();
- int commits = object.get("contributions").getAsInt();
- String profile = object.get("html_url").getAsString();
+ String name = object.getString("login");
+ int commits = object.getInt("contributions");
+ String profile = object.getString("html_url");
if (!blacklist.contains(name)) {
github.addContributor(aliases.getOrDefault(name, name), profile, role, commits);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubConnector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubConnector.java
index 68e76ec42..1ab1b4149 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubConnector.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubConnector.java
@@ -6,17 +6,14 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.net.URL;
-import java.net.URLConnection;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
-
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import kong.unirest.HttpResponse;
+import kong.unirest.JsonNode;
+import kong.unirest.Unirest;
+import kong.unirest.UnirestException;
+import kong.unirest.json.JSONException;
import me.mrCookieSlime.Slimefun.api.Slimefun;
abstract class GitHubConnector {
@@ -34,7 +31,7 @@ abstract class GitHubConnector {
public abstract String getURLSuffix();
- public abstract void onSuccess(JsonElement element);
+ public abstract void onSuccess(JsonNode element);
public void onFailure() {
// Don't do anything by default
@@ -48,58 +45,54 @@ abstract class GitHubConnector {
}
try {
- URL website = new URL("https://api.github.com/repos/" + repository + getURLSuffix());
+ HttpResponse resp = Unirest.get("https://api.github.com/repos/" + repository + getURLSuffix())
+ .header("User-Agent", "Slimefun4 (https://github.com/Slimefun)")
+ .asJson();
- URLConnection connection = website.openConnection();
- connection.setConnectTimeout(8000);
- connection.addRequestProperty("Accept-Charset", "UTF-8");
- connection.addRequestProperty("User-Agent", "Slimefun 4 GitHub Agent (by TheBusyBiscuit)");
- connection.setDoOutput(true);
-
- try (ReadableByteChannel channel = Channels.newChannel(connection.getInputStream())) {
- try (FileOutputStream stream = new FileOutputStream(file)) {
- stream.getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
- parseData();
- }
+ if (resp.isSuccess()) {
+ onSuccess(resp.getBody());
+ writeCacheFile(resp.getBody());
+ }
+ else {
+ Slimefun.getLogger().log(Level.WARNING, "Failed to fetch {0}", repository + getURLSuffix());
}
}
- catch (IOException e) {
+ catch (UnirestException e) {
if (github.isLoggingEnabled()) {
Slimefun.getLogger().log(Level.WARNING, "Could not connect to GitHub in time.");
}
- if (hasData()) {
- parseData();
- }
- else {
- onFailure();
- }
- }
- }
+ // It has the cached file, let's just read that then
+ if (file.exists()) {
+ JsonNode cache = readCacheFile();
- public boolean hasData() {
- return getFile().exists();
- }
-
- public File getFile() {
- return file;
- }
-
- public void parseData() {
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(getFile()), StandardCharsets.UTF_8))) {
- StringBuilder builder = new StringBuilder();
-
- String line;
- while ((line = reader.readLine()) != null) {
- builder.append(line);
+ if (cache != null) {
+ onSuccess(cache);
+ return;
+ }
}
- JsonElement element = new JsonParser().parse(builder.toString());
- onSuccess(element);
- }
- catch (IOException x) {
- Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occurred while parsing GitHub-Data for Slimefun " + SlimefunPlugin.getVersion());
+ // If the request failed and it failed to read the cache then call onFailure.
onFailure();
}
}
+
+ private JsonNode readCacheFile() {
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
+ return new JsonNode(br.readLine());
+ }
+ catch (IOException | JSONException e) {
+ Slimefun.getLogger().log(Level.WARNING, "Failed to read Github cache file: {0}", file.getName());
+ return null;
+ }
+ }
+
+ private void writeCacheFile(JsonNode node) {
+ try (FileOutputStream fos = new FileOutputStream(file)) {
+ fos.write(node.toString().getBytes(StandardCharsets.UTF_8));
+ }
+ catch (IOException e) {
+ Slimefun.getLogger().log(Level.WARNING, "Failed to populate GitHub cache");
+ }
+ }
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubIssuesTracker.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubIssuesTracker.java
index 9686d4e92..84af62998 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubIssuesTracker.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubIssuesTracker.java
@@ -2,10 +2,9 @@ package io.github.thebusybiscuit.slimefun4.core.services.github;
import java.util.logging.Level;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-
+import kong.unirest.JsonNode;
+import kong.unirest.json.JSONArray;
+import kong.unirest.json.JSONObject;
import me.mrCookieSlime.Slimefun.api.Slimefun;
class GitHubIssuesTracker extends GitHubConnector {
@@ -25,15 +24,15 @@ class GitHubIssuesTracker extends GitHubConnector {
}
@Override
- public void onSuccess(JsonElement element) {
- if (element.isJsonArray()) {
- JsonArray array = element.getAsJsonArray();
+ public void onSuccess(JsonNode element) {
+ if (element.isArray()) {
+ JSONArray array = element.getArray();
int issues = 0;
int pullRequests = 0;
- for (JsonElement elem : array) {
- JsonObject obj = elem.getAsJsonObject();
+ for (int i = 0; i < array.length(); i++) {
+ JSONObject obj = array.getJSONObject(i);
if (obj.has("pull_request")) {
pullRequests++;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java
index 1942eeb52..77df08cc0 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java
@@ -9,14 +9,13 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-
import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.slimefun4.core.services.localization.Translators;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
+import kong.unirest.JsonNode;
+import kong.unirest.json.JSONObject;
/**
* This Service is responsible for grabbing every {@link Contributor} to this project
@@ -108,11 +107,11 @@ public class GitHubService {
connectors.add(new GitHubConnector(this, repository) {
@Override
- public void onSuccess(JsonElement element) {
- JsonObject object = element.getAsJsonObject();
- forks = object.get("forks").getAsInt();
- stars = object.get("stargazers_count").getAsInt();
- lastUpdate = NumberUtils.parseGitHubDate(object.get("pushed_at").getAsString());
+ public void onSuccess(JsonNode element) {
+ JSONObject object = element.getObject();
+ forks = object.getInt("forks");
+ stars = object.getInt("stargazers_count");
+ lastUpdate = NumberUtils.parseGitHubDate(object.getString("pushed_at"));
}
@Override
@@ -206,9 +205,7 @@ public class GitHubService {
for (Contributor contributor : contributors.values()) {
Optional uuid = contributor.getUniqueId();
- if (uuid.isPresent()) {
- uuidCache.setValue(contributor.getName(), uuid.get());
- }
+ uuid.ifPresent(value -> uuidCache.setValue(contributor.getName(), value));
if (contributor.hasTexture()) {
String texture = contributor.getTexture();
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java
index d7d9a9186..de91ac576 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java
@@ -56,9 +56,9 @@ class GitHubTask implements Runnable {
}
}
- if (requests >= MAX_REQUESTS_PER_MINUTE && SlimefunPlugin.instance != null && SlimefunPlugin.instance.isEnabled()) {
+ if (requests >= MAX_REQUESTS_PER_MINUTE && SlimefunPlugin.instance() != null && SlimefunPlugin.instance().isEnabled()) {
// Slow down API requests and wait a minute after more than x requests were made
- Bukkit.getScheduler().runTaskLaterAsynchronously(SlimefunPlugin.instance, this::grabTextures, 2 * 60 * 20L);
+ Bukkit.getScheduler().runTaskLaterAsynchronously(SlimefunPlugin.instance(), this::grabTextures, 2 * 60 * 20L);
}
for (GitHubConnector connector : gitHubService.getConnectors()) {
@@ -94,14 +94,14 @@ class GitHubTask implements Runnable {
// Retry after 5 minutes if it was rate-limiting
if (x.getMessage().contains("429")) {
- Bukkit.getScheduler().runTaskLaterAsynchronously(SlimefunPlugin.instance, this::grabTextures, 5 * 60 * 20L);
+ Bukkit.getScheduler().runTaskLaterAsynchronously(SlimefunPlugin.instance(), this::grabTextures, 5 * 60 * 20L);
}
return -1;
}
catch (TooManyRequestsException x) {
Slimefun.getLogger().log(Level.WARNING, "Received a rate-limit from mojang.com, retrying in 4 minutes");
- Bukkit.getScheduler().runTaskLaterAsynchronously(SlimefunPlugin.instance, this::grabTextures, 4 * 60 * 20L);
+ Bukkit.getScheduler().runTaskLaterAsynchronously(SlimefunPlugin.instance(), this::grabTextures, 4 * 60 * 20L);
return -1;
}
@@ -116,9 +116,7 @@ class GitHubTask implements Runnable {
if (!uuid.isPresent()) {
uuid = MinecraftAccount.getUUID(contributor.getMinecraftName());
- if (uuid.isPresent()) {
- contributor.setUniqueId(uuid.get());
- }
+ uuid.ifPresent(contributor::setUniqueId);
}
if (uuid.isPresent()) {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/AddonsChart.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/AddonsChart.java
deleted file mode 100644
index 2ed2a7d59..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/AddonsChart.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.bstats.bukkit.Metrics.AdvancedPie;
-import org.bukkit.plugin.Plugin;
-
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
-
-class AddonsChart extends AdvancedPie {
-
- AddonsChart() {
- super("installed_addons", () -> {
- Map addons = new HashMap<>();
-
- for (Plugin plugin : SlimefunPlugin.getInstalledAddons()) {
- if (plugin.isEnabled()) {
- addons.put(plugin.getName(), 1);
- }
- }
-
- return addons;
- });
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/AutoUpdaterChart.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/AutoUpdaterChart.java
deleted file mode 100644
index eba426338..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/AutoUpdaterChart.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import org.bstats.bukkit.Metrics.SimplePie;
-
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
-
-class AutoUpdaterChart extends SimplePie {
-
- AutoUpdaterChart() {
- super("auto_updates", () -> {
- boolean enabled = SlimefunPlugin.getUpdater().isEnabled();
- return enabled ? "enabled" : "disabled";
- });
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/CommandChart.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/CommandChart.java
deleted file mode 100644
index d9fc909c1..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/CommandChart.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.bstats.bukkit.Metrics.AdvancedPie;
-
-import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand;
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
-
-class CommandChart extends AdvancedPie {
-
- CommandChart() {
- super("commands_ran", () -> {
- Map commands = new HashMap<>();
-
- for (Map.Entry entry : SlimefunPlugin.getCommand().getCommandUsage().entrySet()) {
- commands.put("/sf " + entry.getKey().getName(), entry.getValue());
- }
-
- return commands;
- });
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/CompatibilityModeChart.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/CompatibilityModeChart.java
deleted file mode 100644
index 045c2657e..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/CompatibilityModeChart.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import org.bstats.bukkit.Metrics.SimplePie;
-
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
-
-class CompatibilityModeChart extends SimplePie {
-
- CompatibilityModeChart() {
- super("compatibility_mode", () -> {
- boolean enabled = SlimefunPlugin.getRegistry().isBackwardsCompatible();
- return enabled ? "enabled" : "disabled";
- });
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/GuideLayoutChart.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/GuideLayoutChart.java
deleted file mode 100644
index 75fc72b42..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/GuideLayoutChart.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import org.bstats.bukkit.Metrics.SimplePie;
-
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
-
-class GuideLayoutChart extends SimplePie {
-
- GuideLayoutChart() {
- super("guide_layout", () -> {
- boolean book = SlimefunPlugin.getCfg().getBoolean("guide.default-view-book");
-
- return book ? "Book" : "Chest GUI";
- });
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/MetricsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/MetricsService.java
deleted file mode 100644
index d6654f6a2..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/MetricsService.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import org.bstats.bukkit.Metrics;
-import org.bukkit.plugin.Plugin;
-
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
-
-/**
- * This Class represents a Metrics Service that sends data to https://bstats.org/
- * This data is used to analyse the usage of this {@link Plugin}.
- *
- * You can find more info in the README file of this Project on GitHub.
- *
- * @author TheBusyBiscuit
- *
- */
-public class MetricsService {
-
- private final SlimefunPlugin plugin;
-
- /**
- * This creates a new {@link MetricsService}. The constructor does not set up
- * anything related to bStats yet, that happens in the {@link MetricsService#start()} method.
- *
- * @param plugin
- * The instance of our {@link SlimefunPlugin}
- */
- public MetricsService(SlimefunPlugin plugin) {
- this.plugin = plugin;
- }
-
- /**
- * This method intializes and starts the metrics collection.
- */
- public void start() {
- Metrics metrics = new Metrics(plugin, 4574);
-
- if (SlimefunPlugin.getUpdater().getBranch().isOfficial()) {
- // We really do not need this data if it is an unofficially modified build...
- metrics.addCustomChart(new AutoUpdaterChart());
- }
-
- metrics.addCustomChart(new ResourcePackChart());
- metrics.addCustomChart(new SlimefunVersionChart());
- metrics.addCustomChart(new ServerLanguageChart());
- metrics.addCustomChart(new PlayerLanguageChart());
- metrics.addCustomChart(new ResearchesEnabledChart());
- metrics.addCustomChart(new GuideLayoutChart());
- metrics.addCustomChart(new AddonsChart());
- metrics.addCustomChart(new CommandChart());
- metrics.addCustomChart(new ServerSizeChart());
- metrics.addCustomChart(new CompatibilityModeChart());
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/PlayerLanguageChart.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/PlayerLanguageChart.java
deleted file mode 100644
index 347bf0640..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/PlayerLanguageChart.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.bstats.bukkit.Metrics.AdvancedPie;
-import org.bukkit.Bukkit;
-import org.bukkit.entity.Player;
-
-import io.github.thebusybiscuit.slimefun4.core.services.localization.Language;
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
-
-class PlayerLanguageChart extends AdvancedPie {
-
- PlayerLanguageChart() {
- super("player_languages", () -> {
- Map languages = new HashMap<>();
-
- for (Player p : Bukkit.getOnlinePlayers()) {
- Language language = SlimefunPlugin.getLocalization().getLanguage(p);
- boolean supported = SlimefunPlugin.getLocalization().isLanguageLoaded(language.getId());
-
- String lang = supported ? language.getId() : "Unsupported Language";
- languages.merge(lang, 1, Integer::sum);
- }
-
- return languages;
- });
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ResearchesEnabledChart.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ResearchesEnabledChart.java
deleted file mode 100644
index 87a66bf2f..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ResearchesEnabledChart.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import org.bstats.bukkit.Metrics.SimplePie;
-
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
-
-class ResearchesEnabledChart extends SimplePie {
-
- ResearchesEnabledChart() {
- super("servers_with_researches_enabled", () -> {
- boolean enabled = SlimefunPlugin.getRegistry().isFreeCreativeResearchingEnabled();
- return enabled ? "enabled" : "disabled";
- });
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ResourcePackChart.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ResourcePackChart.java
deleted file mode 100644
index 0622c6e03..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ResourcePackChart.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import org.bstats.bukkit.Metrics.SimplePie;
-
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
-
-class ResourcePackChart extends SimplePie {
-
- ResourcePackChart() {
- super("resourcepack", () -> {
- String version = SlimefunPlugin.getItemTextureService().getVersion();
-
- if (version != null && version.startsWith("v")) {
- return version + " (Official)";
- }
- else if (SlimefunPlugin.getItemTextureService().isActive()) {
- return "Custom / Modified";
- }
- else {
- return "None";
- }
- });
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ServerLanguageChart.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ServerLanguageChart.java
deleted file mode 100644
index e006eaf6d..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ServerLanguageChart.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import org.bstats.bukkit.Metrics.SimplePie;
-
-import io.github.thebusybiscuit.slimefun4.core.services.localization.Language;
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
-
-class ServerLanguageChart extends SimplePie {
-
- ServerLanguageChart() {
- super("language", () -> {
- Language language = SlimefunPlugin.getLocalization().getDefaultLanguage();
- boolean supported = SlimefunPlugin.getLocalization().isLanguageLoaded(language.getId());
- return supported ? language.getId() : "Unsupported Language";
- });
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ServerSizeChart.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ServerSizeChart.java
deleted file mode 100644
index 607859ba6..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/ServerSizeChart.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import org.bstats.bukkit.Metrics.SimplePie;
-import org.bukkit.Bukkit;
-
-class ServerSizeChart extends SimplePie {
-
- ServerSizeChart() {
- super("server_size", () -> {
- int players = Bukkit.getOnlinePlayers().size();
-
- if (players < 10) {
- return "0-10";
- }
-
- if (players < 25) {
- return "10-25";
- }
-
- if (players < 50) {
- return "25-50";
- }
-
- if (players < 100) {
- return "50-100";
- }
-
- if (players < 200) {
- return "100-200";
- }
-
- if (players < 300) {
- return "200-300";
- }
-
- return "300+";
- });
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/SlimefunVersionChart.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/SlimefunVersionChart.java
deleted file mode 100644
index 6140b60b0..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/SlimefunVersionChart.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.bstats.bukkit.Metrics.DrilldownPie;
-
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
-
-class SlimefunVersionChart extends DrilldownPie {
-
- SlimefunVersionChart() {
- super("slimefun_version", () -> {
- Map> outerMap = new HashMap<>();
- Map innerMap = new HashMap<>();
-
- innerMap.put(SlimefunPlugin.getVersion(), 1);
- outerMap.put(SlimefunPlugin.getUpdater().getBranch().getName(), innerMap);
-
- return outerMap;
- });
- }
-
-}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/package-info.java
deleted file mode 100644
index 3528603ca..000000000
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/metrics/package-info.java
+++ /dev/null
@@ -1,4 +0,0 @@
-/**
- * This package contains everything related to bStats Metrics
- */
-package io.github.thebusybiscuit.slimefun4.core.services.metrics;
\ No newline at end of file
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java
index 111ee37ad..457068e97 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/PlaceholderAPIHook.java
@@ -16,7 +16,7 @@ class PlaceholderAPIHook extends PlaceholderExpansion {
@Override
public String getAuthor() {
- return SlimefunPlugin.instance.getDescription().getAuthors().toString();
+ return SlimefunPlugin.instance().getDescription().getAuthors().toString();
}
@Override
@@ -26,7 +26,7 @@ class PlaceholderAPIHook extends PlaceholderExpansion {
@Override
public String getVersion() {
- return SlimefunPlugin.instance.getDescription().getVersion();
+ return SlimefunPlugin.instance().getDescription().getVersion();
}
@Override
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java
index 5262a1745..af5cb695e 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceSummary.java
@@ -17,23 +17,22 @@ import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
+import net.md_5.bungee.api.chat.hover.content.Content;
+import net.md_5.bungee.api.chat.hover.content.Text;
class PerformanceSummary {
// The threshold at which a Block or Chunk is significant enough to appear in /sf timings
- private static final int VISIBILITY_THRESHOLD = 280_000;
- private static final int MIN_ITEMS = 3;
- private static final int MAX_ITEMS = 10;
-
- // A minecraft server tick is 50ms and Slimefun ticks are stretched across
- // two ticks (sync and async blocks), so we use 100ms as a reference here
- static final int MAX_TICK_DURATION = 100;
+ private static final int VISIBILITY_THRESHOLD = 300_000;
+ private static final int MIN_ITEMS = 4;
+ private static final int MAX_ITEMS = 12;
private final SlimefunProfiler profiler;
private final PerformanceRating rating;
private final long totalElapsedTime;
private final int totalTickedBlocks;
private final float percentage;
+ private final int tickRate;
private final Map chunks;
private final Map plugins;
@@ -45,6 +44,7 @@ class PerformanceSummary {
this.percentage = profiler.getPercentageOfTick();
this.totalElapsedTime = totalElapsedTime;
this.totalTickedBlocks = totalTickedBlocks;
+ this.tickRate = profiler.getTickRate();
chunks = profiler.getByChunk();
plugins = profiler.getByPlugin();
@@ -54,7 +54,8 @@ class PerformanceSummary {
public void send(CommandSender sender) {
sender.sendMessage("");
sender.sendMessage(ChatColor.GREEN + "===== Slimefun Lag Profiler =====");
- sender.sendMessage(ChatColor.GOLD + "Total: " + ChatColor.YELLOW + NumberUtils.getAsMillis(totalElapsedTime));
+ sender.sendMessage(ChatColor.GOLD + "Total time: " + ChatColor.YELLOW + NumberUtils.getAsMillis(totalElapsedTime));
+ sender.sendMessage(ChatColor.GOLD + "Running every: " + ChatColor.YELLOW + NumberUtils.roundDecimalNumber(tickRate / 20.0) + "s (" + tickRate + " ticks)");
sender.sendMessage(ChatColor.GOLD + "Performance: " + getPerformanceRating());
sender.sendMessage("");
@@ -128,7 +129,8 @@ class PerformanceSummary {
builder.append("\n\n&c+ &6").append(hidden).append(" more");
}
- hoverComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(ChatColors.color(builder.toString()))));
+ Content content = new Text(TextComponent.fromLegacyText(ChatColors.color(builder.toString())));
+ hoverComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, content));
component.addExtra(hoverComponent);
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/ProfiledBlock.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/ProfiledBlock.java
index 70c5c2549..940bca213 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/ProfiledBlock.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/ProfiledBlock.java
@@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.services.profiler;
+import org.bukkit.Location;
import org.bukkit.block.Block;
import io.github.thebusybiscuit.cscorelib2.blocks.BlockPosition;
@@ -11,6 +12,11 @@ class ProfiledBlock {
private final BlockPosition position;
private final SlimefunItem item;
+ ProfiledBlock(Location l, SlimefunItem item) {
+ this.position = new BlockPosition(l);
+ this.item = item;
+ }
+
ProfiledBlock(BlockPosition position, SlimefunItem item) {
this.position = position;
this.item = item;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java
index 2f22a1f1a..fad49ad33 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java
@@ -19,7 +19,6 @@ import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
-import io.github.thebusybiscuit.cscorelib2.blocks.BlockPosition;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask;
@@ -41,7 +40,11 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
*/
public class SlimefunProfiler {
- private final ExecutorService executor = Executors.newFixedThreadPool(3);
+ // A minecraft server tick is 50ms and Slimefun ticks are stretched across
+ // two ticks (sync and async blocks), so we use 100ms as a reference here
+ private static final int MAX_TICK_DURATION = 100;
+
+ private final ExecutorService executor = Executors.newFixedThreadPool(4);
private final AtomicBoolean running = new AtomicBoolean(false);
private final AtomicInteger queued = new AtomicInteger(0);
@@ -78,8 +81,10 @@ public class SlimefunProfiler {
* Be careful to {@link #closeEntry(Location, SlimefunItem, long)} all of them again!
* No {@link PerformanceSummary} will be sent until all entires were closed.
*
+ * If the specified amount is negative, scheduled entries will be removed
+ *
* @param amount
- * The amount of entries that should be scheduled.
+ * The amount of entries that should be scheduled. Can be negative
*/
public void scheduleEntries(int amount) {
if (running.get()) {
@@ -111,8 +116,9 @@ public class SlimefunProfiler {
long elapsedTime = System.nanoTime() - timestamp;
executor.execute(() -> {
- ProfiledBlock block = new ProfiledBlock(new BlockPosition(l), item);
- timings.put(block, elapsedTime);
+ ProfiledBlock block = new ProfiledBlock(l, item);
+
+ timings.putIfAbsent(block, elapsedTime);
queued.decrementAndGet();
});
@@ -125,43 +131,53 @@ public class SlimefunProfiler {
public void stop() {
running.set(false);
- if (SlimefunPlugin.instance == null || !SlimefunPlugin.instance.isEnabled()) {
+ if (SlimefunPlugin.instance() == null || !SlimefunPlugin.instance().isEnabled()) {
// Slimefun has been disabled
return;
}
- // Since we got more than one Thread in our pool, blocking this one is completely fine
- executor.execute(() -> {
+ // Since we got more than one Thread in our pool,
+ // blocking this one is (hopefully) completely fine
+ executor.execute(this::finishReport);
+ }
- // Wait for all timing results to come in
- while (queued.get() > 0 && !running.get()) {
- try {
- Thread.sleep(1);
- }
- catch (InterruptedException e) {
- Slimefun.getLogger().log(Level.SEVERE, "A waiting Thread was interrupted", e);
- Thread.currentThread().interrupt();
+ private void finishReport() {
+ // We will only wait for a maximum of this many 1ms sleeps
+ int iterations = 1000;
+
+ // Wait for all timing results to come in
+ while (!running.get() && queued.get() > 0) {
+ try {
+ Thread.sleep(1);
+ iterations--;
+
+ // If we waited for too long, then we should just abort
+ if (iterations <= 0) {
+ return;
}
}
-
- if (running.get()) {
- // Looks like the next profiling has already started, abort!
- return;
+ catch (InterruptedException e) {
+ Slimefun.getLogger().log(Level.SEVERE, "A Profiler Thread was interrupted", e);
+ Thread.currentThread().interrupt();
}
+ }
- totalElapsedTime = timings.values().stream().mapToLong(Long::longValue).sum();
+ if (running.get() && queued.get() > 0) {
+ // Looks like the next profiling has already started, abort!
+ return;
+ }
- if (!requests.isEmpty()) {
- PerformanceSummary summary = new PerformanceSummary(this, totalElapsedTime, timings.size());
- Iterator iterator = requests.iterator();
+ totalElapsedTime = timings.values().stream().mapToLong(Long::longValue).sum();
- while (iterator.hasNext()) {
- summary.send(iterator.next());
- iterator.remove();
- }
+ if (!requests.isEmpty()) {
+ PerformanceSummary summary = new PerformanceSummary(this, totalElapsedTime, timings.size());
+ Iterator iterator = requests.iterator();
+
+ while (iterator.hasNext()) {
+ summary.send(iterator.next());
+ iterator.remove();
}
- });
-
+ }
}
/**
@@ -253,7 +269,7 @@ public class SlimefunProfiler {
protected float getPercentageOfTick() {
float millis = totalElapsedTime / 1000000.0F;
- float fraction = (millis * 100.0F) / PerformanceSummary.MAX_TICK_DURATION;
+ float fraction = (millis * 100.0F) / MAX_TICK_DURATION;
return Math.round((fraction * 100.0F) / 100.0F);
}
@@ -278,6 +294,10 @@ public class SlimefunProfiler {
return NumberUtils.getAsMillis(totalElapsedTime);
}
+ public int getTickRate() {
+ return SlimefunPlugin.getTickerTask().getTickRate();
+ }
+
/**
* This method checks whether the {@link SlimefunProfiler} has collected timings on
* the given {@link Block}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java
index 1823f1f8e..2c61892c8 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java
@@ -44,6 +44,7 @@ public final class SlimefunItems {
public static final SlimefunItemStack BROKEN_SPAWNER = new SlimefunItemStack("BROKEN_SPAWNER", Material.SPAWNER, "&cBroken Spawner", "&7Type: &b", "", "&cFractured, must be repaired in an Ancient Altar");
public static final SlimefunItemStack REPAIRED_SPAWNER = new SlimefunItemStack("REINFORCED_SPAWNER", Material.SPAWNER, "&bReinforced Spawner", "&7Type: &b");
public static final SlimefunItemStack INFERNAL_BONEMEAL = new SlimefunItemStack("INFERNAL_BONEMEAL", Material.BONE_MEAL, "&4Infernal Bonemeal", "", "&cSpeeds up the Growth of", "&cNether Warts as well");
+ public static final SlimefunItemStack TAPE_MEASURE = new SlimefunItemStack("TAPE_MEASURE", "180d5c43a6cf5bb7769fd0c8240e1e70d2ae38ef9d78a1db401aca6a2cb36f65", "&6Tape Measure", "", "&eCrouch & Right Click &7to set an anchor", "&eRight Click &7to measure");
/* Gadgets */
public static final SlimefunItemStack GOLD_PAN = new SlimefunItemStack("GOLD_PAN", Material.BOWL, "&6Gold Pan", "", "&eRight Click&7 to collect resources", "&7from Gravel");
@@ -815,6 +816,7 @@ public final class SlimefunItems {
public static final SlimefunItemStack FLUID_PUMP = new SlimefunItemStack("FLUID_PUMP", Material.BLUE_TERRACOTTA, "&9Fluid Pump", "", LoreBuilder.machine(MachineTier.ADVANCED, MachineType.MACHINE), "&8\u21E8 &e\u26A1 &732 J/Block");
public static final SlimefunItemStack CHARGING_BENCH = new SlimefunItemStack("CHARGING_BENCH", Material.CRAFTING_TABLE, "&6Charging Bench", "", "&fCharges Items such as Jetpacks", "", LoreBuilder.machine(MachineTier.BASIC, MachineType.MACHINE), LoreBuilder.powerBuffer(128), "&8\u21E8 &e\u26A1 &7Energy Loss: &c50%");
+ public static final SlimefunItemStack IRON_GOLEM_ASSEMBLER = new SlimefunItemStack("IRON_GOLEM_ASSEMBLER", Material.IRON_BLOCK, "&6Iron Golem Assembler", "", LoreBuilder.machine(MachineTier.END_GAME, MachineType.MACHINE), "&8\u21E8 &7Cooldown: &b30 Seconds", LoreBuilder.powerBuffer(4096), "&8\u21E8 &e\u26A1 &72048 J/Golem");
public static final SlimefunItemStack WITHER_ASSEMBLER = new SlimefunItemStack("WITHER_ASSEMBLER", Material.OBSIDIAN, "&5Wither Assembler", "", LoreBuilder.machine(MachineTier.END_GAME, MachineType.MACHINE), "&8\u21E8 &7Cooldown: &b30 Seconds", LoreBuilder.powerBuffer(4096), "&8\u21E8 &e\u26A1 &74096 J/Wither");
public static final SlimefunItemStack TRASH_CAN = new SlimefunItemStack("TRASH_CAN_BLOCK", HeadTexture.TRASH_CAN, "&3Trash Can", "", "&fWill destroy all Items put into it");
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java
index 85fc62f3a..b46b45f22 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java
@@ -41,12 +41,11 @@ import io.github.thebusybiscuit.slimefun4.core.services.PerWorldSettingsService;
import io.github.thebusybiscuit.slimefun4.core.services.PermissionsService;
import io.github.thebusybiscuit.slimefun4.core.services.UpdaterService;
import io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService;
-import io.github.thebusybiscuit.slimefun4.core.services.metrics.MetricsService;
+import io.github.thebusybiscuit.slimefun4.core.services.MetricsService;
import io.github.thebusybiscuit.slimefun4.core.services.plugins.ThirdPartyPluginService;
import io.github.thebusybiscuit.slimefun4.core.services.profiler.SlimefunProfiler;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler;
-import io.github.thebusybiscuit.slimefun4.implementation.items.electric.BasicCircuitBoard;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor;
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.GrapplingHook;
import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAxe;
@@ -91,6 +90,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.setup.SlimefunItemSetup
import io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator;
@@ -107,7 +107,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
*/
public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
- public static SlimefunPlugin instance;
+ private static SlimefunPlugin instance;
private MinecraftVersion minecraftVersion = MinecraftVersion.UNKNOWN;
@@ -166,6 +166,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
}
else if (getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) {
long timestamp = System.nanoTime();
+
+ PaperLib.suggestPaper(this);
// We wanna ensure that the Server uses a compatible version of Minecraft
if (isVersionUnsupported()) {
@@ -195,7 +197,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
networkManager = new NetworkManager(networkSize);
// Setting up bStats
- metricsService.start();
+ new Thread(metricsService::start).start();
// Starting the Auto-Updater
if (config.getBoolean("options.auto-update")) {
@@ -331,7 +333,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
@Override
public void onDisable() {
// Slimefun never loaded successfully, so we don't even bother doing stuff here
- if (instance == null || minecraftVersion == MinecraftVersion.UNIT_TEST) {
+ if (instance() == null || minecraftVersion == MinecraftVersion.UNIT_TEST) {
return;
}
@@ -366,6 +368,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
// Create a new backup zip
backupService.run();
+ metricsService.cleanUp();
+
// Prevent Memory Leaks
// These static Maps should be removed at some point...
AContainer.processing = null;
@@ -432,7 +436,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
new BeeListener(this);
}
- new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem());
+ new MobDropListener(this);
// Item-specific Listeners
new VampireBladeListener(this, (VampireBlade) SlimefunItems.BLADE_OF_VAMPIRES.getItem());
@@ -484,6 +488,10 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
}
}
+ public static SlimefunPlugin instance() {
+ return instance;
+ }
+
public static Config getCfg() {
return instance.config;
}
@@ -564,6 +572,16 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
return instance.updaterService;
}
+ /**
+ * This method returns the {@link MetricsService} of Slimefun.
+ * It is used to handle sending metric information to bStats.
+ *
+ * @return The {@link MetricsService} for Slimefun
+ */
+ public static MetricsService getMetricsService() {
+ return instance.metricsService;
+ }
+
/**
* This method returns the {@link GitHubService} of Slimefun.
* It is used to retrieve data from GitHub repositories.
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/BookSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/BookSlimefunGuide.java
index cac68da1f..afaa464d4 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/BookSlimefunGuide.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/BookSlimefunGuide.java
@@ -35,7 +35,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
public class BookSlimefunGuide implements SlimefunGuideImplementation {
- private final NamespacedKey guideSearch = new NamespacedKey(SlimefunPlugin.instance, "search");
+ private final NamespacedKey guideSearch = new NamespacedKey(SlimefunPlugin.instance(), "search");
@Override
public SlimefunGuideLayout getLayout() {
@@ -53,7 +53,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
}
private void openBook(Player p, PlayerProfile profile, List lines, boolean backButton) {
- CustomBookInterface book = new CustomBookInterface(SlimefunPlugin.instance);
+ CustomBookInterface book = new CustomBookInterface(SlimefunPlugin.instance());
book.setTitle(SlimefunPlugin.getLocalization().getMessage(p, "guide.title.main"));
for (int i = 0; i < lines.size(); i = i + 10) {
@@ -63,7 +63,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
header.setClickEvent(new ClickEvent(guideSearch, player -> Slimefun.runSync(() -> {
SlimefunPlugin.getLocalization().sendMessage(player, "guide.search.message");
- ChatInput.waitForPlayer(SlimefunPlugin.instance, player, msg -> SlimefunGuide.openSearch(profile, msg, true, true));
+ ChatInput.waitForPlayer(SlimefunPlugin.instance(), player, msg -> SlimefunGuide.openSearch(profile, msg, true, true));
}, 1)));
page.append(header);
@@ -77,7 +77,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
if (backButton) {
ChatComponent button = new ChatComponent(ChatColor.DARK_BLUE + "\u21E6 " + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.title"));
button.setHoverEvent(new HoverEvent(ChatColor.DARK_BLUE + "\u21E6 " + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.title"), "", ChatColor.GRAY + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.guide")));
- button.setClickEvent(new ClickEvent(new NamespacedKey(SlimefunPlugin.instance, "slimefun_guide"), pl -> openMainMenu(profile, 1)));
+ button.setClickEvent(new ClickEvent(new NamespacedKey(SlimefunPlugin.instance(), "slimefun_guide"), pl -> openMainMenu(profile, 1)));
page.append(button);
}
@@ -189,7 +189,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
}
private void appendSlimefunItem(Category category, int page, Player p, PlayerProfile profile, SlimefunItem item, List items) {
- NamespacedKey key = new NamespacedKey(SlimefunPlugin.instance, item.getID().toLowerCase(Locale.ROOT));
+ NamespacedKey key = new NamespacedKey(SlimefunPlugin.instance(), item.getID().toLowerCase(Locale.ROOT));
if (!Slimefun.hasUnlocked(p, item, false) && item.getResearch() != null) {
Research research = item.getResearch();
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java
index 6d8ead8b1..52b3670ed 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java
@@ -561,7 +561,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
pl.closeInventory();
SlimefunPlugin.getLocalization().sendMessage(pl, "guide.search.message");
- ChatInput.waitForPlayer(SlimefunPlugin.instance, pl, msg -> SlimefunGuide.openSearch(profile, msg, isSurvivalMode(), isSurvivalMode()));
+ ChatInput.waitForPlayer(SlimefunPlugin.instance(), pl, msg -> SlimefunGuide.openSearch(profile, msg, isSurvivalMode(), isSurvivalMode()));
return false;
});
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/RecipeChoiceTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/RecipeChoiceTask.java
index f48420ec3..c2facc104 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/RecipeChoiceTask.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/RecipeChoiceTask.java
@@ -31,7 +31,7 @@ class RecipeChoiceTask implements Runnable {
private Inventory inventory;
private int id;
- private Map> iterators = new HashMap<>();
+ private final Map> iterators = new HashMap<>();
/**
* This will start this task for the given {@link Inventory}.
@@ -42,7 +42,7 @@ class RecipeChoiceTask implements Runnable {
public void start(Inventory inv) {
Validate.notNull(inv, "Inventory must not be null");
inventory = inv;
- id = Bukkit.getScheduler().runTaskTimerAsynchronously(SlimefunPlugin.instance, this, 0, UPDATE_INTERVAL).getTaskId();
+ id = Bukkit.getScheduler().runTaskTimerAsynchronously(SlimefunPlugin.instance(), this, 0, UPDATE_INTERVAL).getTaskId();
}
public void add(int slot, MaterialChoice choice) {
diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SimpleSlimefunItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/SimpleSlimefunItem.java
similarity index 92%
rename from src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SimpleSlimefunItem.java
rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/SimpleSlimefunItem.java
index 690b13c58..f8ce58999 100644
--- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SimpleSlimefunItem.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/SimpleSlimefunItem.java
@@ -1,10 +1,11 @@
-package me.mrCookieSlime.Slimefun.Objects.SlimefunItem;
+package io.github.thebusybiscuit.slimefun4.implementation.items;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
+import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/altar/AncientPedestal.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/altar/AncientPedestal.java
index 8c2242596..a57fddafa 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/altar/AncientPedestal.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/altar/AncientPedestal.java
@@ -20,7 +20,7 @@ public class AncientPedestal extends SlimefunItem {
Item stack = listener.findItem(b);
if (stack != null) {
- stack.removeMetadata("no_pickup", SlimefunPlugin.instance);
+ stack.removeMetadata("no_pickup", SlimefunPlugin.instance());
b.getWorld().dropItem(b.getLocation(), listener.fixItemStack(stack.getItemStack(), stack.getCustomName()));
stack.remove();
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ButcherAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ButcherAndroid.java
index f0580738c..0c1e8ad0f 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ButcherAndroid.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ButcherAndroid.java
@@ -14,7 +14,6 @@ import org.bukkit.metadata.FixedMetadataValue;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public abstract class ButcherAndroid extends ProgrammableAndroid {
@@ -31,14 +30,14 @@ public abstract class ButcherAndroid extends ProgrammableAndroid {
}
@Override
- protected void attack(Block b, Predicate predicate) {
+ protected void attack(Block b, BlockFace face, Predicate predicate) {
double damage = getTier() >= 3 ? 20D : 4D * getTier();
double radius = 4.0 + getTier();
for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), radius, radius, radius, n -> n instanceof LivingEntity && !(n instanceof ArmorStand) && !(n instanceof Player) && n.isValid() && predicate.test((LivingEntity) n))) {
boolean attack = false;
- switch (BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"))) {
+ switch (face) {
case NORTH:
attack = n.getLocation().getZ() < b.getZ();
break;
@@ -57,10 +56,10 @@ public abstract class ButcherAndroid extends ProgrammableAndroid {
if (attack) {
if (n.hasMetadata(METADATA_KEY)) {
- n.removeMetadata(METADATA_KEY, SlimefunPlugin.instance);
+ n.removeMetadata(METADATA_KEY, SlimefunPlugin.instance());
}
- n.setMetadata(METADATA_KEY, new FixedMetadataValue(SlimefunPlugin.instance, new AndroidInstance(this, b)));
+ n.setMetadata(METADATA_KEY, new FixedMetadataValue(SlimefunPlugin.instance(), new AndroidInstance(this, b)));
((LivingEntity) n).damage(damage);
break;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java
index a2c70889b..02a24c1af 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java
@@ -83,22 +83,22 @@ enum Instruction {
// Action - Sword
ATTACK_MOBS_ANIMALS(AndroidType.FIGHTER, HeadTexture.SCRIPT_ATTACK, (android, b, inv, face) -> {
Predicate predicate = e -> true;
- android.attack(b, predicate);
+ android.attack(b, face, predicate);
}),
ATTACK_MOBS(AndroidType.FIGHTER, HeadTexture.SCRIPT_ATTACK, (android, b, inv, face) -> {
Predicate predicate = e -> e instanceof Monster;
- android.attack(b, predicate);
+ android.attack(b, face, predicate);
}),
ATTACK_ANIMALS(AndroidType.FIGHTER, HeadTexture.SCRIPT_ATTACK, (android, b, inv, face) -> {
Predicate predicate = e -> e instanceof Animals;
- android.attack(b, predicate);
+ android.attack(b, face, predicate);
}),
ATTACK_ANIMALS_ADULT(AndroidType.FIGHTER, HeadTexture.SCRIPT_ATTACK, (android, b, inv, face) -> {
Predicate predicate = e -> e instanceof Animals && e instanceof Ageable && ((Ageable) e).isAdult();
- android.attack(b, predicate);
+ android.attack(b, face, predicate);
}),
// Action - Axe
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java
index 874b13505..149614e11 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java
@@ -14,6 +14,7 @@ import org.bukkit.Sound;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Rotatable;
@@ -36,6 +37,7 @@ import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.AdvancedMenuClickHandler;
@@ -441,7 +443,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
SlimefunPlugin.getLocalization().sendMessages(p, "android.scripts.enter-name");
int id = nextId;
- ChatInput.waitForPlayer(SlimefunPlugin.instance, p, msg -> {
+ ChatInput.waitForPlayer(SlimefunPlugin.instance(), p, msg -> {
Script.upload(p, getAndroidType(), id, msg, code);
SlimefunPlugin.getLocalization().sendMessages(p, "android.scripts.uploaded");
openScriptDownloader(p, b, page);
@@ -532,7 +534,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
private void registerDefaultFuelTypes() {
switch (getFuelSource()) {
case SOLID:
- registerFuelType(new MachineFuel(800, new ItemStack(Material.COAL_BLOCK)));
+ registerFuelType(new MachineFuel(80, new ItemStack(Material.COAL_BLOCK)));
registerFuelType(new MachineFuel(45, new ItemStack(Material.BLAZE_ROD)));
registerFuelType(new MachineFuel(70, new ItemStack(Material.DRIED_KELP_BLOCK)));
@@ -689,19 +691,23 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
protected void depositItems(BlockMenu menu, Block facedBlock) {
if (facedBlock.getType() == Material.DISPENSER && BlockStorage.check(facedBlock, "ANDROID_INTERFACE_ITEMS")) {
- Dispenser d = (Dispenser) facedBlock.getState();
+ BlockState state = PaperLib.getBlockState(facedBlock, false).getState();
- for (int slot : getOutputSlots()) {
- ItemStack stack = menu.getItemInSlot(slot);
+ if (state instanceof Dispenser) {
+ Dispenser d = (Dispenser) state;
- if (stack != null) {
- Optional optional = d.getInventory().addItem(stack).values().stream().findFirst();
+ for (int slot : getOutputSlots()) {
+ ItemStack stack = menu.getItemInSlot(slot);
- if (optional.isPresent()) {
- menu.replaceExistingItem(slot, optional.get());
- }
- else {
- menu.replaceExistingItem(slot, null);
+ if (stack != null) {
+ Optional optional = d.getInventory().addItem(stack).values().stream().findFirst();
+
+ if (optional.isPresent()) {
+ menu.replaceExistingItem(slot, optional.get());
+ }
+ else {
+ menu.replaceExistingItem(slot, null);
+ }
}
}
}
@@ -710,13 +716,17 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
protected void refuel(BlockMenu menu, Block facedBlock) {
if (facedBlock.getType() == Material.DISPENSER && BlockStorage.check(facedBlock, "ANDROID_INTERFACE_FUEL")) {
- Dispenser d = (Dispenser) facedBlock.getState();
+ BlockState state = PaperLib.getBlockState(facedBlock, false).getState();
- for (int slot = 0; slot < 9; slot++) {
- ItemStack item = d.getInventory().getItem(slot);
+ if (state instanceof Dispenser) {
+ Dispenser d = (Dispenser) state;
- if (item != null) {
- insertFuel(menu, d.getInventory(), slot, menu.getItemInSlot(43), item);
+ for (int slot = 0; slot < 9; slot++) {
+ ItemStack item = d.getInventory().getItem(slot);
+
+ if (item != null) {
+ insertFuel(menu, d.getInventory(), slot, menu.getItemInSlot(43), item);
+ }
}
}
}
@@ -814,7 +824,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
}
}
- protected void attack(Block b, Predicate predicate) {
+ protected void attack(Block b, BlockFace face, Predicate predicate) {
throw new UnsupportedOperationException("Non-butcher Android tried to butcher!");
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/WoodcutterAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/WoodcutterAndroid.java
index 60c85e59e..f0900fa58 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/WoodcutterAndroid.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/WoodcutterAndroid.java
@@ -69,9 +69,7 @@ public abstract class WoodcutterAndroid extends ProgrammableAndroid {
if (log.getY() == android.getRelative(face).getY()) {
Optional sapling = MaterialConverter.getSaplingFromLog(log.getType());
- if (sapling.isPresent()) {
- log.setType(sapling.get());
- }
+ sapling.ifPresent(log::setType);
}
else {
log.setType(Material.AIR);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java
index 6cc0d0324..f50860c3b 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java
@@ -30,7 +30,7 @@ public class HazmatArmorPiece extends SlimefunArmorPiece implements ProtectiveAr
super(category, item, recipeType, recipe, effects);
types = new ProtectionType[] { ProtectionType.BEES, ProtectionType.RADIATION };
- namespacedKey = new NamespacedKey(SlimefunPlugin.instance, "hazmat_suit");
+ namespacedKey = new NamespacedKey(SlimefunPlugin.instance(), "hazmat_suit");
}
@Override
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/EnderBackpack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/EnderBackpack.java
index 288ca6c69..14f7b30fe 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/EnderBackpack.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/EnderBackpack.java
@@ -6,9 +6,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class EnderBackpack extends SimpleSlimefunItem implements NotPlaceable {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java
index 359f9fff8..5d7af79f1 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/backpacks/SlimefunBackpack.java
@@ -7,10 +7,10 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListener;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java
index 6b2f02caa..096941e03 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/BlockPlacer.java
@@ -21,9 +21,9 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
@@ -31,7 +31,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class BlockPlacer extends SimpleSlimefunItem {
- private ItemSetting> blacklist = new ItemSetting<>("unplaceable-blocks", MaterialCollections.getAllUnbreakableBlocks().stream().map(Material::name).collect(Collectors.toList()));
+ private final ItemSetting> blacklist = new ItemSetting<>("unplaceable-blocks", MaterialCollections.getAllUnbreakableBlocks().stream().map(Material::name).collect(Collectors.toList()));
public BlockPlacer(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Composter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Composter.java
index cbb7bd53c..43ac95fc8 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Composter.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Composter.java
@@ -10,6 +10,7 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -22,10 +23,11 @@ import io.github.thebusybiscuit.cscorelib2.scheduling.TaskQueue;
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
@@ -98,7 +100,7 @@ public class Composter extends SimpleSlimefunItem implements Re
pushItem(b, output.clone());
});
- tasks.execute(SlimefunPlugin.instance);
+ tasks.execute(SlimefunPlugin.instance());
}
else {
SlimefunPlugin.getLocalization().sendMessage(p, "machines.wrong-item", true);
@@ -129,10 +131,14 @@ public class Composter extends SimpleSlimefunItem implements Re
if (id != null && id.equals("OUTPUT_CHEST")) {
// Found the output chest! Now, let's check if we can fit the product in it.
- Inventory inv = ((Chest) potentialOutput.getState()).getInventory();
+ BlockState state = PaperLib.getBlockState(potentialOutput, false).getState();
- if (InvUtils.fits(inv, output)) {
- return Optional.of(inv);
+ if (state instanceof Chest) {
+ Inventory inv = ((Chest) state).getInventory();
+
+ if (InvUtils.fits(inv, output)) {
+ return Optional.of(inv);
+ }
}
}
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java
index e866be381..b87d1cfe6 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java
@@ -19,10 +19,10 @@ import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java
index 24012fc56..a57ea975c 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/EnhancedFurnace.java
@@ -7,10 +7,10 @@ import org.bukkit.block.Block;
import org.bukkit.block.Furnace;
import org.bukkit.inventory.ItemStack;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HardenedGlass.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HardenedGlass.java
new file mode 100644
index 000000000..8c947e937
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HardenedGlass.java
@@ -0,0 +1,28 @@
+package io.github.thebusybiscuit.slimefun4.implementation.items.blocks;
+
+import org.bukkit.entity.Wither;
+import org.bukkit.entity.WitherSkull;
+import org.bukkit.inventory.ItemStack;
+
+import io.github.thebusybiscuit.slimefun4.core.attributes.WitherProof;
+import me.mrCookieSlime.Slimefun.Lists.RecipeType;
+import me.mrCookieSlime.Slimefun.Objects.Category;
+import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
+
+/**
+ * {@link HardenedGlass} is a special kind of block which cannot be destroyed by explosions.
+ * It is partially {@link WitherProof}, as it cannot be destroyed through explosions caused by
+ * a {@link WitherSkull}. However the {@link Wither} is still able to destroy it directly.
+ *
+ * @author TheBusyBiscuit
+ *
+ * @see WitherProofBlock
+ *
+ */
+public class HardenedGlass extends WitherProofBlock {
+
+ public HardenedGlass(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
+ super(category, item, recipeType, recipe, recipeOutput);
+ }
+
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java
index ff09249af..c030eee2d 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java
@@ -13,13 +13,13 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/InfusedHopper.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/InfusedHopper.java
index 15ba809cd..8e98ce420 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/InfusedHopper.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/InfusedHopper.java
@@ -10,11 +10,11 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RainbowBlock.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RainbowBlock.java
index 613a72fc4..6f9c13dfc 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RainbowBlock.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RainbowBlock.java
@@ -3,9 +3,9 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.blocks;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.RainbowTickHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class RainbowBlock extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RepairedSpawner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RepairedSpawner.java
index d64ef794d..6155cbd97 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RepairedSpawner.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/RepairedSpawner.java
@@ -10,10 +10,10 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class RepairedSpawner extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/UnplaceableBlock.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/UnplaceableBlock.java
index 688d4571c..5697103a3 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/UnplaceableBlock.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/UnplaceableBlock.java
@@ -5,9 +5,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class UnplaceableBlock extends SimpleSlimefunItem implements NotPlaceable {
@@ -16,6 +16,10 @@ public class UnplaceableBlock extends SimpleSlimefunItem impleme
super(category, item, recipeType, recipe);
}
+ public UnplaceableBlock(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
+ super(category, item, recipeType, recipe, recipeOutput);
+ }
+
@Override
public ItemUseHandler getItemHandler() {
return PlayerRightClickEvent::cancel;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java
index 16da4bca6..13f46f541 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoConnectorNode.java
@@ -7,9 +7,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.core.networks.cargo.CargoNet;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class CargoConnectorNode extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java
index 29ff47e5b..bd1e20633 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/CargoManager.java
@@ -46,8 +46,6 @@ public class CargoManager extends SlimefunItem {
}, new BlockUseHandler() {
- private String visualizerKey = "visualizer";
-
@Override
public void onRightClick(PlayerRightClickEvent e) {
Optional block = e.getClickedBlock();
@@ -56,12 +54,12 @@ public class CargoManager extends SlimefunItem {
Player p = e.getPlayer();
Block b = block.get();
- if (BlockStorage.getLocationInfo(b.getLocation(), visualizerKey) == null) {
- BlockStorage.addBlockInfo(b, visualizerKey, "disabled");
+ if (BlockStorage.getLocationInfo(b.getLocation(), "visualizer") == null) {
+ BlockStorage.addBlockInfo(b, "visualizer", "disabled");
p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cCargo Net Visualizer: " + "&4\u2718"));
}
else {
- BlockStorage.addBlockInfo(b, visualizerKey, null);
+ BlockStorage.addBlockInfo(b, "visualizer", null);
p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cCargo Net Visualizer: " + "&2\u2714"));
}
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java
index 4f31246ec..899b8b937 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java
@@ -11,8 +11,8 @@ import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor;
+import io.github.thebusybiscuit.slimefun4.implementation.items.misc.CoolantCell;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
-import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@@ -74,18 +74,27 @@ public class ReactorAccessPort extends SlimefunItem {
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
- if (flow == ItemTransportFlow.INSERT) return getInputSlots();
- else return getOutputSlots();
+ if (flow == ItemTransportFlow.INSERT) {
+ return getInputSlots();
+ }
+ else {
+ return getOutputSlots();
+ }
}
@Override
public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportFlow flow, ItemStack item) {
if (flow == ItemTransportFlow.INSERT) {
- if (SlimefunUtils.isItemSimilar(item, SlimefunItems.REACTOR_COOLANT_CELL, true)) return getCoolantSlots();
- else if (SlimefunUtils.isItemSimilar(item, SlimefunItems.NETHER_ICE_COOLANT_CELL, true)) return getCoolantSlots();
- else return getFuelSlots();
+ if (SlimefunItem.getByItem(item) instanceof CoolantCell) {
+ return getCoolantSlots();
+ }
+ else {
+ return getFuelSlots();
+ }
+ }
+ else {
+ return getOutputSlots();
}
- else return getOutputSlots();
}
};
@@ -157,12 +166,11 @@ public class ReactorAccessPort extends SlimefunItem {
}
private BlockMenu getReactor(Location l) {
- Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ());
-
- SlimefunItem item = BlockStorage.check(reactorL.getBlock());
+ Location location = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ());
+ SlimefunItem item = BlockStorage.check(location.getBlock());
if (item instanceof Reactor) {
- return BlockStorage.getInventory(reactorL);
+ return BlockStorage.getInventory(location);
}
return null;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/AbstractEnergyProvider.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/AbstractEnergyProvider.java
index 8a7700f03..b6f9252b5 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/AbstractEnergyProvider.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/AbstractEnergyProvider.java
@@ -5,17 +5,19 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import org.bukkit.Location;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
-import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
+import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider;
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
+import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@@ -34,7 +36,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
* @see Reactor
*
*/
-public abstract class AbstractEnergyProvider extends SlimefunItem implements InventoryBlock, RecipeDisplayItem, EnergyNetComponent {
+public abstract class AbstractEnergyProvider extends SlimefunItem implements InventoryBlock, RecipeDisplayItem, EnergyNetProvider {
protected final Set fuelTypes = new HashSet<>();
@@ -79,13 +81,48 @@ public abstract class AbstractEnergyProvider extends SlimefunItem implements Inv
return EnergyNetComponentType.GENERATOR;
}
- protected abstract GeneratorTicker onTick();
+ /**
+ * @deprecated Please implement the methods
+ * {@link #getGeneratedOutput(org.bukkit.Location, me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config)}
+ * and {@link #willExplode(org.bukkit.Location, me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config)}
+ * instead
+ *
+ * @return A {@link GeneratorTicker}
+ */
+ @Deprecated
+ protected GeneratorTicker onTick() {
+ return null;
+ }
+
+ @Override
+ public int getGeneratedOutput(Location l, Config data) {
+ if (generatorTicker != null) {
+ return (int) generatorTicker.generateEnergy(l, this, data);
+ }
+ else {
+ return 0;
+ }
+ }
+
+ @Override
+ public boolean willExplode(Location l, Config data) {
+ if (generatorTicker != null) {
+ return generatorTicker.explode(l);
+ }
+ else {
+ return false;
+ }
+ }
@Override
public void preRegister() {
super.preRegister();
- addItemHandler(onTick());
+ GeneratorTicker ticker = onTick();
+
+ if (ticker != null) {
+ addItemHandler(ticker);
+ }
}
public void registerFuel(MachineFuel fuel) {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java
index 437f1e4d4..8cbd760a1 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/Multimeter.java
@@ -9,9 +9,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java
index f7042c789..5513058bc 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/generators/SolarGenerator.java
@@ -6,23 +6,25 @@ import org.bukkit.World.Environment;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
-import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
+import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
-import me.mrCookieSlime.Slimefun.Objects.handlers.GeneratorTicker;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
-public abstract class SolarGenerator extends SimpleSlimefunItem implements EnergyNetComponent {
+public class SolarGenerator extends SlimefunItem implements EnergyNetProvider {
- private static final int DEFAULT_NIGHT_ENERGY = 0;
+ private final int dayEnergy;
+ private final int nightEnergy;
- public SolarGenerator(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
+ public SolarGenerator(Category category, int dayEnergy, int nightEnergy, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
+
+ this.dayEnergy = dayEnergy;
+ this.nightEnergy = nightEnergy;
}
/**
@@ -31,19 +33,18 @@ public abstract class SolarGenerator extends SimpleSlimefunItem
*
* @return The amount of energy generated at daylight
*/
- public abstract double getDayEnergy();
+ public int getDayEnergy() {
+ return dayEnergy;
+ }
/**
* This method returns the amount of energy that this {@link SolarGenerator}
* produces during the night.
*
- * This is 0 by default.
- *
* @return The amount of energy generated at night time
*/
- public double getNightEnergy() {
- // Override this as necessary for highly advanced Solar Generators
- return DEFAULT_NIGHT_ENERGY;
+ public int getNightEnergy() {
+ return nightEnergy;
}
@Override
@@ -57,40 +58,29 @@ public abstract class SolarGenerator extends SimpleSlimefunItem
}
@Override
- public GeneratorTicker getItemHandler() {
- return new GeneratorTicker() {
+ public int getGeneratedOutput(Location l, Config data) {
+ World world = l.getWorld();
- @Override
- public double generateEnergy(Location l, SlimefunItem item, Config data) {
- World world = l.getWorld();
+ if (world.getEnvironment() != Environment.NORMAL) {
+ return 0;
+ }
- if (world.getEnvironment() != Environment.NORMAL) {
- return 0;
- }
+ boolean isDaytime = isDaytime(world);
- boolean isDaytime = isDaytime(world);
+ // Performance optimization for daytime-only solar generators
+ if (!isDaytime && getNightEnergy() < 0.1) {
+ return 0;
+ }
- // Performance optimization for daytime-only solar generators
- if (!isDaytime && getNightEnergy() < 0.1) {
- return 0;
- }
+ if (!world.isChunkLoaded(l.getBlockX() >> 4, l.getBlockZ() >> 4) || l.getBlock().getLightFromSky() != 15) {
+ return 0;
+ }
- if (!world.isChunkLoaded(l.getBlockX() >> 4, l.getBlockZ() >> 4) || l.getBlock().getLightFromSky() != 15) {
- return 0;
- }
+ if (isDaytime) {
+ return getDayEnergy();
+ }
- if (isDaytime) {
- return getDayEnergy();
- }
-
- return getNightEnergy();
- }
-
- @Override
- public boolean explode(Location l) {
- return false;
- }
- };
+ return getNightEnergy();
}
/**
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractEntityAssembler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractEntityAssembler.java
new file mode 100644
index 000000000..083d9a741
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractEntityAssembler.java
@@ -0,0 +1,293 @@
+package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;
+
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
+import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
+import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
+import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
+import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
+import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
+import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
+import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
+import me.mrCookieSlime.Slimefun.Lists.RecipeType;
+import me.mrCookieSlime.Slimefun.Objects.Category;
+import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
+import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
+import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
+import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
+import me.mrCookieSlime.Slimefun.api.BlockStorage;
+import me.mrCookieSlime.Slimefun.api.Slimefun;
+import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
+import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
+import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
+import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
+import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
+import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
+
+/**
+ * This is an abstract super class for Entity Assemblers.
+ *
+ * @author TheBusyBiscuit
+ *
+ * @see WitherAssembler
+ * @see IronGolemAssembler
+ *
+ */
+public abstract class AbstractEntityAssembler extends SimpleSlimefunItem implements EnergyNetComponent {
+
+ private final int[] border = { 0, 2, 3, 4, 5, 6, 8, 12, 14, 21, 23, 30, 32, 39, 40, 41 };
+ private final int[] inputSlots = { 19, 28, 25, 34 };
+
+ private final int[] headSlots = { 19, 28 };
+ private final int[] headBorder = { 9, 10, 11, 18, 20, 27, 29, 36, 37, 38 };
+
+ private final int[] bodySlots = { 25, 34 };
+ private final int[] bodyBorder = { 15, 16, 17, 24, 26, 33, 35, 42, 43, 44 };
+
+ private int lifetime = 0;
+
+ public AbstractEntityAssembler(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
+ super(category, item, recipeType, recipe);
+
+ new BlockMenuPreset(getID(), item.getImmutableMeta().getDisplayName().orElse("Entity Assembler")) {
+
+ @Override
+ public void init() {
+ for (int i : border) {
+ addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
+ }
+
+ for (int i : headBorder) {
+ addItem(i, new CustomItem(getHeadBorder(), " "), ChestMenuUtils.getEmptyClickHandler());
+ }
+
+ for (int i : bodyBorder) {
+ addItem(i, new CustomItem(getBodyBorder(), " "), ChestMenuUtils.getEmptyClickHandler());
+ }
+
+ constructMenu(this);
+ }
+
+ @Override
+ public void newInstance(BlockMenu menu, Block b) {
+ if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "enabled") == null || BlockStorage.getLocationInfo(b.getLocation(), "enabled").equals(String.valueOf(false))) {
+ menu.replaceExistingItem(22, new CustomItem(Material.GUNPOWDER, "&7Enabled: &4\u2718", "", "&e> Click to enable this Machine"));
+ menu.addMenuClickHandler(22, (p, slot, item, action) -> {
+ BlockStorage.addBlockInfo(b, "enabled", String.valueOf(true));
+ newInstance(menu, b);
+ return false;
+ });
+ }
+ else {
+ menu.replaceExistingItem(22, new CustomItem(Material.REDSTONE, "&7Enabled: &2\u2714", "", "&e> Click to disable this Machine"));
+ menu.addMenuClickHandler(22, (p, slot, item, action) -> {
+ BlockStorage.addBlockInfo(b, "enabled", String.valueOf(false));
+ newInstance(menu, b);
+ return false;
+ });
+ }
+
+ double offset = (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "offset") == null) ? 3.0F : Double.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "offset"));
+
+ menu.replaceExistingItem(31, new CustomItem(Material.PISTON, "&7Offset: &3" + offset + " Block(s)", "", "&rLeft Click: &7+0.1", "&rRight Click: &7-0.1"));
+ menu.addMenuClickHandler(31, (p, slot, item, action) -> {
+ double offsetv = DoubleHandler.fixDouble(Double.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "offset")) + (action.isRightClicked() ? -0.1F : 0.1F));
+ BlockStorage.addBlockInfo(b, "offset", String.valueOf(offsetv));
+ newInstance(menu, b);
+ return false;
+ });
+ }
+
+ @Override
+ public boolean canOpen(Block b, Player p) {
+ return p.hasPermission("slimefun.inventory.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
+ }
+
+ @Override
+ public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
+ if (flow == ItemTransportFlow.INSERT) {
+ return inputSlots;
+ }
+ else {
+ return new int[0];
+ }
+ }
+
+ @Override
+ public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportFlow flow, ItemStack item) {
+ if (flow == ItemTransportFlow.INSERT && item != null) {
+ if (item.getType() == getBody().getType()) {
+ return bodySlots;
+ }
+
+ if (item.getType() == getHead().getType()) {
+ return headSlots;
+ }
+ }
+
+ return new int[0];
+ }
+ };
+
+ registerBlockHandler(getID(), new SlimefunBlockHandler() {
+
+ @Override
+ public void onPlace(Player p, Block b, SlimefunItem item) {
+ BlockStorage.addBlockInfo(b, "offset", "3.0");
+ BlockStorage.addBlockInfo(b, "enabled", String.valueOf(false));
+ }
+
+ @Override
+ public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
+ if (reason == UnregisterReason.EXPLODE) {
+ return false;
+ }
+
+ BlockMenu inv = BlockStorage.getInventory(b);
+
+ if (inv != null) {
+ for (int slot : bodySlots) {
+ if (inv.getItemInSlot(slot) != null) {
+ b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
+ inv.replaceExistingItem(slot, null);
+ }
+ }
+
+ for (int slot : headSlots) {
+ if (inv.getItemInSlot(slot) != null) {
+ b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
+ inv.replaceExistingItem(slot, null);
+ }
+ }
+ }
+
+ return true;
+ }
+ });
+ }
+
+ @Override
+ public BlockTicker getItemHandler() {
+ return new BlockTicker() {
+
+ @Override
+ public void tick(Block b, SlimefunItem sf, Config data) {
+ if (String.valueOf(false).equals(BlockStorage.getLocationInfo(b.getLocation(), "enabled"))) {
+ return;
+ }
+
+ if (lifetime % 60 == 0 && ChargableBlock.getCharge(b) >= getEnergyConsumption()) {
+ BlockMenu menu = BlockStorage.getInventory(b);
+
+ boolean hasBody = findResource(menu, getBody(), bodySlots);
+ boolean hasHead = findResource(menu, getHead(), headSlots);
+
+ if (hasBody && hasHead) {
+ consumeResources(menu);
+
+ ChargableBlock.addCharge(b, -getEnergyConsumption());
+ double offset = Double.parseDouble(BlockStorage.getLocationInfo(b.getLocation(), "offset"));
+
+ Slimefun.runSync(() -> {
+ Location loc = new Location(b.getWorld(), b.getX() + 0.5D, b.getY() + offset, b.getZ() + 0.5D);
+ b.getWorld().spawnEntity(loc, EntityType.WITHER);
+ });
+ }
+ }
+ }
+
+ @Override
+ public void uniqueTick() {
+ lifetime++;
+ }
+
+ @Override
+ public boolean isSynchronized() {
+ return false;
+ }
+ };
+ }
+
+ private boolean findResource(BlockMenu menu, ItemStack item, int[] slots) {
+ Material resource = item.getType();
+ int required = item.getAmount();
+ int found = 0;
+
+ for (int slot : slots) {
+ if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(resource), true, false)) {
+ found += menu.getItemInSlot(slot).getAmount();
+
+ if (found > required) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ private void consumeResources(BlockMenu inv) {
+ int bodyCount = getBody().getAmount();
+ int headCount = getHead().getAmount();
+
+ for (int slot : bodySlots) {
+ if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), new ItemStack(getBody().getType()), true, false)) {
+ int amount = inv.getItemInSlot(slot).getAmount();
+
+ if (amount >= bodyCount) {
+ inv.consumeItem(slot, bodyCount);
+ break;
+ }
+ else {
+ bodyCount -= amount;
+ inv.replaceExistingItem(slot, null);
+ }
+ }
+ }
+
+ for (int slot : headSlots) {
+ if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), new ItemStack(getHead().getType()), true, false)) {
+ int amount = inv.getItemInSlot(slot).getAmount();
+
+ if (amount >= headCount) {
+ inv.consumeItem(slot, headCount);
+ break;
+ }
+ else {
+ headCount -= amount;
+ inv.replaceExistingItem(slot, null);
+ }
+ }
+ }
+ }
+
+ protected void constructMenu(BlockMenuPreset preset) {
+ preset.addItem(1, new CustomItem(getHead(), "&7Head Slot", "", "&rThis Slot accepts the head type"), ChestMenuUtils.getEmptyClickHandler());
+ preset.addItem(7, new CustomItem(getBody(), "&7Body Slot", "", "&rThis Slot accepts the body type"), ChestMenuUtils.getEmptyClickHandler());
+ preset.addItem(13, new CustomItem(Material.CLOCK, "&7Cooldown: &b30 Seconds", "", "&rThis Machine takes up to half a Minute to operate", "&rso give it some Time!"), ChestMenuUtils.getEmptyClickHandler());
+ }
+
+ @Override
+ public EnergyNetComponentType getEnergyComponentType() {
+ return EnergyNetComponentType.CONSUMER;
+ }
+
+ public abstract int getEnergyConsumption();
+
+ public abstract ItemStack getHead();
+
+ public abstract ItemStack getBody();
+
+ public abstract Material getHeadBorder();
+
+ public abstract Material getBodyBorder();
+
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java
index c405cb0f4..242e4fd75 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java
@@ -14,6 +14,7 @@ import io.github.thebusybiscuit.cscorelib2.blocks.Vein;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
@@ -21,7 +22,6 @@ import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.AdvancedMenu
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/IronGolemAssembler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/IronGolemAssembler.java
new file mode 100644
index 000000000..d5532cd3b
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/IronGolemAssembler.java
@@ -0,0 +1,66 @@
+package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;
+
+import org.bukkit.Material;
+import org.bukkit.entity.IronGolem;
+import org.bukkit.inventory.ItemStack;
+
+import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
+import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
+import me.mrCookieSlime.Slimefun.Lists.RecipeType;
+import me.mrCookieSlime.Slimefun.Objects.Category;
+import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
+import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
+
+/**
+ * The {@link IronGolemAssembler} is an electrical machine that can automatically spawn
+ * a {@link IronGolem} if the required ingredients have been provided.
+ *
+ * @author TheBusyBiscuit
+ *
+ * @see WitherAssembler
+ *
+ */
+public class IronGolemAssembler extends AbstractEntityAssembler {
+
+ public IronGolemAssembler(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
+ super(category, item, recipeType, recipe);
+ }
+
+ @Override
+ public int getCapacity() {
+ return 4096;
+ }
+
+ @Override
+ public int getEnergyConsumption() {
+ return 2048;
+ }
+
+ @Override
+ public ItemStack getHead() {
+ return new ItemStack(Material.PUMPKIN);
+ }
+
+ @Override
+ public Material getHeadBorder() {
+ return Material.ORANGE_STAINED_GLASS_PANE;
+ }
+
+ @Override
+ public ItemStack getBody() {
+ return new ItemStack(Material.IRON_BLOCK, 4);
+ }
+
+ @Override
+ public Material getBodyBorder() {
+ return Material.WHITE_STAINED_GLASS_PANE;
+ }
+
+ @Override
+ protected void constructMenu(BlockMenuPreset preset) {
+ preset.addItem(1, new CustomItem(getHead(), "&7Pumpkin Slot", "", "&rThis Slot accepts Pumpkins"), ChestMenuUtils.getEmptyClickHandler());
+ preset.addItem(7, new CustomItem(getBody(), "&7Iron Block Slot", "", "&rThis Slot accepts Iron Blocks"), ChestMenuUtils.getEmptyClickHandler());
+ preset.addItem(13, new CustomItem(Material.CLOCK, "&7Cooldown: &b30 Seconds", "", "&rThis Machine takes up to half a Minute to operate", "&rso give it some Time!"), ChestMenuUtils.getEmptyClickHandler());
+ }
+
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/WitherAssembler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/WitherAssembler.java
index 549d1f938..3cedfb251 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/WitherAssembler.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/WitherAssembler.java
@@ -1,182 +1,29 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines;
-import org.bukkit.Location;
import org.bukkit.Material;
-import org.bukkit.block.Block;
-import org.bukkit.entity.EntityType;
-import org.bukkit.entity.Player;
import org.bukkit.entity.Wither;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
-import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
-import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
-import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
-import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
-import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
-import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
-import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
-import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
-import me.mrCookieSlime.Slimefun.api.BlockStorage;
-import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
-import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
-import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
-import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
-import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
/**
* The {@link WitherAssembler} is an electrical machine that can automatically spawn
* a {@link Wither} if the required ingredients have been provided.
*
* @author TheBusyBiscuit
+ *
+ * @see IronGolemAssembler
*
*/
-public class WitherAssembler extends SimpleSlimefunItem implements EnergyNetComponent {
-
- private static final int ENERGY_CONSUMPTION = 4096;
-
- private final int[] border = { 0, 2, 3, 4, 5, 6, 8, 12, 14, 21, 23, 30, 32, 39, 40, 41 };
- private final int[] skullBorder = { 9, 10, 11, 18, 20, 27, 29, 36, 37, 38 };
- private final int[] sandBorder = { 15, 16, 17, 24, 26, 33, 35, 42, 43, 44 };
-
- private int lifetime = 0;
+public class WitherAssembler extends AbstractEntityAssembler {
public WitherAssembler(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
-
- new BlockMenuPreset(getID(), "&5Wither Assembler") {
-
- @Override
- public void init() {
- constructMenu(this);
- }
-
- @Override
- public void newInstance(BlockMenu menu, Block b) {
- if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "enabled") == null || BlockStorage.getLocationInfo(b.getLocation(), "enabled").equals(String.valueOf(false))) {
- menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.GUNPOWDER), "&7Enabled: &4\u2718", "", "&e> Click to enable this Machine"));
- menu.addMenuClickHandler(22, (p, slot, item, action) -> {
- BlockStorage.addBlockInfo(b, "enabled", String.valueOf(true));
- newInstance(menu, b);
- return false;
- });
- }
- else {
- menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.REDSTONE), "&7Enabled: &2\u2714", "", "&e> Click to disable this Machine"));
- menu.addMenuClickHandler(22, (p, slot, item, action) -> {
- BlockStorage.addBlockInfo(b, "enabled", String.valueOf(false));
- newInstance(menu, b);
- return false;
- });
- }
-
- double offset = (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "offset") == null) ? 3.0F : Double.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "offset"));
-
- menu.replaceExistingItem(31, new CustomItem(new ItemStack(Material.PISTON), "&7Offset: &3" + offset + " Block(s)", "", "&rLeft Click: &7+0.1", "&rRight Click: &7-0.1"));
- menu.addMenuClickHandler(31, (p, slot, item, action) -> {
- double offsetv = DoubleHandler.fixDouble(Double.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "offset")) + (action.isRightClicked() ? -0.1F : 0.1F));
- BlockStorage.addBlockInfo(b, "offset", String.valueOf(offsetv));
- newInstance(menu, b);
- return false;
- });
- }
-
- @Override
- public boolean canOpen(Block b, Player p) {
- return p.hasPermission("slimefun.inventory.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES);
- }
-
- @Override
- public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
- if (flow == ItemTransportFlow.INSERT) return getInputSlots();
- else return new int[0];
- }
-
- @Override
- public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportFlow flow, ItemStack item) {
- if (flow == ItemTransportFlow.INSERT) {
- if (SlimefunUtils.isItemSimilar(item, new ItemStack(Material.SOUL_SAND), true)) return getSoulSandSlots();
- else return getWitherSkullSlots();
- }
- else return new int[0];
- }
- };
-
- registerBlockHandler(getID(), new SlimefunBlockHandler() {
-
- @Override
- public void onPlace(Player p, Block b, SlimefunItem item) {
- BlockStorage.addBlockInfo(b, "offset", "3.0");
- BlockStorage.addBlockInfo(b, "enabled", String.valueOf(false));
- }
-
- @Override
- public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
- if (reason == UnregisterReason.EXPLODE) return false;
- BlockMenu inv = BlockStorage.getInventory(b);
-
- if (inv != null) {
- for (int slot : getSoulSandSlots()) {
- if (inv.getItemInSlot(slot) != null) {
- b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
- inv.replaceExistingItem(slot, null);
- }
- }
-
- for (int slot : getWitherSkullSlots()) {
- if (inv.getItemInSlot(slot) != null) {
- b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
- inv.replaceExistingItem(slot, null);
- }
- }
- }
- return true;
- }
- });
- }
-
- private void constructMenu(BlockMenuPreset preset) {
- for (int i : border) {
- preset.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
- }
-
- for (int i : skullBorder) {
- preset.addItem(i, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
- }
-
- for (int i : sandBorder) {
- preset.addItem(i, new CustomItem(Material.BROWN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
- }
-
- preset.addItem(1, new CustomItem(Material.WITHER_SKELETON_SKULL, "&7Wither Skull Slot", "", "&rThis Slot accepts Wither Skeleton Skulls"), ChestMenuUtils.getEmptyClickHandler());
- preset.addItem(7, new CustomItem(Material.SOUL_SAND, "&7Soul Sand Slot", "", "&rThis Slot accepts Soul Sand"), ChestMenuUtils.getEmptyClickHandler());
- preset.addItem(13, new CustomItem(Material.CLOCK, "&7Cooldown: &b30 Seconds", "", "&rThis Machine takes up to half a Minute to operate", "&rso give it some Time!"), ChestMenuUtils.getEmptyClickHandler());
- }
-
- public int[] getInputSlots() {
- return new int[] { 19, 28, 25, 34 };
- }
-
- public int[] getWitherSkullSlots() {
- return new int[] { 19, 28 };
- }
-
- public int[] getSoulSandSlots() {
- return new int[] { 25, 34 };
- }
-
- @Override
- public EnergyNetComponentType getEnergyComponentType() {
- return EnergyNetComponentType.CONSUMER;
}
@Override
@@ -185,93 +32,35 @@ public class WitherAssembler extends SimpleSlimefunItem implements
}
@Override
- public BlockTicker getItemHandler() {
- return new BlockTicker() {
-
- @Override
- public void tick(Block b, SlimefunItem sf, Config data) {
- if (String.valueOf(false).equals(BlockStorage.getLocationInfo(b.getLocation(), "enabled"))) {
- return;
- }
-
- if (lifetime % 60 == 0 && ChargableBlock.getCharge(b) >= ENERGY_CONSUMPTION) {
- BlockMenu menu = BlockStorage.getInventory(b);
-
- boolean soulsand = findResource(menu, Material.SOUL_SAND, 4, getSoulSandSlots());
- boolean skulls = findResource(menu, Material.WITHER_SKELETON_SKULL, 3, getWitherSkullSlots());
-
- if (soulsand && skulls) {
- consumeResources(menu);
-
- ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
- double offset = Double.parseDouble(BlockStorage.getLocationInfo(b.getLocation(), "offset"));
-
- Slimefun.runSync(() -> b.getWorld().spawnEntity(new Location(b.getWorld(), b.getX() + 0.5D, b.getY() + offset, b.getZ() + 0.5D), EntityType.WITHER));
- }
- }
- }
-
- @Override
- public void uniqueTick() {
- lifetime++;
- }
-
- @Override
- public boolean isSynchronized() {
- return false;
- }
- };
+ public int getEnergyConsumption() {
+ return 4096;
}
- private boolean findResource(BlockMenu menu, Material resource, int required, int[] slots) {
- int found = 0;
-
- for (int slot : slots) {
- if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(resource), true)) {
- found += menu.getItemInSlot(slot).getAmount();
-
- if (found > required) {
- return true;
- }
- }
- }
-
- return false;
+ @Override
+ public ItemStack getHead() {
+ return new ItemStack(Material.WITHER_SKELETON_SKULL, 3);
}
- private void consumeResources(BlockMenu inv) {
- int soulsand = 4;
- int skulls = 3;
+ @Override
+ public Material getHeadBorder() {
+ return Material.BLACK_STAINED_GLASS_PANE;
+ }
- for (int slot : getSoulSandSlots()) {
- if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), new ItemStack(Material.SOUL_SAND), true)) {
- int amount = inv.getItemInSlot(slot).getAmount();
+ @Override
+ public ItemStack getBody() {
+ return new ItemStack(Material.SOUL_SAND, 4);
+ }
- if (amount >= soulsand) {
- inv.consumeItem(slot, soulsand);
- break;
- }
- else {
- soulsand -= amount;
- inv.replaceExistingItem(slot, null);
- }
- }
- }
+ @Override
+ public Material getBodyBorder() {
+ return Material.BROWN_STAINED_GLASS_PANE;
+ }
- for (int slot : getWitherSkullSlots()) {
- if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), new ItemStack(Material.WITHER_SKELETON_SKULL), true)) {
- int amount = inv.getItemInSlot(slot).getAmount();
-
- if (amount >= skulls) {
- inv.consumeItem(slot, skulls);
- break;
- }
- else {
- skulls -= amount;
- inv.replaceExistingItem(slot, null);
- }
- }
- }
+ @Override
+ protected void constructMenu(BlockMenuPreset preset) {
+ preset.addItem(1, new CustomItem(getHead(), "&7Wither Skeleton Skull Slot", "", "&rThis Slot accepts Wither Skeleton Skulls"), ChestMenuUtils.getEmptyClickHandler());
+ preset.addItem(7, new CustomItem(getBody(), "&7Soul Sand Slot", "", "&rThis Slot accepts Soul Sand"), ChestMenuUtils.getEmptyClickHandler());
+ preset.addItem(13, new CustomItem(Material.CLOCK, "&7Cooldown: &b30 Seconds", "", "&rThis Machine takes up to half a Minute to operate", "&rso give it some Time!"), ChestMenuUtils.getEmptyClickHandler());
}
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java
index 582fd78e5..81e77ce96 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java
@@ -29,14 +29,11 @@ import io.github.thebusybiscuit.slimefun4.utils.holograms.SimpleHologram;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
-import me.mrCookieSlime.Slimefun.Objects.handlers.GeneratorTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
-import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
@@ -72,6 +69,8 @@ public abstract class Reactor extends AbstractEnergyProvider {
// No coolant border
private static final int[] border_4 = { 25, 34, 43 };
+ private final Set explosionsQueue = new HashSet<>();
+
public Reactor(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
@@ -107,7 +106,7 @@ public abstract class Reactor extends AbstractEnergyProvider {
BlockMenu port = getAccessPort(b.getLocation());
if (port != null) {
- menu.replaceExistingItem(INFO_SLOT, new CustomItem(new ItemStack(Material.GREEN_WOOL), "&7Access Port", "", "&6Detected", "", "&7> Click to view Access Port"));
+ menu.replaceExistingItem(INFO_SLOT, new CustomItem(Material.GREEN_WOOL, "&7Access Port", "", "&6Detected", "", "&7> Click to view Access Port"));
menu.addMenuClickHandler(INFO_SLOT, (p, slot, item, action) -> {
port.open(p);
newInstance(menu, b);
@@ -116,7 +115,7 @@ public abstract class Reactor extends AbstractEnergyProvider {
});
}
else {
- menu.replaceExistingItem(INFO_SLOT, new CustomItem(new ItemStack(Material.RED_WOOL), "&7Access Port", "", "&cNot detected", "", "&7Access Port must be", "&7placed 3 blocks above", "&7a reactor!"));
+ menu.replaceExistingItem(INFO_SLOT, new CustomItem(Material.RED_WOOL, "&7Access Port", "", "&cNot detected", "", "&7Access Port must be", "&7placed 3 blocks above", "&7a reactor!"));
menu.addMenuClickHandler(INFO_SLOT, (p, slot, item, action) -> {
newInstance(menu, b);
menu.open(p);
@@ -261,89 +260,86 @@ public abstract class Reactor extends AbstractEnergyProvider {
}
@Override
- protected GeneratorTicker onTick() {
- return new GeneratorTicker() {
+ public int getGeneratedOutput(Location l, Config data) {
+ BlockMenu inv = BlockStorage.getInventory(l);
+ BlockMenu accessPort = getAccessPort(l);
- private final Set explosionsQueue = new HashSet<>();
+ if (isProcessing(l)) {
+ extraTick(l);
+ int timeleft = progress.get(l);
- @Override
- public double generateEnergy(Location l, SlimefunItem sf, Config data) {
- BlockMenu inv = BlockStorage.getInventory(l);
- BlockMenu accessPort = getAccessPort(l);
- int charge = ChargableBlock.getCharge(l);
+ if (timeleft > 0) {
+ int produced = getEnergyProduction();
+ int charge = 0;
- if (isProcessing(l)) {
- extraTick(l);
- int timeleft = progress.get(l);
+ if (data.contains("energy-charge")) {
+ charge = Integer.parseInt(data.getString("energy-charge"));
+ }
- if (timeleft > 0) {
- int produced = getEnergyProduction();
- int space = getCapacity() - charge;
+ int space = getCapacity() - charge;
- if (space >= produced || !ReactorMode.GENERATOR.toString().equals(BlockStorage.getLocationInfo(l, MODE))) {
- progress.put(l, timeleft - 1);
- checkForWaterBlocks(l);
+ if (space >= produced || !ReactorMode.GENERATOR.toString().equals(BlockStorage.getLocationInfo(l, MODE))) {
+ progress.put(l, timeleft - 1);
+ checkForWaterBlocks(l);
- ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(l).getTicks(), getProgressBar());
+ ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(l).getTicks(), getProgressBar());
- if (needsCooling() && !hasEnoughCoolant(l, inv, accessPort, timeleft)) {
- explosionsQueue.add(l);
- return 0;
- }
- }
-
- if (space >= produced) {
- ChargableBlock.addCharge(l, getEnergyProduction());
- return (double) (charge + getEnergyProduction());
- }
- else {
- return charge;
- }
- }
- else {
- createByproduct(l, inv, accessPort);
- return charge;
+ if (needsCooling() && !hasEnoughCoolant(l, inv, accessPort, timeleft)) {
+ explosionsQueue.add(l);
+ return 0;
}
}
+
+ if (space >= produced) {
+ return getEnergyProduction();
+ }
else {
- burnNextFuel(l, inv, accessPort);
- return charge;
+ return 0;
}
}
-
- @Override
- public boolean explode(Location l) {
- boolean explosion = explosionsQueue.contains(l);
-
- if (explosion) {
- Slimefun.runSync(() -> {
- ReactorExplodeEvent event = new ReactorExplodeEvent(l, Reactor.this);
- Bukkit.getPluginManager().callEvent(event);
-
- BlockStorage.getInventory(l).close();
- SimpleHologram.remove(l.getBlock());
- });
-
- explosionsQueue.remove(l);
- processing.remove(l);
- progress.remove(l);
- }
-
- return explosion;
+ else {
+ createByproduct(l, inv, accessPort);
+ return 0;
}
+ }
+ else {
+ burnNextFuel(l, inv, accessPort);
+ return 0;
+ }
+ }
- private void checkForWaterBlocks(Location l) {
- Slimefun.runSync(() -> {
- // We will pick a surrounding block at random and see if this is water.
- // If it isn't, then we will make it explode.
- BlockFace randomNeighbour = WATER_BLOCKS[ThreadLocalRandom.current().nextInt(WATER_BLOCKS.length)];
+ @Override
+ public boolean willExplode(Location l, Config data) {
+ boolean explosion = explosionsQueue.contains(l);
- if (l.getBlock().getRelative(randomNeighbour).getType() != Material.WATER) {
- explosionsQueue.add(l);
- }
- });
+ if (explosion) {
+ Slimefun.runSync(() -> {
+ ReactorExplodeEvent event = new ReactorExplodeEvent(l, Reactor.this);
+ Bukkit.getPluginManager().callEvent(event);
+
+ BlockStorage.getInventory(l).close();
+ SimpleHologram.remove(l.getBlock());
+ });
+
+ explosionsQueue.remove(l);
+ processing.remove(l);
+ progress.remove(l);
+ }
+
+ return explosion;
+ }
+
+ private void checkForWaterBlocks(Location l) {
+ Slimefun.runSync(() -> {
+ // We will pick a surrounding block at random and see if this is water.
+ // If it isn't, then we will make it explode.
+ int index = ThreadLocalRandom.current().nextInt(WATER_BLOCKS.length);
+ BlockFace randomNeighbour = WATER_BLOCKS[index];
+
+ if (l.getBlock().getRelative(randomNeighbour).getType() != Material.WATER) {
+ explosionsQueue.add(l);
}
- };
+ });
}
private void createByproduct(Location l, BlockMenu inv, BlockMenu accessPort) {
@@ -404,7 +400,8 @@ public abstract class Reactor extends AbstractEnergyProvider {
if (accessPort != null) {
for (int slot : getCoolantSlots()) {
if (SlimefunUtils.isItemSimilar(accessPort.getItemInSlot(slot), getCoolant(), true)) {
- accessPort.replaceExistingItem(slot, menu.pushItem(accessPort.getItemInSlot(slot), getCoolantSlots()));
+ ItemStack remainingItem = menu.pushItem(accessPort.getItemInSlot(slot), getCoolantSlots());
+ accessPort.replaceExistingItem(slot, remainingItem);
}
}
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/DietCookie.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/DietCookie.java
index 5956b14cf..634746bf9 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/DietCookie.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/DietCookie.java
@@ -7,9 +7,9 @@ import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
/**
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/FortuneCookie.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/FortuneCookie.java
index d57ba3b2f..cb8a13a23 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/FortuneCookie.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/FortuneCookie.java
@@ -10,9 +10,9 @@ import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
import io.github.thebusybiscuit.slimefun4.core.services.LocalizationService;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MagicSugar.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MagicSugar.java
index 6e48a99bc..a09eaf31e 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MagicSugar.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MagicSugar.java
@@ -10,9 +10,9 @@ import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class MagicSugar extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java
index 36d47bfff..a0e935e5d 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MeatJerky.java
@@ -4,9 +4,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
/**
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MonsterJerky.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MonsterJerky.java
index 8377f6ff0..1766b481f 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MonsterJerky.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/food/MonsterJerky.java
@@ -5,9 +5,9 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOScanner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOScanner.java
index 2b0834283..de00637ad 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOScanner.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOScanner.java
@@ -5,9 +5,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class GEOScanner extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/OilPump.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/OilPump.java
index 6996a3d87..721020aa2 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/OilPump.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/OilPump.java
@@ -36,7 +36,7 @@ public abstract class OilPump extends AContainer implements RecipeDisplayItem {
public OilPump(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
- oil = SlimefunPlugin.getRegistry().getGEOResources().get(new NamespacedKey(SlimefunPlugin.instance, "oil")).orElse(null);
+ oil = SlimefunPlugin.getRegistry().getGEOResources().get(new NamespacedKey(SlimefunPlugin.instance(), "oil")).orElse(null);
new BlockMenuPreset(getID(), getInventoryTitle()) {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/PortableGEOScanner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/PortableGEOScanner.java
index 1a30b19e4..19975c36a 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/PortableGEOScanner.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/PortableGEOScanner.java
@@ -7,9 +7,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class PortableGEOScanner extends SimpleSlimefunItem {
@@ -24,9 +24,7 @@ public class PortableGEOScanner extends SimpleSlimefunItem {
Optional block = e.getClickedBlock();
e.cancel();
- if (block.isPresent()) {
- SlimefunPlugin.getGPSNetwork().getResourceManager().scan(e.getPlayer(), block.get(), 0);
- }
+ block.ifPresent(value -> SlimefunPlugin.getGPSNetwork().getResourceManager().scan(e.getPlayer(), value, 0));
};
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java
index b411cc895..1495378dd 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java
@@ -22,12 +22,13 @@ import io.github.thebusybiscuit.cscorelib2.chat.json.HoverEvent;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
@@ -96,7 +97,7 @@ public class ElevatorPlate extends SimpleSlimefunItem {
return;
}
- CustomBookInterface book = new CustomBookInterface(SlimefunPlugin.instance);
+ CustomBookInterface book = new CustomBookInterface(SlimefunPlugin.instance());
ChatComponent page = null;
List floors = getFloors(b);
@@ -119,13 +120,13 @@ public class ElevatorPlate extends SimpleSlimefunItem {
ChatComponent line;
if (block.getY() == b.getY()) {
- line = new ChatComponent("\n" + ChatColor.GRAY + "> " + (floors.size() - i) + ". " + ChatColor.RESET + floor);
- line.setHoverEvent(new HoverEvent(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.current-floor")), "", ChatColor.RESET + floor, ""));
+ line = new ChatComponent("\n" + ChatColor.GRAY + "> " + (floors.size() - i) + ". " + ChatColor.BLACK + floor);
+ line.setHoverEvent(new HoverEvent(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.current-floor")), "", ChatColor.WHITE + floor, ""));
}
else {
- line = new ChatComponent("\n" + ChatColor.GRAY.toString() + (floors.size() - i) + ". " + ChatColor.RESET + floor);
- line.setHoverEvent(new HoverEvent(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.click-to-teleport")), "", ChatColor.RESET + floor, ""));
- line.setClickEvent(new ClickEvent(new NamespacedKey(SlimefunPlugin.instance, DATA_KEY + i), player -> Slimefun.runSync(() -> {
+ line = new ChatComponent("\n" + ChatColor.GRAY + (floors.size() - i) + ". " + ChatColor.BLACK + floor);
+ line.setHoverEvent(new HoverEvent(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.click-to-teleport")), "", ChatColor.WHITE + floor, ""));
+ line.setClickEvent(new ClickEvent(new NamespacedKey(SlimefunPlugin.instance(), DATA_KEY + i), player -> Slimefun.runSync(() -> {
users.add(player.getUniqueId());
float yaw = player.getEyeLocation().getYaw() + 180;
@@ -134,8 +135,12 @@ public class ElevatorPlate extends SimpleSlimefunItem {
yaw = -180 + (yaw - 180);
}
- player.teleport(new Location(player.getWorld(), block.getX() + 0.5, block.getY() + 0.4, block.getZ() + 0.5, yaw, player.getEyeLocation().getPitch()));
- player.sendTitle(ChatColor.RESET + ChatColors.color(floor), " ", 20, 60, 20);
+ Location destination = new Location(player.getWorld(), block.getX() + 0.5, block.getY() + 0.4, block.getZ() + 0.5, yaw, player.getEyeLocation().getPitch());
+ PaperLib.teleportAsync(player, destination).thenAccept(teleported -> {
+ if (teleported.booleanValue()) {
+ player.sendTitle(ChatColor.WHITE + ChatColors.color(floor), null, 20, 60, 20);
+ }
+ });
})));
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSControlPanel.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSControlPanel.java
index 57323e3d7..4d11de893 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSControlPanel.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSControlPanel.java
@@ -4,9 +4,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class GPSControlPanel extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSMarkerTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSMarkerTool.java
index 9cba1fbe4..b19fd4c0b 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSMarkerTool.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSMarkerTool.java
@@ -6,9 +6,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class GPSMarkerTool extends SimpleSlimefunItem implements NotPlaceable {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSTransmitter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSTransmitter.java
index d96be8f1f..ef66e79c0 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSTransmitter.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/GPSTransmitter.java
@@ -9,11 +9,11 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfernalBonemeal.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfernalBonemeal.java
index 28b7a88d5..f10c86655 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfernalBonemeal.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/InfernalBonemeal.java
@@ -12,9 +12,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class InfernalBonemeal extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeFlask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeFlask.java
index 72d6fa168..99744102d 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeFlask.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeFlask.java
@@ -7,9 +7,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeTome.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeTome.java
index 7a32c1eae..ed923bc6d 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeTome.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/KnowledgeTome.java
@@ -17,9 +17,9 @@ import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.core.researching.Research;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class KnowledgeTome extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicEyeOfEnder.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicEyeOfEnder.java
index 810d53f31..b8163c176 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicEyeOfEnder.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicEyeOfEnder.java
@@ -8,10 +8,10 @@ import org.bukkit.inventory.PlayerInventory;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class MagicEyeOfEnder extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java
index 1882e63c7..b14be25e1 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/MagicalZombiePills.java
@@ -10,9 +10,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.core.handlers.EntityInteractHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java
index eb07c0540..c9f33c4e5 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java
@@ -14,10 +14,10 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.attributes.Soulbound;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemDropHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java
index 0d649de9f..8e14f1ed1 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/StormStaff.java
@@ -20,9 +20,9 @@ import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
@@ -37,7 +37,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
*/
public class StormStaff extends SimpleSlimefunItem {
- private static final NamespacedKey usageKey = new NamespacedKey(SlimefunPlugin.instance, "stormstaff_usage");
+ private static final NamespacedKey usageKey = new NamespacedKey(SlimefunPlugin.instance(), "stormstaff_usage");
public static final int MAX_USES = 8;
public StormStaff(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java
index 4a7f227e4..be4d3ed4f 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/TelepositionScroll.java
@@ -8,9 +8,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WaterStaff.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WaterStaff.java
index f81147741..ca0f26c6d 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WaterStaff.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WaterStaff.java
@@ -5,9 +5,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WindStaff.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WindStaff.java
index ddf53c80f..6c07381ac 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WindStaff.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/WindStaff.java
@@ -11,9 +11,9 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class WindStaff extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/EnderTalisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/EnderTalisman.java
index 4790a6a1d..ee66d564f 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/EnderTalisman.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/EnderTalisman.java
@@ -19,7 +19,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
*/
class EnderTalisman extends Talisman {
- private static final LockedCategory ENDER_TALISMANS_CATEGORY = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance, "ender_talismans"), new CustomItem(SlimefunItems.ENDER_TALISMAN, "&7Talismans - &aTier II"), 3, Talisman.TALISMANS_CATEGORY.getKey());
+ private static final LockedCategory ENDER_TALISMANS_CATEGORY = new LockedCategory(new NamespacedKey(SlimefunPlugin.instance(), "ender_talismans"), new CustomItem(SlimefunItems.ENDER_TALISMAN, "&7Talismans - &aTier II"), 3, Talisman.TALISMANS_CATEGORY.getKey());
public EnderTalisman(Talisman parent, SlimefunItemStack item) {
super(ENDER_TALISMANS_CATEGORY, item, new ItemStack[] { SlimefunItems.ENDER_LUMP_3, null, SlimefunItems.ENDER_LUMP_3, null, parent.getItem(), null, SlimefunItems.ENDER_LUMP_3, null, SlimefunItems.ENDER_LUMP_3 }, parent.isConsumable(), parent.isEventCancelled(), parent.getMessageSuffix(), parent.getChance(), parent.getEffects());
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java
index e5a945025..e0a58a0da 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java
@@ -31,7 +31,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class Talisman extends SlimefunItem {
- protected static final Category TALISMANS_CATEGORY = new Category(new NamespacedKey(SlimefunPlugin.instance, "talismans"), new CustomItem(SlimefunItems.COMMON_TALISMAN, "&7Talismans - &aTier I"), 2);
+ protected static final Category TALISMANS_CATEGORY = new Category(new NamespacedKey(SlimefunPlugin.instance(), "talismans"), new CustomItem(SlimefunItems.COMMON_TALISMAN, "&7Talismans - &aTier I"), 2);
private final SlimefunItemStack enderTalisman;
@@ -117,7 +117,7 @@ public class Talisman extends SlimefunItem {
protected void createEnderTalisman() {
EnderTalisman talisman = (EnderTalisman) SlimefunItem.getByItem(getEnderVariant());
- Optional research = Research.getResearch(new NamespacedKey(SlimefunPlugin.instance, "ender_talismans"));
+ Optional research = Research.getResearch(new NamespacedKey(SlimefunPlugin.instance(), "ender_talismans"));
if (talisman != null && research.isPresent()) {
talisman.setResearch(research.get());
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java
index 8b9f68f9d..33235a6a3 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java
@@ -11,9 +11,9 @@ import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class Bandage extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Medicine.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Medicine.java
index 1fa813917..8d42e4b7e 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Medicine.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Medicine.java
@@ -4,9 +4,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class Medicine extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Rag.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Rag.java
index 772faed29..2d314ee86 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Rag.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Rag.java
@@ -11,9 +11,9 @@ import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class Rag extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java
index ec417312c..7518fd402 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java
@@ -10,9 +10,9 @@ import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class Splint extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Vitamins.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Vitamins.java
index fc9fd4261..2b7240427 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Vitamins.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Vitamins.java
@@ -9,9 +9,9 @@ import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class Vitamins extends SimpleSlimefunItem {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/BasicCircuitBoard.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/BasicCircuitBoard.java
similarity index 72%
rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/BasicCircuitBoard.java
rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/BasicCircuitBoard.java
index d7e6e42aa..ee6d4420a 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/BasicCircuitBoard.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/BasicCircuitBoard.java
@@ -1,24 +1,32 @@
-package io.github.thebusybiscuit.slimefun4.implementation.items.electric;
+package io.github.thebusybiscuit.slimefun4.implementation.items.misc;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
+import io.github.thebusybiscuit.slimefun4.core.attributes.RandomMobDrop;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
-public class BasicCircuitBoard extends SimpleSlimefunItem implements NotPlaceable {
+public class BasicCircuitBoard extends SimpleSlimefunItem implements NotPlaceable, RandomMobDrop {
private final ItemSetting dropSetting = new ItemSetting<>("drop-from-golems", true);
+ private final ItemSetting chance = new ItemSetting<>("golem-drop-chance", 75);
public BasicCircuitBoard(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
addItemSetting(dropSetting);
+ addItemSetting(chance);
+ }
+
+ @Override
+ public int getMobDropChance() {
+ return chance.getValue();
}
public boolean isDroppedFromGolems() {
@@ -30,4 +38,4 @@ public class BasicCircuitBoard extends SimpleSlimefunItem implem
return PlayerRightClickEvent::cancel;
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/CoolantCell.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/CoolantCell.java
new file mode 100644
index 000000000..347a70d75
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/CoolantCell.java
@@ -0,0 +1,35 @@
+package io.github.thebusybiscuit.slimefun4.implementation.items.misc;
+
+import org.bukkit.inventory.ItemStack;
+
+import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.UnplaceableBlock;
+import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.ReactorAccessPort;
+import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.NetherStarReactor;
+import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.NuclearReactor;
+import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor;
+import me.mrCookieSlime.Slimefun.Lists.RecipeType;
+import me.mrCookieSlime.Slimefun.Objects.Category;
+import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
+
+/**
+ * A {@link CoolantCell} is an {@link ItemStack} that is used to cool a {@link Reactor}.
+ *
+ * @author TheBusyBiscuit
+ *
+ * @see Reactor
+ * @see ReactorAccessPort
+ * @see NuclearReactor
+ * @see NetherStarReactor
+ *
+ */
+public class CoolantCell extends UnplaceableBlock {
+
+ public CoolantCell(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
+ super(category, item, recipeType, recipe);
+ }
+
+ public CoolantCell(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
+ super(category, item, recipeType, recipe, recipeOutput);
+ }
+
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractSmeltery.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractSmeltery.java
index 032d3424e..a0b97afd4 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractSmeltery.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractSmeltery.java
@@ -6,6 +6,7 @@ import org.bukkit.Effect;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -15,6 +16,7 @@ import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.Slimefun;
@@ -28,37 +30,41 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
*/
abstract class AbstractSmeltery extends MultiBlockMachine {
- public AbstractSmeltery(Category category, SlimefunItemStack item, ItemStack[] recipe, ItemStack[] machineRecipes, BlockFace trigger) {
- super(category, item, recipe, machineRecipes, trigger);
+ public AbstractSmeltery(Category category, SlimefunItemStack item, ItemStack[] recipe, BlockFace trigger) {
+ super(category, item, recipe, trigger);
}
@Override
public void onInteract(Player p, Block b) {
Block dispBlock = b.getRelative(BlockFace.DOWN);
- Dispenser disp = (Dispenser) dispBlock.getState();
- Inventory inv = disp.getInventory();
- List inputs = RecipeType.getRecipeInputList(this);
+ BlockState state = PaperLib.getBlockState(dispBlock, false).getState();
- for (int i = 0; i < inputs.size(); i++) {
- if (canCraft(inv, inputs, i)) {
- ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
+ if (state instanceof Dispenser) {
+ Dispenser disp = (Dispenser) state;
+ Inventory inv = disp.getInventory();
+ List inputs = RecipeType.getRecipeInputList(this);
- if (Slimefun.hasUnlocked(p, output, true)) {
- Inventory outputInv = findOutputInventory(output, dispBlock, inv);
+ for (int i = 0; i < inputs.size(); i++) {
+ if (canCraft(inv, inputs, i)) {
+ ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
- if (outputInv != null) {
- craft(p, b, inv, inputs.get(i), output, outputInv);
- }
- else {
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
+ if (Slimefun.hasUnlocked(p, output, true)) {
+ Inventory outputInv = findOutputInventory(output, dispBlock, inv);
+
+ if (outputInv != null) {
+ craft(p, b, inv, inputs.get(i), output, outputInv);
+ }
+ else {
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
+ }
}
+
+ return;
}
-
- return;
}
- }
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
+ }
}
private boolean canCraft(Inventory inv, List inputs, int i) {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/ArmorForge.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/ArmorForge.java
index f01a0149e..cd97b214f 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/ArmorForge.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/ArmorForge.java
@@ -6,6 +6,7 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -16,6 +17,7 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.Slimefun;
@@ -24,40 +26,40 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class ArmorForge extends MultiBlockMachine {
public ArmorForge(Category category, SlimefunItemStack item) {
- super(category, item, new ItemStack[] {
- null, null, null,
- null, new ItemStack(Material.ANVIL), null,
- null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null
- }, new ItemStack[0], BlockFace.SELF);
+ super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.ANVIL), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null }, BlockFace.SELF);
}
@Override
public void onInteract(Player p, Block b) {
Block dispBlock = b.getRelative(BlockFace.DOWN);
- Dispenser disp = (Dispenser) dispBlock.getState();
- Inventory inv = disp.getInventory();
- List inputs = RecipeType.getRecipeInputList(this);
+ BlockState state = PaperLib.getBlockState(dispBlock, false).getState();
- for (int i = 0; i < inputs.size(); i++) {
- if (isCraftable(inv, inputs.get(i))) {
- ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
+ if (state instanceof Dispenser) {
+ Dispenser disp = (Dispenser) state;
+ Inventory inv = disp.getInventory();
+ List inputs = RecipeType.getRecipeInputList(this);
- if (Slimefun.hasUnlocked(p, output, true)) {
- Inventory outputInv = findOutputInventory(output, dispBlock, inv);
+ for (int i = 0; i < inputs.size(); i++) {
+ if (isCraftable(inv, inputs.get(i))) {
+ ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
- if (outputInv != null) {
- craft(p, output, inv, outputInv);
- }
- else {
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
+ if (Slimefun.hasUnlocked(p, output, true)) {
+ Inventory outputInv = findOutputInventory(output, dispBlock, inv);
+
+ if (outputInv != null) {
+ craft(p, output, inv, outputInv);
+ }
+ else {
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
+ }
}
+
+ return;
}
-
- return;
}
- }
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.pattern-not-found", true);
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.pattern-not-found", true);
+ }
}
private boolean isCraftable(Inventory inv, ItemStack[] recipe) {
@@ -73,7 +75,7 @@ public class ArmorForge extends MultiBlockMachine {
private void craft(Player p, ItemStack output, Inventory inv, Inventory outputInv) {
for (int j = 0; j < 9; j++) {
ItemStack item = inv.getContents()[j];
-
+
if (item != null && item.getType() != Material.AIR) {
ItemUtils.consumeItem(item, true);
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AutomatedPanningMachine.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AutomatedPanningMachine.java
index aa33cc629..fb7f4ceff 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AutomatedPanningMachine.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AutomatedPanningMachine.java
@@ -29,7 +29,7 @@ public class AutomatedPanningMachine extends MultiBlockMachine {
private final GoldPan netherGoldPan = (GoldPan) SlimefunItems.NETHER_GOLD_PAN.getItem();
public AutomatedPanningMachine(Category category, SlimefunItemStack item) {
- super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.OAK_TRAPDOOR), null, null, new ItemStack(Material.CAULDRON), null }, new ItemStack[0], BlockFace.SELF);
+ super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.OAK_TRAPDOOR), null, null, new ItemStack(Material.CAULDRON), null }, BlockFace.SELF);
}
@Override
@@ -46,7 +46,7 @@ public class AutomatedPanningMachine extends MultiBlockMachine {
public void onInteract(Player p, Block b) {
ItemStack input = p.getInventory().getItemInMainHand();
- if (SlimefunUtils.isItemSimilar(input, new ItemStack(Material.GRAVEL), true) || SlimefunUtils.isItemSimilar(input, new ItemStack(Material.SOUL_SAND), true)) {
+ if (SlimefunUtils.isItemSimilar(input, new ItemStack(Material.GRAVEL), true, false) || SlimefunUtils.isItemSimilar(input, new ItemStack(Material.SOUL_SAND), true, false)) {
Material material = input.getType();
if (p.getGameMode() != GameMode.CREATIVE) {
@@ -76,7 +76,7 @@ public class AutomatedPanningMachine extends MultiBlockMachine {
}
});
- queue.execute(SlimefunPlugin.instance);
+ queue.execute(SlimefunPlugin.instance());
}
else {
SlimefunPlugin.getLocalization().sendMessage(p, "machines.wrong-item", true);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/BackpackCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/BackpackCrafter.java
index 51375c919..6d2786244 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/BackpackCrafter.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/BackpackCrafter.java
@@ -26,8 +26,8 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
abstract class BackpackCrafter extends MultiBlockMachine {
- public BackpackCrafter(Category category, SlimefunItemStack item, ItemStack[] recipe, ItemStack[] machineRecipes, BlockFace trigger) {
- super(category, item, recipe, machineRecipes, trigger);
+ public BackpackCrafter(Category category, SlimefunItemStack item, ItemStack[] recipe, BlockFace trigger) {
+ super(category, item, recipe, trigger);
}
protected Inventory createVirtualInventory(Inventory inv) {
@@ -92,9 +92,7 @@ abstract class BackpackCrafter extends MultiBlockMachine {
PlayerProfile.fromUUID(UUID.fromString(idSplit[0]), profile -> {
Optional optional = profile.getBackpack(Integer.parseInt(idSplit[1]));
- if (optional.isPresent()) {
- optional.get().setSize(size);
- }
+ optional.ifPresent(playerBackpack -> playerBackpack.setSize(size));
});
return Optional.of(id);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Compressor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Compressor.java
index 90e9b9af0..854e047e0 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Compressor.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Compressor.java
@@ -7,6 +7,7 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -17,6 +18,7 @@ import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.Slimefun;
@@ -24,61 +26,67 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class Compressor extends MultiBlockMachine {
- public Compressor(Category category, SlimefunItemStack item) {
- super(category, item,
- new ItemStack[] {null, null, null, null, new ItemStack(Material.NETHER_BRICK_FENCE), null, new ItemStack(Material.PISTON), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.PISTON)},
- new ItemStack[] {
- new CustomItem(SlimefunItems.STONE_CHUNK, 4), new ItemStack(Material.COBBLESTONE),
- new ItemStack(Material.FLINT, 8), new ItemStack(Material.COBBLESTONE)
- },
- BlockFace.SELF
- );
- }
-
- @Override
- public List getDisplayRecipes() {
- return recipes.stream().map(items -> items[0]).collect(Collectors.toList());
- }
-
- @Override
- public void onInteract(Player p, Block b) {
- Block dispBlock = b.getRelative(BlockFace.DOWN);
- Dispenser disp = (Dispenser) dispBlock.getState();
- Inventory inv = disp.getInventory();
-
- for (ItemStack item : inv.getContents()) {
- for (ItemStack recipeInput : RecipeType.getRecipeInputs(this)) {
- if (recipeInput != null && SlimefunUtils.isItemSimilar(item, recipeInput, true)) {
- ItemStack output = RecipeType.getRecipeOutput(this, recipeInput);
- Inventory outputInv = findOutputInventory(output, dispBlock, inv);
-
- if (outputInv != null) {
- ItemStack removing = item.clone();
- removing.setAmount(recipeInput.getAmount());
- inv.removeItem(removing);
+ public Compressor(Category category, SlimefunItemStack item) {
+ super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.NETHER_BRICK_FENCE), null, new ItemStack(Material.PISTON), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.PISTON) }, BlockFace.SELF);
+ }
- craft(p, output, outputInv);
- }
- else {
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
- }
-
- return;
- }
- }
- }
-
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
- }
+ @Override
+ protected void registerDefaultRecipes(List recipes) {
+ recipes.add(new SlimefunItemStack(SlimefunItems.STONE_CHUNK, 4));
+ recipes.add(new ItemStack(Material.COBBLESTONE));
+
+ recipes.add(new ItemStack(Material.FLINT, 8));
+ recipes.add(new ItemStack(Material.COBBLESTONE));
+ }
+
+ @Override
+ public List getDisplayRecipes() {
+ return recipes.stream().map(items -> items[0]).collect(Collectors.toList());
+ }
+
+ @Override
+ public void onInteract(Player p, Block b) {
+ Block dispBlock = b.getRelative(BlockFace.DOWN);
+ BlockState state = PaperLib.getBlockState(dispBlock, false).getState();
+
+ if (state instanceof Dispenser) {
+ Dispenser disp = (Dispenser) state;
+ Inventory inv = disp.getInventory();
+
+ for (ItemStack item : inv.getContents()) {
+ for (ItemStack recipeInput : RecipeType.getRecipeInputs(this)) {
+ if (recipeInput != null && SlimefunUtils.isItemSimilar(item, recipeInput, true)) {
+ ItemStack output = RecipeType.getRecipeOutput(this, recipeInput);
+ Inventory outputInv = findOutputInventory(output, dispBlock, inv);
+
+ if (outputInv != null) {
+ ItemStack removing = item.clone();
+ removing.setAmount(recipeInput.getAmount());
+ inv.removeItem(removing);
+
+ craft(p, output, outputInv);
+ }
+ else {
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
+ }
+
+ return;
+ }
+ }
+ }
+
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
+ }
+ }
private void craft(Player p, ItemStack output, Inventory outputInv) {
for (int i = 0; i < 4; i++) {
int j = i;
-
+
Slimefun.runSync(() -> {
if (j < 3) {
p.getWorld().playSound(p.getLocation(), j == 1 ? Sound.BLOCK_PISTON_CONTRACT : Sound.BLOCK_PISTON_EXTEND, 1F, j == 0 ? 1F : 2F);
- }
+ }
else {
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F);
outputInv.addItem(output);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java
index de69888a3..97b72b81a 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/EnhancedCraftingTable.java
@@ -6,6 +6,7 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -15,6 +16,7 @@ import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@@ -24,28 +26,32 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class EnhancedCraftingTable extends BackpackCrafter {
public EnhancedCraftingTable(Category category, SlimefunItemStack item) {
- super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.CRAFTING_TABLE), null, null, new ItemStack(Material.DISPENSER), null }, new ItemStack[0], BlockFace.SELF);
+ super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.CRAFTING_TABLE), null, null, new ItemStack(Material.DISPENSER), null }, BlockFace.SELF);
}
@Override
public void onInteract(Player p, Block b) {
Block dispenser = b.getRelative(BlockFace.DOWN);
- Dispenser disp = (Dispenser) dispenser.getState();
- Inventory inv = disp.getInventory();
+ BlockState state = PaperLib.getBlockState(dispenser, false).getState();
- List inputs = RecipeType.getRecipeInputList(this);
+ if (state instanceof Dispenser) {
+ Dispenser disp = (Dispenser) state;
+ Inventory inv = disp.getInventory();
- for (int i = 0; i < inputs.size(); i++) {
- if (isCraftable(inv, inputs.get(i))) {
- ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
- if (Slimefun.hasUnlocked(p, output, true)) {
- craft(inv, dispenser, p, b, output);
+ List inputs = RecipeType.getRecipeInputList(this);
+
+ for (int i = 0; i < inputs.size(); i++) {
+ if (isCraftable(inv, inputs.get(i))) {
+ ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
+ if (Slimefun.hasUnlocked(p, output, true)) {
+ craft(inv, dispenser, p, b, output);
+ }
+
+ return;
}
-
- return;
}
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.pattern-not-found", true);
}
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.pattern-not-found", true);
}
private void craft(Inventory inv, Block dispenser, Player p, Block b, ItemStack output) {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/GrindStone.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/GrindStone.java
index cff7af535..cff9d414e 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/GrindStone.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/GrindStone.java
@@ -7,6 +7,7 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -17,67 +18,99 @@ import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class GrindStone extends MultiBlockMachine {
- public GrindStone(Category category, SlimefunItemStack item) {
- super(category, item,
- new ItemStack[] {null, null, null, null, new ItemStack(Material.OAK_FENCE), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null},
- new ItemStack[] {
- new ItemStack(Material.BLAZE_ROD), new ItemStack(Material.BLAZE_POWDER, 4),
- new ItemStack(Material.BONE), new ItemStack(Material.BONE_MEAL, 4),
- new ItemStack(Material.GRAVEL), new ItemStack(Material.FLINT),
- new ItemStack(Material.ENDER_EYE), new CustomItem(SlimefunItems.ENDER_LUMP_1, 2),
- new ItemStack(Material.COBBLESTONE), new ItemStack(Material.GRAVEL),
- new ItemStack(Material.ANDESITE), new ItemStack(Material.GRAVEL),
- new ItemStack(Material.DIORITE), new ItemStack(Material.GRAVEL),
- new ItemStack(Material.GRANITE), new ItemStack(Material.GRAVEL),
- new ItemStack(Material.DIRT), SlimefunItems.STONE_CHUNK,
- new ItemStack(Material.SANDSTONE), new ItemStack(Material.SAND, 4),
- new ItemStack(Material.RED_SANDSTONE), new ItemStack(Material.RED_SAND, 4),
- new ItemStack(Material.PRISMARINE_BRICKS), new ItemStack(Material.PRISMARINE, 2),
- new ItemStack(Material.PRISMARINE), new ItemStack(Material.PRISMARINE_SHARD, 4)
- },
- BlockFace.SELF
- );
- }
-
- @Override
- public List getDisplayRecipes() {
- return recipes.stream().map(items -> items[0]).collect(Collectors.toList());
- }
-
- @Override
- public void onInteract(Player p, Block b) {
- Block dispBlock = b.getRelative(BlockFace.DOWN);
- Dispenser disp = (Dispenser) dispBlock.getState();
- Inventory inv = disp.getInventory();
-
- for (ItemStack current : inv.getContents()) {
- for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
- if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
- ItemStack output = RecipeType.getRecipeOutput(this, convert);
- Inventory outputInv = findOutputInventory(output, dispBlock, inv);
-
- if (outputInv != null) {
- ItemStack removing = current.clone();
- removing.setAmount(1);
- inv.removeItem(removing);
- outputInv.addItem(output);
- p.getWorld().playSound(p.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1);
- }
- else {
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
- }
-
- return;
- }
- }
- }
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
- }
+ public GrindStone(Category category, SlimefunItemStack item) {
+ super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.OAK_FENCE), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null }, BlockFace.SELF);
+ }
+
+ @Override
+ protected void registerDefaultRecipes(List recipes) {
+ recipes.add(new ItemStack(Material.BLAZE_ROD));
+ recipes.add(new ItemStack(Material.BLAZE_POWDER, 4));
+
+ recipes.add(new ItemStack(Material.BONE));
+ recipes.add(new ItemStack(Material.BONE_MEAL, 4));
+
+ recipes.add(new ItemStack(Material.BONE_BLOCK));
+ recipes.add(new ItemStack(Material.BONE_MEAL, 9));
+
+ recipes.add(new ItemStack(Material.GRAVEL));
+ recipes.add(new ItemStack(Material.FLINT));
+
+ recipes.add(new ItemStack(Material.ENDER_EYE));
+ recipes.add(new SlimefunItemStack(SlimefunItems.ENDER_LUMP_1, 2));
+
+ recipes.add(new ItemStack(Material.COBBLESTONE));
+ recipes.add(new ItemStack(Material.GRAVEL));
+
+ recipes.add(new ItemStack(Material.ANDESITE));
+ recipes.add(new ItemStack(Material.GRAVEL));
+
+ recipes.add(new ItemStack(Material.DIORITE));
+ recipes.add(new ItemStack(Material.GRAVEL));
+
+ recipes.add(new ItemStack(Material.GRANITE));
+ recipes.add(new ItemStack(Material.GRAVEL));
+
+ recipes.add(new ItemStack(Material.DIRT));
+ recipes.add(SlimefunItems.STONE_CHUNK);
+
+ recipes.add(new ItemStack(Material.SANDSTONE));
+ recipes.add(new ItemStack(Material.SAND, 4));
+
+ recipes.add(new ItemStack(Material.RED_SANDSTONE));
+ recipes.add(new ItemStack(Material.RED_SAND, 4));
+
+ recipes.add(new ItemStack(Material.PRISMARINE_BRICKS));
+ recipes.add(new ItemStack(Material.PRISMARINE, 2));
+
+ recipes.add(new ItemStack(Material.PRISMARINE));
+ recipes.add(new ItemStack(Material.PRISMARINE_SHARD, 4));
+ }
+
+ @Override
+ public List getDisplayRecipes() {
+ return recipes.stream().map(items -> items[0]).collect(Collectors.toList());
+ }
+
+ @Override
+ public void onInteract(Player p, Block b) {
+ Block dispBlock = b.getRelative(BlockFace.DOWN);
+ BlockState state = PaperLib.getBlockState(dispBlock, false).getState();
+
+ if (state instanceof Dispenser) {
+ Dispenser disp = (Dispenser) state;
+ Inventory inv = disp.getInventory();
+
+ for (ItemStack current : inv.getContents()) {
+ for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
+ if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
+ ItemStack output = RecipeType.getRecipeOutput(this, convert);
+ Inventory outputInv = findOutputInventory(output, dispBlock, inv);
+
+ if (outputInv != null) {
+ ItemStack removing = current.clone();
+ removing.setAmount(1);
+ inv.removeItem(removing);
+ outputInv.addItem(output);
+ p.getWorld().playSound(p.getLocation(), Sound.BLOCK_WOODEN_BUTTON_CLICK_ON, 1, 1);
+ }
+ else {
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
+ }
+
+ return;
+ }
+ }
+ }
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
+ }
+ }
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Juicer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Juicer.java
index 3d5ae8cba..abd6e6f4d 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Juicer.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Juicer.java
@@ -8,6 +8,7 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -17,53 +18,56 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class Juicer extends MultiBlockMachine {
- public Juicer(Category category, SlimefunItemStack item) {
- super(category, item,
- new ItemStack[] {null, new ItemStack(Material.GLASS), null, null, new ItemStack(Material.NETHER_BRICK_FENCE), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null},
- new ItemStack[0],
- BlockFace.SELF
- );
- }
-
- @Override
- public List getDisplayRecipes() {
- return recipes.stream().map(items -> items[0]).collect(Collectors.toList());
- }
-
- @Override
- public void onInteract(Player p, Block b) {
- Block dispBlock = b.getRelative(BlockFace.DOWN);
- Dispenser disp = (Dispenser) dispBlock.getState();
- Inventory inv = disp.getInventory();
-
- for (ItemStack current : inv.getContents()) {
- for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
- if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
- ItemStack adding = RecipeType.getRecipeOutput(this, convert);
- Inventory outputInv = findOutputInventory(adding, dispBlock, inv);
-
- if (outputInv != null) {
- ItemStack removing = current.clone();
- removing.setAmount(1);
- inv.removeItem(removing);
- outputInv.addItem(adding);
- p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
- p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.HAY_BLOCK);
- }
- else SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
-
- return;
- }
- }
- }
-
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
- }
+ public Juicer(Category category, SlimefunItemStack item) {
+ super(category, item, new ItemStack[] { null, new ItemStack(Material.GLASS), null, null, new ItemStack(Material.NETHER_BRICK_FENCE), null, null, new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), null }, BlockFace.SELF);
+ }
+
+ @Override
+ public List getDisplayRecipes() {
+ return recipes.stream().map(items -> items[0]).collect(Collectors.toList());
+ }
+
+ @Override
+ public void onInteract(Player p, Block b) {
+ Block dispBlock = b.getRelative(BlockFace.DOWN);
+ BlockState state = PaperLib.getBlockState(dispBlock, false).getState();
+
+ if (state instanceof Dispenser) {
+ Dispenser disp = (Dispenser) state;
+ Inventory inv = disp.getInventory();
+
+ for (ItemStack current : inv.getContents()) {
+ for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
+ if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
+ ItemStack adding = RecipeType.getRecipeOutput(this, convert);
+ Inventory outputInv = findOutputInventory(adding, dispBlock, inv);
+
+ if (outputInv != null) {
+ ItemStack removing = current.clone();
+ removing.setAmount(1);
+ inv.removeItem(removing);
+ outputInv.addItem(adding);
+ p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
+ p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.HAY_BLOCK);
+ }
+ else {
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
+ }
+
+ return;
+ }
+ }
+ }
+
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
+ }
+ }
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MagicWorkbench.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MagicWorkbench.java
index bc853dbdd..1b0de4047 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MagicWorkbench.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MagicWorkbench.java
@@ -2,12 +2,12 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks;
import java.util.List;
-import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -17,6 +17,7 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@@ -26,7 +27,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class MagicWorkbench extends BackpackCrafter {
public MagicWorkbench(Category category, SlimefunItemStack item) {
- super(category, item, new ItemStack[] { null, null, null, null, null, null, new ItemStack(Material.BOOKSHELF), new ItemStack(Material.CRAFTING_TABLE), new ItemStack(Material.DISPENSER) }, new ItemStack[0], BlockFace.UP);
+ super(category, item, new ItemStack[] { null, null, null, null, null, null, new ItemStack(Material.BOOKSHELF), new ItemStack(Material.CRAFTING_TABLE), new ItemStack(Material.DISPENSER) }, BlockFace.UP);
}
@Override
@@ -38,21 +39,27 @@ public class MagicWorkbench extends BackpackCrafter {
return;
}
- Inventory inv = ((Dispenser) dispenser.getState()).getInventory();
- List inputs = RecipeType.getRecipeInputList(this);
+ BlockState state = PaperLib.getBlockState(dispenser, false).getState();
- for (int i = 0; i < inputs.size(); i++) {
- if (isCraftable(inv, inputs.get(i))) {
- ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
+ if (state instanceof Dispenser) {
+ Dispenser disp = (Dispenser) state;
+ Inventory inv = disp.getInventory();
+ List inputs = RecipeType.getRecipeInputList(this);
- if (Slimefun.hasUnlocked(p, output, true)) {
- craft(inv, dispenser, p, b, output);
+ for (int i = 0; i < inputs.size(); i++) {
+ if (isCraftable(inv, inputs.get(i))) {
+ ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
+
+ if (Slimefun.hasUnlocked(p, output, true)) {
+ craft(inv, dispenser, p, b, output);
+ }
+
+ return;
}
-
- return;
}
+
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.pattern-not-found", true);
}
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.pattern-not-found", true);
}
private void craft(Inventory inv, Block dispenser, Player p, Block b, ItemStack output) {
@@ -68,20 +75,26 @@ public class MagicWorkbench extends BackpackCrafter {
for (int j = 0; j < 9; j++) {
if (inv.getContents()[j] != null && inv.getContents()[j].getType() != Material.AIR) {
- if (inv.getContents()[j].getAmount() > 1) inv.setItem(j, new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1));
- else inv.setItem(j, null);
+ if (inv.getContents()[j].getAmount() > 1) {
+ inv.setItem(j, new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1));
+ }
+ else {
+ inv.setItem(j, null);
+ }
}
}
startAnimation(p, b, outputInv, output);
}
- else SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
+ else {
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
+ }
}
private void startAnimation(Player p, Block b, Inventory inv, ItemStack output) {
for (int j = 0; j < 4; j++) {
int current = j;
- Bukkit.getScheduler().runTaskLater(SlimefunPlugin.instance, () -> {
+ Slimefun.runSync(() -> {
p.getWorld().playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
p.getWorld().playEffect(b.getLocation(), Effect.ENDER_SIGNAL, 1);
@@ -99,10 +112,18 @@ public class MagicWorkbench extends BackpackCrafter {
private Block locateDispenser(Block b) {
Block block = null;
- if (b.getRelative(1, 0, 0).getType() == Material.DISPENSER) block = b.getRelative(1, 0, 0);
- else if (b.getRelative(0, 0, 1).getType() == Material.DISPENSER) block = b.getRelative(0, 0, 1);
- else if (b.getRelative(-1, 0, 0).getType() == Material.DISPENSER) block = b.getRelative(-1, 0, 0);
- else if (b.getRelative(0, 0, -1).getType() == Material.DISPENSER) block = b.getRelative(0, 0, -1);
+ if (b.getRelative(1, 0, 0).getType() == Material.DISPENSER) {
+ block = b.getRelative(1, 0, 0);
+ }
+ else if (b.getRelative(0, 0, 1).getType() == Material.DISPENSER) {
+ block = b.getRelative(0, 0, 1);
+ }
+ else if (b.getRelative(-1, 0, 0).getType() == Material.DISPENSER) {
+ block = b.getRelative(-1, 0, 0);
+ }
+ else if (b.getRelative(0, 0, -1).getType() == Material.DISPENSER) {
+ block = b.getRelative(0, 0, -1);
+ }
return block;
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MakeshiftSmeltery.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MakeshiftSmeltery.java
index 513b8b3e3..83b044271 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MakeshiftSmeltery.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/MakeshiftSmeltery.java
@@ -18,7 +18,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class MakeshiftSmeltery extends AbstractSmeltery {
public MakeshiftSmeltery(Category category, SlimefunItemStack item) {
- super(category, item, new ItemStack[] { null, new ItemStack(Material.OAK_FENCE), null, new ItemStack(Material.BRICKS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.BRICKS), null, new ItemStack(Material.FLINT_AND_STEEL), null }, new ItemStack[0], BlockFace.DOWN);
+ super(category, item, new ItemStack[] { null, new ItemStack(Material.OAK_FENCE), null, new ItemStack(Material.BRICKS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.BRICKS), null, new ItemStack(Material.FLINT_AND_STEEL), null }, BlockFace.DOWN);
}
@Override
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java
index 85337c638..9d07221a0 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreCrusher.java
@@ -8,6 +8,7 @@ import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -20,6 +21,7 @@ import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@@ -30,11 +32,32 @@ public class OreCrusher extends MultiBlockMachine {
private final DoubleOreSetting doubleOres = new DoubleOreSetting();
public OreCrusher(Category category, SlimefunItemStack item) {
- super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.NETHER_BRICK_FENCE), null, new ItemStack(Material.IRON_BARS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.IRON_BARS) }, new ItemStack[] { new ItemStack(Material.COBBLESTONE, 8), new ItemStack(Material.SAND, 1), SlimefunItems.GOLD_4K, SlimefunItems.GOLD_DUST, new ItemStack(Material.GRAVEL), new ItemStack(Material.SAND), new ItemStack(Material.MAGMA_BLOCK, 4), SlimefunItems.SULFATE }, BlockFace.SELF);
+ super(category, item, new ItemStack[] { null, null, null, null, new ItemStack(Material.NETHER_BRICK_FENCE), null, new ItemStack(Material.IRON_BARS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.IRON_BARS) }, BlockFace.SELF);
addItemSetting(doubleOres);
}
+ @Override
+ protected void registerDefaultRecipes(List recipes) {
+ recipes.add(new ItemStack(Material.COBBLESTONE, 8));
+ recipes.add(new ItemStack(Material.SAND, 1));
+
+ recipes.add(SlimefunItems.GOLD_4K);
+ recipes.add(SlimefunItems.GOLD_DUST);
+
+ recipes.add(new ItemStack(Material.GRAVEL));
+ recipes.add(new ItemStack(Material.SAND));
+
+ recipes.add(new ItemStack(Material.MAGMA_BLOCK, 4));
+ recipes.add(SlimefunItems.SULFATE);
+
+ recipes.add(SlimefunItems.CARBON);
+ recipes.add(new ItemStack(Material.COAL, 8));
+
+ recipes.add(SlimefunItems.COMPRESSED_CARBON);
+ recipes.add(new SlimefunItemStack(SlimefunItems.CARBON, 4));
+ }
+
public boolean isOreDoublingEnabled() {
return doubleOres.getValue();
}
@@ -62,29 +85,35 @@ public class OreCrusher extends MultiBlockMachine {
@Override
public void onInteract(Player p, Block b) {
Block dispBlock = b.getRelative(BlockFace.DOWN);
- Dispenser disp = (Dispenser) dispBlock.getState();
- Inventory inv = disp.getInventory();
+ BlockState state = PaperLib.getBlockState(dispBlock, false).getState();
- for (ItemStack current : inv.getContents()) {
- for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
- if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
- ItemStack adding = RecipeType.getRecipeOutput(this, convert);
- Inventory outputInv = findOutputInventory(adding, dispBlock, inv);
- if (outputInv != null) {
- ItemStack removing = current.clone();
- removing.setAmount(convert.getAmount());
- inv.removeItem(removing);
- outputInv.addItem(adding);
- p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, 1);
+ if (state instanceof Dispenser) {
+ Dispenser disp = (Dispenser) state;
+ Inventory inv = disp.getInventory();
+
+ for (ItemStack current : inv.getContents()) {
+ for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
+ if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
+ ItemStack adding = RecipeType.getRecipeOutput(this, convert);
+ Inventory outputInv = findOutputInventory(adding, dispBlock, inv);
+ if (outputInv != null) {
+ ItemStack removing = current.clone();
+ removing.setAmount(convert.getAmount());
+ inv.removeItem(removing);
+ outputInv.addItem(adding);
+ p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, 1);
+ }
+ else {
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
+ }
+
+ return;
}
- else SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
-
- return;
}
}
- }
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
+ }
}
private class DoubleOreSetting extends ItemSetting {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreWasher.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreWasher.java
index 719646aad..73e2a4fe3 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreWasher.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/OreWasher.java
@@ -9,6 +9,7 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -18,6 +19,7 @@ import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
@@ -27,7 +29,7 @@ public class OreWasher extends MultiBlockMachine {
private final ItemStack[] dusts;
public OreWasher(Category category, SlimefunItemStack item) {
- super(category, item, new ItemStack[] { null, new ItemStack(Material.DISPENSER), null, null, new ItemStack(Material.OAK_FENCE), null, null, new ItemStack(Material.CAULDRON), null }, new ItemStack[0], BlockFace.SELF);
+ super(category, item, new ItemStack[] { null, new ItemStack(Material.DISPENSER), null, null, new ItemStack(Material.OAK_FENCE), null, null, new ItemStack(Material.CAULDRON), null }, BlockFace.SELF);
legacyMode = SlimefunPlugin.getCfg().getBoolean("options.legacy-ore-washer");
dusts = new ItemStack[] { SlimefunItems.IRON_DUST, SlimefunItems.GOLD_DUST, SlimefunItems.COPPER_DUST, SlimefunItems.TIN_DUST, SlimefunItems.ZINC_DUST, SlimefunItems.ALUMINUM_DUST, SlimefunItems.MAGNESIUM_DUST, SlimefunItems.LEAD_DUST, SlimefunItems.SILVER_DUST };
@@ -41,57 +43,62 @@ public class OreWasher extends MultiBlockMachine {
@Override
public void onInteract(Player p, Block b) {
Block dispBlock = b.getRelative(BlockFace.UP);
- Dispenser disp = (Dispenser) dispBlock.getState();
- Inventory inv = disp.getInventory();
+ BlockState state = PaperLib.getBlockState(dispBlock, false).getState();
- for (ItemStack input : inv.getContents()) {
- if (input != null) {
- if (SlimefunUtils.isItemSimilar(input, SlimefunItems.SIFTED_ORE, true)) {
- ItemStack output = getRandomDust();
- Inventory outputInv = null;
+ if (state instanceof Dispenser) {
+ Dispenser disp = (Dispenser) state;
+ Inventory inv = disp.getInventory();
- if (!legacyMode) {
- // This is a fancy way of checking if there is empty space in the inv; by checking if an
- // unobtainable item could fit in it.
- // However, due to the way the method findValidOutputInv() functions, the dummyAdding will never
- // actually be added to the real inventory,
- // so it really doesn't matter what item the ItemStack is made by. SlimefunItems.DEBUG_FISH
- // however, signals that it's
- // not supposed to be given to the player.
- ItemStack dummyAdding = SlimefunItems.DEBUG_FISH;
- outputInv = findOutputInventory(dummyAdding, dispBlock, inv);
+ for (ItemStack input : inv.getContents()) {
+ if (input != null) {
+ if (SlimefunUtils.isItemSimilar(input, SlimefunItems.SIFTED_ORE, true)) {
+ ItemStack output = getRandomDust();
+ Inventory outputInv = null;
+
+ if (!legacyMode) {
+ // This is a fancy way of checking if there is empty space in the inv; by checking if an
+ // unobtainable item could fit in it.
+ // However, due to the way the method findValidOutputInv() functions, the dummyAdding will
+ // never
+ // actually be added to the real inventory,
+ // so it really doesn't matter what item the ItemStack is made by. SlimefunItems.DEBUG_FISH
+ // however, signals that it's
+ // not supposed to be given to the player.
+ ItemStack dummyAdding = SlimefunItems.DEBUG_FISH;
+ outputInv = findOutputInventory(dummyAdding, dispBlock, inv);
+ }
+ else {
+ outputInv = findOutputInventory(output, dispBlock, inv);
+ }
+
+ removeItem(p, b, inv, outputInv, input, output, 1);
+
+ if (outputInv != null) {
+ outputInv.addItem(SlimefunItems.STONE_CHUNK);
+ }
+
+ return;
}
- else {
- outputInv = findOutputInventory(output, dispBlock, inv);
+ else if (SlimefunUtils.isItemSimilar(input, new ItemStack(Material.SAND, 2), false)) {
+ ItemStack output = SlimefunItems.SALT;
+ Inventory outputInv = findOutputInventory(output, dispBlock, inv);
+
+ removeItem(p, b, inv, outputInv, input, output, 2);
+
+ return;
}
+ else if (SlimefunUtils.isItemSimilar(input, SlimefunItems.PULVERIZED_ORE, true)) {
+ ItemStack output = SlimefunItems.PURE_ORE_CLUSTER;
+ Inventory outputInv = findOutputInventory(output, dispBlock, inv);
- removeItem(p, b, inv, outputInv, input, output, 1);
+ removeItem(p, b, inv, outputInv, input, output, 1);
- if (outputInv != null) {
- outputInv.addItem(SlimefunItems.STONE_CHUNK);
+ return;
}
-
- return;
- }
- else if (SlimefunUtils.isItemSimilar(input, new ItemStack(Material.SAND, 2), false)) {
- ItemStack output = SlimefunItems.SALT;
- Inventory outputInv = findOutputInventory(output, dispBlock, inv);
-
- removeItem(p, b, inv, outputInv, input, output, 2);
-
- return;
- }
- else if (SlimefunUtils.isItemSimilar(input, SlimefunItems.PULVERIZED_ORE, true)) {
- ItemStack output = SlimefunItems.PURE_ORE_CLUSTER;
- Inventory outputInv = findOutputInventory(output, dispBlock, inv);
-
- removeItem(p, b, inv, outputInv, input, output, 1);
-
- return;
}
}
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
}
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
}
private void removeItem(Player p, Block b, Inventory inputInv, Inventory outputInv, ItemStack input, ItemStack output, int amount) {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/PressureChamber.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/PressureChamber.java
index 50f919e5d..b10c5fcbc 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/PressureChamber.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/PressureChamber.java
@@ -3,12 +3,12 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks;
import java.util.List;
import java.util.stream.Collectors;
-import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -19,18 +19,17 @@ import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
+import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class PressureChamber extends MultiBlockMachine {
-
+
public PressureChamber(Category category, SlimefunItemStack item) {
- super(category, item, new ItemStack[] {
- SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14) ? new ItemStack(Material.SMOOTH_STONE_SLAB) : new ItemStack(Material.STONE_SLAB), new CustomItem(Material.DISPENSER, "Dispenser (Facing down)"), SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14) ? new ItemStack(Material.SMOOTH_STONE_SLAB) : new ItemStack(Material.STONE_SLAB),
- new ItemStack(Material.PISTON), new ItemStack(Material.GLASS), new ItemStack(Material.PISTON),
- new ItemStack(Material.PISTON), new ItemStack(Material.CAULDRON), new ItemStack(Material.PISTON)
- }, new ItemStack[0], BlockFace.UP);
+ super(category, item, new ItemStack[] { SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14) ? new ItemStack(Material.SMOOTH_STONE_SLAB) : new ItemStack(Material.STONE_SLAB), new CustomItem(Material.DISPENSER, "Dispenser (Facing down)"), SlimefunPlugin.getMinecraftVersion()
+ .isAtLeast(MinecraftVersion.MINECRAFT_1_14) ? new ItemStack(Material.SMOOTH_STONE_SLAB) : new ItemStack(Material.STONE_SLAB), new ItemStack(Material.PISTON), new ItemStack(Material.GLASS), new ItemStack(Material.PISTON), new ItemStack(Material.PISTON), new ItemStack(Material.CAULDRON), new ItemStack(Material.PISTON) }, BlockFace.UP);
}
@Override
@@ -41,36 +40,42 @@ public class PressureChamber extends MultiBlockMachine {
@Override
public void onInteract(Player p, Block b) {
Block dispBlock = b.getRelative(BlockFace.UP).getRelative(BlockFace.UP);
- Dispenser disp = (Dispenser) dispBlock.getState();
- Inventory inv = disp.getInventory();
+ BlockState state = PaperLib.getBlockState(dispBlock, false).getState();
- for (ItemStack current : inv.getContents()) {
- for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
- if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
- ItemStack output = RecipeType.getRecipeOutput(this, convert);
- Inventory outputInv = findOutputInventory(output, dispBlock, inv);
+ if (state instanceof Dispenser) {
+ Dispenser disp = (Dispenser) state;
+ Inventory inv = disp.getInventory();
- if (outputInv != null) {
- ItemStack removing = current.clone();
- removing.setAmount(convert.getAmount());
- inv.removeItem(removing);
+ for (ItemStack current : inv.getContents()) {
+ for (ItemStack convert : RecipeType.getRecipeInputs(this)) {
+ if (convert != null && SlimefunUtils.isItemSimilar(current, convert, true)) {
+ ItemStack output = RecipeType.getRecipeOutput(this, convert);
+ Inventory outputInv = findOutputInventory(output, dispBlock, inv);
- craft(p, b, output, outputInv);
+ if (outputInv != null) {
+ ItemStack removing = current.clone();
+ removing.setAmount(convert.getAmount());
+ inv.removeItem(removing);
+
+ craft(p, b, output, outputInv);
+ }
+ else {
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
+ }
+
+ return;
}
- else SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true);
-
- return;
}
}
+ SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
}
- SlimefunPlugin.getLocalization().sendMessage(p, "machines.unknown-material", true);
}
private void craft(Player p, Block b, ItemStack output, Inventory outputInv) {
for (int i = 0; i < 4; i++) {
int j = i;
- Bukkit.getScheduler().runTaskLater(SlimefunPlugin.instance, () -> {
+ Slimefun.runSync(() -> {
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1);
p.getWorld().playEffect(b.getRelative(BlockFace.UP).getLocation(), Effect.SMOKE, 4);
p.getWorld().playEffect(b.getRelative(BlockFace.UP).getLocation(), Effect.SMOKE, 4);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java
index 0fd03ccd1..5adce87a3 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/Smeltery.java
@@ -11,6 +11,7 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dropper;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -22,6 +23,7 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
@@ -32,11 +34,17 @@ public class Smeltery extends AbstractSmeltery {
private final ItemSetting fireBreakingChance = new ItemSetting<>("fire-breaking-chance", 34);
public Smeltery(Category category, SlimefunItemStack item) {
- super(category, item, new ItemStack[] { null, new ItemStack(Material.NETHER_BRICK_FENCE), null, new ItemStack(Material.NETHER_BRICKS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.NETHER_BRICKS), null, new ItemStack(Material.FLINT_AND_STEEL), null }, new ItemStack[] { SlimefunItems.IRON_DUST, new ItemStack(Material.IRON_INGOT) }, BlockFace.DOWN);
+ super(category, item, new ItemStack[] { null, new ItemStack(Material.NETHER_BRICK_FENCE), null, new ItemStack(Material.NETHER_BRICKS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.NETHER_BRICKS), null, new ItemStack(Material.FLINT_AND_STEEL), null }, BlockFace.DOWN);
addItemSetting(fireBreakingChance);
}
+ @Override
+ protected void registerDefaultRecipes(List recipes) {
+ recipes.add(SlimefunItems.IRON_DUST);
+ recipes.add(new ItemStack(Material.IRON_INGOT));
+ }
+
@Override
public List getDisplayRecipes() {
List items = new ArrayList<>();
@@ -97,7 +105,11 @@ public class Smeltery extends AbstractSmeltery {
private Inventory findIgnitionChamber(Block b) {
for (BlockFace face : faces) {
if (b.getRelative(face).getType() == Material.DROPPER && BlockStorage.check(b.getRelative(face), "IGNITION_CHAMBER")) {
- return ((Dropper) b.getRelative(face).getState()).getInventory();
+ BlockState state = PaperLib.getBlockState(b.getRelative(face), false).getState();
+
+ if (state instanceof Dropper) {
+ return ((Dropper) state).getInventory();
+ }
}
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/TableSaw.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/TableSaw.java
index 05916a9b5..22caf32c7 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/TableSaw.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/TableSaw.java
@@ -36,7 +36,7 @@ public class TableSaw extends MultiBlockMachine {
private final List displayedRecipes = new ArrayList<>();
public TableSaw(Category category, SlimefunItemStack item) {
- super(category, item, new ItemStack[] { null, null, null, new ItemStack(Material.SMOOTH_STONE_SLAB), new ItemStack(Material.STONECUTTER), new ItemStack(Material.SMOOTH_STONE_SLAB), null, new ItemStack(Material.IRON_BLOCK), null }, new ItemStack[0], BlockFace.SELF);
+ super(category, item, new ItemStack[] { null, null, null, new ItemStack(Material.SMOOTH_STONE_SLAB), new ItemStack(Material.STONECUTTER), new ItemStack(Material.SMOOTH_STONE_SLAB), null, new ItemStack(Material.IRON_BLOCK), null }, BlockFace.SELF);
for (Material log : Tag.LOGS.getValues()) {
Optional planks = MaterialConverter.getPlanksFromLog(log);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java
index 557953ef6..36f42092b 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/ActiveMiner.java
@@ -11,6 +11,7 @@ import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.data.type.Piston;
import org.bukkit.block.data.type.PistonHead;
@@ -24,6 +25,7 @@ import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.cscorelib2.scheduling.TaskQueue;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel;
import me.mrCookieSlime.Slimefun.api.Slimefun;
@@ -149,7 +151,7 @@ class ActiveMiner implements Runnable {
queue.thenRun(2, () -> setPistonState(pistons[1], false));
queue.thenRun(1, this);
- queue.execute(SlimefunPlugin.instance);
+ queue.execute(SlimefunPlugin.instance());
}
@Override
@@ -202,7 +204,7 @@ class ActiveMiner implements Runnable {
}
});
- queue.execute(SlimefunPlugin.instance);
+ queue.execute(SlimefunPlugin.instance());
}
/**
@@ -251,14 +253,22 @@ class ActiveMiner implements Runnable {
// Check if there is enough fuel to run
if (fuel > 0) {
if (chest.getType() == Material.CHEST) {
- Inventory inv = ((Chest) chest.getState()).getBlockInventory();
+ BlockState state = PaperLib.getBlockState(chest, false).getState();
- if (InvUtils.fits(inv, item)) {
- inv.addItem(item);
- return true;
+ if (state instanceof Chest) {
+ Inventory inv = ((Chest) state).getBlockInventory();
+
+ if (InvUtils.fits(inv, item)) {
+ inv.addItem(item);
+ return true;
+ }
+ else {
+ stop("machines.INDUSTRIAL_MINER.chest-full");
+ }
}
else {
- stop("machines.INDUSTRIAL_MINER.chest-full");
+ // I won't question how this happened...
+ stop("machines.INDUSTRIAL_MINER.destroyed");
}
}
else {
@@ -280,20 +290,24 @@ class ActiveMiner implements Runnable {
*/
private int consumeFuel() {
if (chest.getType() == Material.CHEST) {
- Inventory inv = ((Chest) chest.getState()).getBlockInventory();
+ BlockState state = PaperLib.getBlockState(chest, false).getState();
- for (int i = 0; i < inv.getSize(); i++) {
- for (MachineFuel fuelType : miner.fuelTypes) {
- ItemStack item = inv.getContents()[i];
+ if (state instanceof Chest) {
+ Inventory inv = ((Chest) state).getBlockInventory();
- if (fuelType.test(item)) {
- ItemUtils.consumeItem(item, false);
+ for (int i = 0; i < inv.getSize(); i++) {
+ for (MachineFuel fuelType : miner.fuelTypes) {
+ ItemStack item = inv.getContents()[i];
- if (miner instanceof AdvancedIndustrialMiner) {
- inv.addItem(new ItemStack(Material.BUCKET));
+ if (fuelType.test(item)) {
+ ItemUtils.consumeItem(item, false);
+
+ if (miner instanceof AdvancedIndustrialMiner) {
+ inv.addItem(new ItemStack(Material.BUCKET));
+ }
+
+ return fuelType.getTicks();
}
-
- return fuelType.getTicks();
}
}
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java
index 7caf4b073..deb98ba23 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java
@@ -49,7 +49,7 @@ public class IndustrialMiner extends MultiBlockMachine {
private final boolean silkTouch;
public IndustrialMiner(Category category, SlimefunItemStack item, Material baseMaterial, boolean silkTouch, int range) {
- super(category, item, new ItemStack[] { null, null, null, new CustomItem(Material.PISTON, "Piston (facing up)"), new ItemStack(Material.CHEST), new CustomItem(Material.PISTON, "Piston (facing up)"), new ItemStack(baseMaterial), new ItemStack(SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14) ? Material.BLAST_FURNACE : Material.FURNACE), new ItemStack(baseMaterial) }, new ItemStack[0], BlockFace.UP);
+ super(category, item, new ItemStack[] { null, null, null, new CustomItem(Material.PISTON, "Piston (facing up)"), new ItemStack(Material.CHEST), new CustomItem(Material.PISTON, "Piston (facing up)"), new ItemStack(baseMaterial), new ItemStack(SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14) ? Material.BLAST_FURNACE : Material.FURNACE), new ItemStack(baseMaterial) }, BlockFace.UP);
this.range = range;
this.silkTouch = silkTouch;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/ChristmasPresent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/ChristmasPresent.java
index a408deb6e..bf0ffe8c7 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/ChristmasPresent.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/ChristmasPresent.java
@@ -8,10 +8,10 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class ChristmasPresent extends SimpleSlimefunItem implements NotPlaceable {
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/EasterEgg.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/EasterEgg.java
index 5073842d7..14660476a 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/EasterEgg.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/seasonal/EasterEgg.java
@@ -8,10 +8,10 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.utils.FireworkUtils;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java
index 770bcfe17..2ad1cb1b2 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java
@@ -21,10 +21,10 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
+import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
@@ -38,6 +38,7 @@ class ExplosiveTool extends SimpleSlimefunItem implements Not
public ExplosiveTool(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
+
addItemSetting(damageOnUse, callExplosionEvent);
}
@@ -54,6 +55,7 @@ class ExplosiveTool extends SimpleSlimefunItem implements Not
public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List drops) {
if (isItem(item)) {
Player p = e.getPlayer();
+
if (Slimefun.hasUnlocked(p, ExplosiveTool.this, true)) {
Block b = e.getBlock();
@@ -61,21 +63,7 @@ class ExplosiveTool extends SimpleSlimefunItem implements Not
b.getWorld().playSound(b.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.2F, 1F);
List blocks = findBlocks(b);
- if (callExplosionEvent.getValue().booleanValue()) {
- BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(b, blocks, 0);
- Bukkit.getServer().getPluginManager().callEvent(blockExplodeEvent);
-
- if (!blockExplodeEvent.isCancelled()) {
- for (Block block : blockExplodeEvent.blockList()) {
- breakBlock(p, item, block, fortune, drops);
- }
- }
- }
- else {
- for (Block block : blocks) {
- breakBlock(p, item, block, fortune, drops);
- }
- }
+ breakBlocks(p, item, b, blocks, fortune, drops);
}
return true;
@@ -87,6 +75,24 @@ class ExplosiveTool extends SimpleSlimefunItem implements Not
};
}
+ private void breakBlocks(Player p, ItemStack item, Block b, List blocks, int fortune, List drops) {
+ if (callExplosionEvent.getValue().booleanValue()) {
+ BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(b, blocks, 0);
+ Bukkit.getServer().getPluginManager().callEvent(blockExplodeEvent);
+
+ if (!blockExplodeEvent.isCancelled()) {
+ for (Block block : blockExplodeEvent.blockList()) {
+ breakBlock(p, item, block, fortune, drops);
+ }
+ }
+ }
+ else {
+ for (Block block : blocks) {
+ breakBlock(p, item, block, fortune, drops);
+ }
+ }
+ }
+
private List findBlocks(Block b) {
List blocks = new ArrayList<>(26);
@@ -112,7 +118,7 @@ class ExplosiveTool extends SimpleSlimefunItem implements Not
}
protected void breakBlock(Player p, ItemStack item, Block b, int fortune, List