58 lines
2 KiB
Java
58 lines
2 KiB
Java
/*
|
|
* Copyright (C) 2025 Minecon724
|
|
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
|
* in the project root for the full license text.
|
|
*/
|
|
|
|
package eu.m724.tweaks.redstone;
|
|
|
|
import eu.m724.tweaks.DebugLogger;
|
|
import eu.m724.tweaks.Language;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.NamespacedKey;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.ShapelessRecipe;
|
|
import org.bukkit.persistence.PersistentDataType;
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
public class GatewayItem {
|
|
private final NamespacedKey gatewayKey;
|
|
|
|
public GatewayItem(Plugin plugin) {
|
|
var start = System.nanoTime();
|
|
|
|
this.gatewayKey = new NamespacedKey(plugin, "gateway");
|
|
var recipe = new ShapelessRecipe(gatewayKey, itemStack());
|
|
|
|
// this takes a long time for some reason. The first one especially
|
|
// do this somewhere off measure to JIT and skew the measurement: new RecipeChoice.MaterialChoice(Material.DIRT);
|
|
recipe.addIngredient(Material.NETHER_STAR);
|
|
recipe.addIngredient(Material.ENDER_CHEST);
|
|
recipe.addIngredient(Material.CHORUS_FLOWER);
|
|
recipe.addIngredient(Material.DAYLIGHT_DETECTOR);
|
|
|
|
plugin.getServer().addRecipe(recipe);
|
|
|
|
DebugLogger.finer("Adding the recipe took %d ms, which is a long time", (System.nanoTime() - start) / 1000000);
|
|
}
|
|
|
|
public ItemStack itemStack() {
|
|
var itemStack = new ItemStack(Material.DAYLIGHT_DETECTOR);
|
|
var meta = itemStack.getItemMeta();
|
|
|
|
meta.setItemName(Language.getString("redstoneGatewayItem"));
|
|
meta.getPersistentDataContainer().set(gatewayKey, PersistentDataType.BOOLEAN, true);
|
|
meta.setEnchantmentGlintOverride(true);
|
|
|
|
itemStack.setItemMeta(meta);
|
|
return itemStack;
|
|
}
|
|
|
|
public boolean isGateway(ItemStack itemStack) {
|
|
var meta = itemStack.getItemMeta();
|
|
if (meta == null) return false;
|
|
var value = meta.getPersistentDataContainer().get(gatewayKey, PersistentDataType.BOOLEAN);
|
|
|
|
return value != null;
|
|
}
|
|
}
|