2016-04-14 16:24:03 +00:00
|
|
|
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import me.mrCookieSlime.Slimefun.SlimefunStartup;
|
|
|
|
import me.mrCookieSlime.Slimefun.AncientAltar.AltarRecipe;
|
|
|
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
2018-04-22 14:19:57 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.Research;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.handlers.BlockTicker;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.handlers.ItemHandler;
|
|
|
|
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
|
|
|
|
import me.mrCookieSlime.Slimefun.URID.URID;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.energy.EnergyNet;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.energy.EnergyNet.NetworkComponent;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.energy.EnergyTicker;
|
|
|
|
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
public class SlimefunItem {
|
|
|
|
|
|
|
|
public static List<SlimefunItem> items = new ArrayList<SlimefunItem>();
|
|
|
|
|
2017-10-13 14:34:38 +00:00
|
|
|
public static Map<String, URID> map_id = new HashMap<String, URID>();
|
2016-04-14 16:24:03 +00:00
|
|
|
public static List<ItemStack> radioactive = new ArrayList<ItemStack>();
|
|
|
|
public static int vanilla = 0;
|
|
|
|
public static Set<String> tickers = new HashSet<String>();
|
|
|
|
|
|
|
|
public static List<SlimefunItem> all = new ArrayList<SlimefunItem>();
|
|
|
|
public static Map<String, Set<ItemHandler>> handlers = new HashMap<String, Set<ItemHandler>>();
|
|
|
|
public static Map<String, SlimefunBlockHandler> blockhandler = new HashMap<String, SlimefunBlockHandler>();
|
2017-10-14 12:42:14 +00:00
|
|
|
|
|
|
|
private String id;
|
|
|
|
private URID urid;
|
|
|
|
private String hash;
|
|
|
|
private State state;
|
2017-10-13 13:56:48 +00:00
|
|
|
private ItemStack item;
|
|
|
|
private Category category;
|
|
|
|
private ItemStack[] recipe;
|
|
|
|
private RecipeType recipeType;
|
2017-10-14 12:42:14 +00:00
|
|
|
private ItemStack recipeOutput = null;
|
2017-10-13 13:56:48 +00:00
|
|
|
private Research research;
|
2017-10-14 12:42:14 +00:00
|
|
|
private int month = -1;
|
|
|
|
private boolean enchantable = true, disenchantable = true;
|
|
|
|
private boolean hidden = false;
|
|
|
|
private boolean replacing = false;
|
|
|
|
private boolean addon = false;
|
2017-10-14 08:55:50 +00:00
|
|
|
private String permission = "";
|
2017-10-14 12:42:14 +00:00
|
|
|
private Set<ItemHandler> itemhandlers = new HashSet<ItemHandler>();
|
2017-10-13 13:56:48 +00:00
|
|
|
private boolean ticking = false;
|
2017-10-14 12:42:14 +00:00
|
|
|
private BlockTicker blockTicker;
|
|
|
|
private EnergyTicker energyTicker;
|
|
|
|
private String[] keys = null;
|
|
|
|
private Object[] values = null;
|
2017-08-14 22:06:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines whether a SlimefunItem is enabled, disabled or fall-back to its vanilla behavior.
|
|
|
|
*
|
|
|
|
* @since 4.1.10
|
|
|
|
*/
|
2017-06-22 20:16:22 +00:00
|
|
|
public enum State {
|
2017-08-14 22:06:48 +00:00
|
|
|
/**
|
|
|
|
* This SlimefunItem is enabled.
|
|
|
|
*/
|
2017-06-22 20:16:22 +00:00
|
|
|
ENABLED,
|
2017-08-14 22:06:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This SlimefunItem is disabled and is not a {@link VanillaItem}.
|
|
|
|
*/
|
2017-06-22 20:16:22 +00:00
|
|
|
DISABLED,
|
2017-08-14 22:06:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This SlimefunItem is fall-back to its vanilla behavior, because it is disabled and is a {@link VanillaItem}.
|
|
|
|
*/
|
|
|
|
VANILLA
|
2017-06-22 20:16:22 +00:00
|
|
|
}
|
2016-04-14 16:24:03 +00:00
|
|
|
|
2017-10-13 14:34:38 +00:00
|
|
|
public SlimefunItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
|
2016-04-14 16:24:03 +00:00
|
|
|
this.item = item;
|
|
|
|
this.category = category;
|
2017-10-13 14:34:38 +00:00
|
|
|
this.id = id;
|
2016-04-14 16:24:03 +00:00
|
|
|
this.recipeType = recipeType;
|
|
|
|
this.recipe = recipe;
|
2017-10-14 12:42:14 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
urid = URID.nextURID(this, false);
|
|
|
|
}
|
|
|
|
|
2017-10-13 14:34:38 +00:00
|
|
|
public SlimefunItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
|
2016-04-14 16:24:03 +00:00
|
|
|
this.item = item;
|
|
|
|
this.category = category;
|
2017-10-13 14:34:38 +00:00
|
|
|
this.id = id;
|
2016-04-14 16:24:03 +00:00
|
|
|
this.recipeType = recipeType;
|
|
|
|
this.recipe = recipe;
|
|
|
|
this.recipeOutput = recipeOutput;
|
2017-10-14 12:42:14 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
urid = URID.nextURID(this, false);
|
|
|
|
}
|
|
|
|
|
2017-10-13 14:34:38 +00:00
|
|
|
public SlimefunItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput, String[] keys, Object[] values) {
|
2016-04-14 16:24:03 +00:00
|
|
|
this.item = item;
|
|
|
|
this.category = category;
|
2017-10-13 14:34:38 +00:00
|
|
|
this.id = id;
|
2016-04-14 16:24:03 +00:00
|
|
|
this.recipeType = recipeType;
|
|
|
|
this.recipe = recipe;
|
|
|
|
this.recipeOutput = recipeOutput;
|
|
|
|
this.keys = keys;
|
|
|
|
this.values = values;
|
2017-10-14 12:42:14 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
urid = URID.nextURID(this, false);
|
|
|
|
}
|
|
|
|
|
2017-10-13 14:34:38 +00:00
|
|
|
public SlimefunItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, String[] keys, Object[] values) {
|
2016-04-14 16:24:03 +00:00
|
|
|
this.item = item;
|
|
|
|
this.category = category;
|
2017-10-13 14:34:38 +00:00
|
|
|
this.id = id;
|
2016-04-14 16:24:03 +00:00
|
|
|
this.recipeType = recipeType;
|
|
|
|
this.recipe = recipe;
|
|
|
|
this.keys = keys;
|
|
|
|
this.values = values;
|
2017-10-14 12:42:14 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
urid = URID.nextURID(this, false);
|
|
|
|
}
|
|
|
|
|
2017-10-14 12:42:14 +00:00
|
|
|
public SlimefunItem(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe, boolean hidden) {
|
2016-04-14 16:24:03 +00:00
|
|
|
this.item = item;
|
|
|
|
this.category = category;
|
2017-10-13 14:34:38 +00:00
|
|
|
this.id = id;
|
2016-04-14 16:24:03 +00:00
|
|
|
this.recipeType = recipeType;
|
|
|
|
this.recipe = recipe;
|
2017-10-14 12:42:14 +00:00
|
|
|
this.hidden = hidden;
|
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
urid = URID.nextURID(this, false);
|
|
|
|
}
|
2017-10-14 12:42:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the identifier of this SlimefunItem.
|
|
|
|
*
|
|
|
|
* @return the identifier of this SlimefunItem
|
|
|
|
*
|
|
|
|
* @since 4.0
|
|
|
|
* @deprecated As of 4.1.11, renamed to {@link #getID()} for better name convenience.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2017-11-23 21:21:02 +00:00
|
|
|
public String getName() { return id; }
|
2017-10-14 12:42:14 +00:00
|
|
|
/**
|
|
|
|
* Returns the identifier of this SlimefunItem.
|
|
|
|
*
|
|
|
|
* @return the identifier of this SlimefunItem
|
|
|
|
*
|
|
|
|
* @since 4.1.11, rename of {@link #getName()}.
|
|
|
|
*/
|
2017-11-23 21:21:02 +00:00
|
|
|
public String getID() { return id; }
|
2017-10-14 12:42:14 +00:00
|
|
|
public URID getURID() { return urid; }
|
|
|
|
public String getHash() { return hash; }
|
|
|
|
public State getState() { return state; }
|
|
|
|
public ItemStack getItem() { return item; }
|
2017-11-23 21:21:02 +00:00
|
|
|
public Category getCategory() { return category; }
|
|
|
|
public ItemStack[] getRecipe() { return recipe; }
|
|
|
|
public RecipeType getRecipeType() { return recipeType; }
|
2017-10-14 12:42:14 +00:00
|
|
|
/**
|
|
|
|
* @since 4.0
|
|
|
|
* @deprecated As of 4.1.11, renamed to {@link #getRecipeOutput()} for better name convenience.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2017-11-23 21:21:02 +00:00
|
|
|
public ItemStack getCustomOutput() { return recipeOutput; }
|
2017-10-14 12:42:14 +00:00
|
|
|
/**
|
|
|
|
* @since 4.1.11, rename of {@link #getCustomOutput()}.
|
|
|
|
*/
|
2017-11-23 21:21:02 +00:00
|
|
|
public ItemStack getRecipeOutput() { return recipeOutput; }
|
|
|
|
public Research getResearch() { return research; }
|
2017-10-14 12:42:14 +00:00
|
|
|
public int getMonth() { return month; }
|
2017-11-23 21:21:02 +00:00
|
|
|
public boolean isEnchantable() { return enchantable; }
|
|
|
|
public boolean isDisenchantable() { return disenchantable; }
|
2017-10-14 12:42:14 +00:00
|
|
|
/**
|
|
|
|
* @since 4.1.11
|
|
|
|
*/
|
|
|
|
public boolean isHidden() { return hidden; }
|
2017-11-23 21:21:02 +00:00
|
|
|
public boolean isReplacing() { return replacing; }
|
|
|
|
public boolean isAddonItem() { return addon; }
|
2017-10-14 12:42:14 +00:00
|
|
|
/**
|
|
|
|
* @since 4.1.11
|
|
|
|
*/
|
2017-11-23 21:21:02 +00:00
|
|
|
public String getPermission() { return permission; }
|
|
|
|
public Set<ItemHandler> getHandlers() { return itemhandlers; }
|
2017-10-14 12:42:14 +00:00
|
|
|
public boolean isTicking() { return ticking; }
|
|
|
|
/**
|
|
|
|
* @since 4.0
|
|
|
|
* @deprecated As of 4.1.11, renamed to {@link #getBlockTicker()} for better name convenience.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2017-11-23 21:21:02 +00:00
|
|
|
public BlockTicker getTicker() { return blockTicker; }
|
2017-10-14 12:42:14 +00:00
|
|
|
/**
|
|
|
|
* @since 4.1.11, rename of {@link #getTicker()}.
|
|
|
|
*/
|
2017-11-23 21:21:02 +00:00
|
|
|
public BlockTicker getBlockTicker() { return blockTicker; }
|
|
|
|
public EnergyTicker getEnergyTicker() { return energyTicker; }
|
2017-10-14 12:42:14 +00:00
|
|
|
public String[] listKeys() { return keys; }
|
2017-11-23 21:21:02 +00:00
|
|
|
public Object[] listValues() { return values; }
|
2017-10-14 12:42:14 +00:00
|
|
|
public boolean isDisabled() { return state != State.ENABLED; }
|
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public void register() {
|
|
|
|
register(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void register(boolean slimefun) {
|
2017-11-23 21:16:45 +00:00
|
|
|
this.addon = !slimefun;
|
2016-04-14 16:24:03 +00:00
|
|
|
try {
|
2017-12-26 14:45:52 +00:00
|
|
|
if (map_id.containsKey(this.id)) throw new IllegalArgumentException("ID \"" + this.id + "\" already exists");
|
2017-11-23 21:16:45 +00:00
|
|
|
if (this.recipe.length < 9) this.recipe = new ItemStack[] {null, null, null, null, null, null, null, null, null};
|
2016-04-14 16:24:03 +00:00
|
|
|
all.add(this);
|
|
|
|
|
2017-11-23 21:16:45 +00:00
|
|
|
SlimefunStartup.getItemCfg().setDefaultValue(this.id + ".enabled", true);
|
|
|
|
SlimefunStartup.getItemCfg().setDefaultValue(this.id + ".can-be-used-in-workbenches", this.replacing);
|
|
|
|
SlimefunStartup.getItemCfg().setDefaultValue(this.id + ".hide-in-guide", this.hidden);
|
|
|
|
SlimefunStartup.getItemCfg().setDefaultValue(this.id + ".allow-enchanting", this.enchantable);
|
|
|
|
SlimefunStartup.getItemCfg().setDefaultValue(this.id + ".allow-disenchanting", this.disenchantable);
|
|
|
|
SlimefunStartup.getItemCfg().setDefaultValue(this.id + ".required-permission", this.permission);
|
|
|
|
if (this.keys != null && this.values != null) {
|
|
|
|
for (int i = 0; i < this.keys.length; i++) {
|
|
|
|
SlimefunStartup.getItemCfg().setDefaultValue(this.id + "." + this.keys[i], this.values[i]);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (World world: Bukkit.getWorlds()) {
|
|
|
|
SlimefunStartup.getWhitelist().setDefaultValue(world.getName() + ".enabled", true);
|
2017-11-23 21:16:45 +00:00
|
|
|
SlimefunStartup.getWhitelist().setDefaultValue(world.getName() + ".enabled-items." + this.id, true);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 21:16:45 +00:00
|
|
|
if (this.ticking && !SlimefunStartup.getCfg().getBoolean("URID.enable-tickers")) {
|
|
|
|
this.state = State.DISABLED;
|
2017-06-22 20:54:19 +00:00
|
|
|
return;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-06-22 20:49:36 +00:00
|
|
|
|
2017-10-14 12:42:14 +00:00
|
|
|
if (SlimefunStartup.getItemCfg().getBoolean(id + ".enabled")) {
|
2016-04-14 16:24:03 +00:00
|
|
|
if (!Category.list().contains(category)) category.register();
|
2017-06-22 20:16:22 +00:00
|
|
|
|
2017-11-23 21:23:50 +00:00
|
|
|
this.state = State.ENABLED;
|
2017-06-22 20:16:22 +00:00
|
|
|
|
2017-11-23 21:16:45 +00:00
|
|
|
this.replacing = SlimefunStartup.getItemCfg().getBoolean(this.id + ".can-be-used-in-workbenches");
|
|
|
|
this.hidden = SlimefunStartup.getItemCfg().getBoolean(this.id + ".hide-in-guide");
|
|
|
|
this.enchantable = SlimefunStartup.getItemCfg().getBoolean(this.id + ".allow-enchanting");
|
|
|
|
this.disenchantable = SlimefunStartup.getItemCfg().getBoolean(this.id + ".allow-disenchanting");
|
|
|
|
this.permission = SlimefunStartup.getItemCfg().getString(this.id + ".required-permission");
|
2016-04-14 16:24:03 +00:00
|
|
|
items.add(this);
|
|
|
|
if (slimefun) vanilla++;
|
2017-11-23 21:23:50 +00:00
|
|
|
map_id.put(this.id, this.urid);
|
|
|
|
this.create();
|
2016-04-14 16:24:03 +00:00
|
|
|
for (ItemHandler handler: itemhandlers) {
|
|
|
|
Set<ItemHandler> handlerset = getHandlers(handler.toCodename());
|
|
|
|
handlerset.add(handler);
|
|
|
|
handlers.put(handler.toCodename(), handlerset);
|
|
|
|
}
|
|
|
|
|
2017-11-23 21:23:50 +00:00
|
|
|
if (SlimefunStartup.getCfg().getBoolean("options.print-out-loading")) System.out.println("[Slimefun] Loaded Item \"" + this.id + "\"");
|
2017-06-22 20:44:38 +00:00
|
|
|
} else {
|
2017-11-23 21:16:45 +00:00
|
|
|
if (this instanceof VanillaItem) this.state = State.VANILLA;
|
|
|
|
else this.state = State.DISABLED;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
} catch(Exception x) {
|
2017-11-23 21:23:50 +00:00
|
|
|
System.err.println("[Slimefun] Item Registration failed: " + this.id);
|
2017-12-26 14:44:18 +00:00
|
|
|
x.printStackTrace();
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<SlimefunItem> list() {
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void bindToResearch(Research r) {
|
2017-06-23 11:06:08 +00:00
|
|
|
if (r != null) r.getEffectedItems().add(this);
|
2016-04-14 16:24:03 +00:00
|
|
|
this.research = r;
|
|
|
|
}
|
2017-10-14 12:42:14 +00:00
|
|
|
|
|
|
|
public void setHash(String hash) {
|
|
|
|
this.hash = hash;
|
|
|
|
}
|
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public void setRecipe(ItemStack[] recipe) {
|
|
|
|
this.recipe = recipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRecipeType(RecipeType type) {
|
|
|
|
this.recipeType = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCategory(Category category) {
|
|
|
|
this.category = category;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRecipeOutput(ItemStack output) {
|
|
|
|
this.recipeOutput = output;
|
|
|
|
}
|
2017-10-13 14:34:38 +00:00
|
|
|
|
2017-10-14 12:42:14 +00:00
|
|
|
public void setReplacing(boolean replacing) {
|
|
|
|
this.replacing = replacing;
|
|
|
|
}
|
|
|
|
|
2017-10-13 14:34:38 +00:00
|
|
|
/**
|
|
|
|
* @since 4.0
|
|
|
|
* @deprecated As of 4.1.11, renamed to {@link #getByID(String)} for better name convenience.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2016-04-14 16:24:03 +00:00
|
|
|
public static SlimefunItem getByName(String name) {
|
2017-10-13 14:34:38 +00:00
|
|
|
return (SlimefunItem) URID.decode(map_id.get(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 4.1.11, rename of {@link #getByName(String)}.
|
|
|
|
*/
|
|
|
|
public static SlimefunItem getByID(String id) {
|
|
|
|
return (SlimefunItem) URID.decode(map_id.get(id));
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static SlimefunItem getByItem(ItemStack item) {
|
2018-04-22 16:47:22 +00:00
|
|
|
if (item == null) return null;
|
2018-04-24 00:34:53 +00:00
|
|
|
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BROKEN_SPAWNER, false)) return getByID("BROKEN_SPAWNER");
|
2018-05-05 13:20:10 +00:00
|
|
|
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.REPAIRED_SPAWNER, false)) return getByID("REINFORCED_SPAWNER");
|
2016-04-14 16:24:03 +00:00
|
|
|
for (SlimefunItem sfi: items) {
|
|
|
|
if (sfi instanceof ChargableItem && SlimefunManager.isItemSimiliar(item, sfi.getItem(), false)) return sfi;
|
|
|
|
else if (sfi instanceof DamagableChargableItem && SlimefunManager.isItemSimiliar(item, sfi.getItem(), false)) return sfi;
|
|
|
|
else if (sfi instanceof ChargedItem && SlimefunManager.isItemSimiliar(item, sfi.getItem(), false)) return sfi;
|
2018-04-22 16:11:51 +00:00
|
|
|
else if (sfi instanceof SlimefunBackpack && SlimefunManager.isItemSimiliar(item, sfi.getItem(), false)) return sfi;
|
2018-04-22 14:19:57 +00:00
|
|
|
else if (SlimefunManager.isItemSimiliar(item, sfi.getItem(), true)) return sfi;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isItem(ItemStack item) {
|
|
|
|
if (item == null) return false;
|
2017-10-14 12:42:14 +00:00
|
|
|
if (this instanceof ChargableItem && SlimefunManager.isItemSimiliar(item, this.item, false)) return true;
|
|
|
|
else if (this instanceof DamagableChargableItem && SlimefunManager.isItemSimiliar(item, this.item, false)) return true;
|
|
|
|
else if (this instanceof ChargedItem && SlimefunManager.isItemSimiliar(item, this.item, false)) return true;
|
2018-04-24 00:34:53 +00:00
|
|
|
else return SlimefunManager.isItemSimiliar(item, this.item, true);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void load() {
|
|
|
|
try {
|
2017-10-14 12:42:14 +00:00
|
|
|
if (!hidden) category.add(this);
|
|
|
|
ItemStack output = item.clone();
|
|
|
|
if (recipeOutput != null) output = recipeOutput.clone();
|
2017-10-13 14:34:38 +00:00
|
|
|
|
2017-10-14 12:42:14 +00:00
|
|
|
if (recipeType.toItem().isSimilar(RecipeType.MOB_DROP.toItem())) {
|
2016-04-14 16:24:03 +00:00
|
|
|
try {
|
|
|
|
EntityType entity = EntityType.valueOf(ChatColor.stripColor(recipe[4].getItemMeta().getDisplayName()).toUpperCase().replace(" ", "_"));
|
|
|
|
List<ItemStack> dropping = new ArrayList<ItemStack>();
|
|
|
|
if (SlimefunManager.drops.containsKey(entity)) dropping = SlimefunManager.drops.get(entity);
|
|
|
|
dropping.add(output);
|
|
|
|
SlimefunManager.drops.put(entity, dropping);
|
|
|
|
} catch(Exception x) {
|
|
|
|
}
|
|
|
|
}
|
2017-10-14 12:42:14 +00:00
|
|
|
else if (recipeType.toItem().isSimilar(RecipeType.ANCIENT_ALTAR.toItem())) {
|
|
|
|
new AltarRecipe(Arrays.asList(recipe), output);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-10-14 12:42:14 +00:00
|
|
|
else if (recipeType.getMachine() != null && getByID(recipeType.getMachine().getID()) instanceof SlimefunMachine) {
|
|
|
|
((SlimefunMachine) getByID(recipeType.getMachine().getID())).addRecipe(recipe, output);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2017-10-14 12:42:14 +00:00
|
|
|
install();
|
2016-04-14 16:24:03 +00:00
|
|
|
} catch(Exception x) {
|
2017-10-14 12:42:14 +00:00
|
|
|
System.err.println("[Slimefun] Item Initialization failed: " + id);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-22 20:16:22 +00:00
|
|
|
public static State getState(ItemStack item) {
|
|
|
|
for (SlimefunItem i: all) {
|
2017-11-23 21:21:02 +00:00
|
|
|
if (i.isItem(item)) {
|
|
|
|
return i.getState();
|
|
|
|
}
|
2017-06-22 20:16:22 +00:00
|
|
|
}
|
2017-11-23 21:21:02 +00:00
|
|
|
return State.ENABLED;
|
2017-06-22 20:16:22 +00:00
|
|
|
}
|
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public static boolean isDisabled(ItemStack item) {
|
2017-06-22 20:16:22 +00:00
|
|
|
for (SlimefunItem i: all) {
|
2016-04-14 16:24:03 +00:00
|
|
|
if (i.isItem(item)) {
|
2017-06-22 20:16:22 +00:00
|
|
|
return i.isDisabled();
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-22 20:16:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public void install() {}
|
|
|
|
public void create() {}
|
2017-10-13 19:12:33 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public void addItemHandler(ItemHandler... handler) {
|
|
|
|
this.itemhandlers.addAll(Arrays.asList(handler));
|
|
|
|
|
|
|
|
for (ItemHandler h: handler) {
|
|
|
|
if (h instanceof BlockTicker) {
|
|
|
|
this.ticking = true;
|
2017-10-13 14:34:38 +00:00
|
|
|
tickers.add(getID());
|
2017-10-14 12:42:14 +00:00
|
|
|
this.blockTicker = (BlockTicker) h;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
else if (h instanceof EnergyTicker) {
|
2017-10-14 12:42:14 +00:00
|
|
|
this.energyTicker = (EnergyTicker) h;
|
2017-10-13 14:34:38 +00:00
|
|
|
EnergyNet.registerComponent(getID(), NetworkComponent.SOURCE);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void register(boolean vanilla, ItemHandler... handlers) {
|
|
|
|
addItemHandler(handlers);
|
|
|
|
register(vanilla);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void register(ItemHandler... handlers) {
|
|
|
|
addItemHandler(handlers);
|
|
|
|
register(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void register(boolean vanilla, SlimefunBlockHandler handler) {
|
2017-10-13 14:34:38 +00:00
|
|
|
blockhandler.put(getID(), handler);
|
2016-04-14 16:24:03 +00:00
|
|
|
register(vanilla);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void register(SlimefunBlockHandler handler) {
|
2017-10-13 14:34:38 +00:00
|
|
|
blockhandler.put(getID(), handler);
|
2016-04-14 16:24:03 +00:00
|
|
|
register(false);
|
|
|
|
}
|
|
|
|
|
2017-10-13 14:34:38 +00:00
|
|
|
public static Set<ItemHandler> getHandlers(String codeid) {
|
|
|
|
if (handlers.containsKey(codeid)) return handlers.get(codeid);
|
2016-04-14 16:24:03 +00:00
|
|
|
else return new HashSet<ItemHandler>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setRadioactive(ItemStack item) {
|
|
|
|
radioactive.add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack getItem(String id) {
|
2017-10-13 14:34:38 +00:00
|
|
|
SlimefunItem item = getByID(id);
|
2016-04-14 16:24:03 +00:00
|
|
|
return item != null ? item.getItem(): null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void patchExistingItem(String id, ItemStack stack) {
|
2017-10-13 14:34:38 +00:00
|
|
|
SlimefunItem item = getByID(id);
|
2016-04-14 16:24:03 +00:00
|
|
|
if (item != null) {
|
|
|
|
System.out.println("[Slimefun] WARNING - Patching existing Item - " + id);
|
|
|
|
System.out.println("[Slimefun] This might take a while");
|
|
|
|
|
|
|
|
final ItemStack old = item.getItem();
|
|
|
|
item.setItem(stack);
|
|
|
|
for (SlimefunItem sfi: list()) {
|
|
|
|
ItemStack[] recipe = sfi.getRecipe();
|
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
if (SlimefunManager.isItemSimiliar(recipe[i], old, true)) recipe[i] = stack;
|
|
|
|
}
|
|
|
|
sfi.setRecipe(recipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void registerChargeableBlock(int capacity) {
|
|
|
|
this.registerChargeableBlock(false, capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void registerChargeableBlock(boolean slimefun, int capacity) {
|
|
|
|
this.register(slimefun);
|
2017-10-13 14:34:38 +00:00
|
|
|
ChargableBlock.registerChargableBlock(id, capacity, true);
|
|
|
|
EnergyNet.registerComponent(id, NetworkComponent.CONSUMER);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void registerUnrechargeableBlock(boolean slimefun, int capacity) {
|
|
|
|
this.register(slimefun);
|
2017-10-13 14:34:38 +00:00
|
|
|
ChargableBlock.registerChargableBlock(id, capacity, false);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void registerBlockCapacitor(boolean slimefun, int capacity) {
|
|
|
|
this.register(slimefun);
|
2017-10-13 14:34:38 +00:00
|
|
|
ChargableBlock.registerCapacitor(id, capacity);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void registerEnergyDistributor(boolean slimefun) {
|
|
|
|
this.register(slimefun);
|
2017-10-13 14:34:38 +00:00
|
|
|
EnergyNet.registerComponent(id, NetworkComponent.DISTRIBUTOR);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void registerDistibutingCapacitor(boolean slimefun, final int capacity) {
|
|
|
|
this.register(slimefun);
|
2017-10-13 14:34:38 +00:00
|
|
|
EnergyNet.registerComponent(id, NetworkComponent.DISTRIBUTOR);
|
|
|
|
ChargableBlock.registerCapacitor(id, capacity);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void setItem(ItemStack stack) {
|
|
|
|
this.item = stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isTicking(String item) {
|
|
|
|
return tickers.contains(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void registerBlockHandler(String id, SlimefunBlockHandler handler) {
|
|
|
|
blockhandler.put(id, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void registerChargeableBlock(boolean vanilla, int capacity, ItemHandler... handlers) {
|
|
|
|
addItemHandler(handlers);
|
|
|
|
registerChargeableBlock(vanilla, capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockMenu getBlockMenu(Block b) {
|
|
|
|
return BlockStorage.getInventory(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addWikipage(String page) {
|
2017-11-23 21:11:32 +00:00
|
|
|
Slimefun.addWikiPage(this.getID(), "https://github.com/TheBusyBiscuit/Slimefun4/wiki/" + page);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|