mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 05:42:23 +00:00
More linked item changes
This commit is contained in:
1 parent
d394174108
commit
4a1a092757
15 files changed
+338
-436
No files matched your search
@@ -1,13 +1,22 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.controllers.data.EffectScript;
|
||||
import noppes.npcs.controllers.data.INpcScriptHandler;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
//TODO: load this data from somewhere, use in GUIs, create script wrapper
|
||||
//TODO: load this data from somewhere, use in GUIs
|
||||
public class LinkedItemController {
|
||||
private static LinkedItemController Instance;
|
||||
private final HashMap<String, LinkedItem> linkedItems = new HashMap<>();
|
||||
private int lastUsedID = 0;
|
||||
|
||||
private final HashMap<Integer, LinkedItem> linkedItems = new HashMap<>();
|
||||
private final HashMap<Integer, EffectScript> linkedItemsScripts = new HashMap<>();
|
||||
|
||||
private LinkedItemController() {
|
||||
}
|
||||
@@ -19,16 +28,64 @@ public class LinkedItemController {
|
||||
return Instance;
|
||||
}
|
||||
|
||||
public int getUnusedId() {
|
||||
for (int id : this.linkedItems.keySet()) {
|
||||
if (id > this.lastUsedID)
|
||||
this.lastUsedID = id;
|
||||
}
|
||||
this.lastUsedID++;
|
||||
return this.lastUsedID;
|
||||
}
|
||||
|
||||
private File getDir() {
|
||||
return new File(CustomNpcs.getWorldSaveDirectory(), "linkeditems");
|
||||
}
|
||||
|
||||
public LinkedItem createItem(String name) {
|
||||
return new LinkedItem(name);
|
||||
}
|
||||
|
||||
public void add(LinkedItem linkedItem) {
|
||||
if (linkedItem != null) {
|
||||
String name = linkedItem.getName();
|
||||
if (name != null && !name.isEmpty()) {
|
||||
this.linkedItems.put(name.toLowerCase(), linkedItem);
|
||||
int linkedItemId = linkedItem.getId();
|
||||
int id = this.linkedItems.containsKey(linkedItemId) ? linkedItemId : this.getUnusedId();
|
||||
this.linkedItems.put(id, linkedItem);
|
||||
linkedItem.setId(id);
|
||||
this.addScript(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public LinkedItem get(String name) {
|
||||
return name != null && !name.isEmpty() ? this.linkedItems.get(name.toLowerCase()) : null;
|
||||
@SideOnly(Side.SERVER)
|
||||
private void addScript(int id) {
|
||||
this.linkedItemsScripts.put(id, new EffectScript());
|
||||
}
|
||||
|
||||
public void remove(int id) {
|
||||
this.linkedItems.remove(id);
|
||||
this.removeScript(id);
|
||||
}
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
private void removeScript(int id) {
|
||||
this.linkedItemsScripts.remove(id);
|
||||
}
|
||||
|
||||
public LinkedItem get(int id) {
|
||||
return this.linkedItems.get(id);
|
||||
}
|
||||
|
||||
public boolean contains(int id) {
|
||||
return this.linkedItems.containsKey(id);
|
||||
}
|
||||
|
||||
public boolean contains(LinkedItem linkedItem) {
|
||||
return this.linkedItems.containsValue(linkedItem);
|
||||
}
|
||||
|
||||
public INpcScriptHandler getScriptHandler(int id) {
|
||||
return this.linkedItemsScripts.get(id);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user