Added handler support to NPC API.

This commit is contained in:
luisc committed 2022-01-10 15:21:48 -06:00
1 parent 69f96519dc
commit d50f51e208
40 files changed
+1471 -56

No files matched your search

@@ -2,6 +2,7 @@ package noppes.npcs.controllers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import noppes.npcs.ICompatibilty;
import noppes.npcs.VersionCompatibility;
import noppes.npcs.constants.EnumAvailabilityDialog;
@@ -9,8 +10,11 @@ import noppes.npcs.constants.EnumAvailabilityFaction;
import noppes.npcs.constants.EnumAvailabilityFactionType;
import noppes.npcs.constants.EnumAvailabilityQuest;
import noppes.npcs.constants.EnumDayTime;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.handler.data.IAvailability;
import noppes.npcs.scripted.interfaces.IPlayer;
public class Availability implements ICompatibilty {
public class Availability implements ICompatibilty, IAvailability {
public int version = VersionCompatibility.ModRev;
public EnumAvailabilityDialog dialogAvailable = EnumAvailabilityDialog.Always;
@@ -178,7 +182,7 @@ public class Availability implements ICompatibilty {
if(available == EnumAvailabilityFactionType.Always)
return true;
Faction faction = FactionController.getInstance().getFaction(id);
Faction faction = FactionController.getInstance().get(id);
if(faction == null)
return true;
@@ -233,4 +237,170 @@ public class Availability implements ICompatibilty {
public void setVersion(int version) {
this.version = version;
}
public boolean isAvailable(IPlayer player) {
return this.isAvailable((EntityPlayer)player.getMCEntity());
}
public int getDaytime() {
return this.daytime.ordinal();
}
public void setDaytime(int type) {
this.daytime = EnumDayTime.values()[MathHelper.clamp_int(type, 0, 2)];
}
public int getMinPlayerLevel() {
return this.minPlayerLevel;
}
public void setMinPlayerLevel(int level) {
this.minPlayerLevel = level;
}
public int getDialog(int i) {
if (i < 0 && i > 3) {
throw new CustomNPCsException(i + " isnt between 0 and 3", new Object[0]);
} else if (i == 0) {
return this.dialogId;
} else if (i == 1) {
return this.dialog2Id;
} else {
return i == 2 ? this.dialog3Id : this.dialog4Id;
}
}
public void setDialog(int i, int id, int type) {
if (i < 0 && i > 3) {
throw new CustomNPCsException(i + " isnt between 0 and 3", new Object[0]);
} else {
EnumAvailabilityDialog e = EnumAvailabilityDialog.values()[MathHelper.clamp_int(type, 0, 2)];
if (i == 0) {
this.dialogId = id;
this.dialogAvailable = e;
} else if (i == 1) {
this.dialog2Id = id;
this.dialog2Available = e;
} else if (i == 2) {
this.dialog3Id = id;
this.dialog3Available = e;
} else if (i == 3) {
this.dialog4Id = id;
this.dialog4Available = e;
}
}
}
public void removeDialog(int i) {
if (i < 0 && i > 3) {
throw new CustomNPCsException(i + " isnt between 0 and 3", new Object[0]);
} else {
if (i == 0) {
this.dialogId = -1;
this.dialogAvailable = EnumAvailabilityDialog.Always;
} else if (i == 1) {
this.dialog2Id = -1;
this.dialog2Available = EnumAvailabilityDialog.Always;
} else if (i == 2) {
this.dialog3Id = -1;
this.dialog3Available = EnumAvailabilityDialog.Always;
} else if (i == 3) {
this.dialog4Id = -1;
this.dialog4Available = EnumAvailabilityDialog.Always;
}
}
}
public int getQuest(int i) {
if (i < 0 && i > 3) {
throw new CustomNPCsException(i + " isnt between 0 and 3", new Object[0]);
} else if (i == 0) {
return this.questId;
} else if (i == 1) {
return this.quest2Id;
} else {
return i == 2 ? this.quest3Id : this.quest4Id;
}
}
public void setQuest(int i, int id, int type) {
if (i < 0 && i > 3) {
throw new CustomNPCsException(i + " isnt between 0 and 3", new Object[0]);
} else {
EnumAvailabilityQuest e = EnumAvailabilityQuest.values()[MathHelper.clamp_int(type, 0, 5)];
if (i == 0) {
this.questId = id;
this.questAvailable = e;
} else if (i == 1) {
this.quest2Id = id;
this.quest2Available = e;
} else if (i == 2) {
this.quest3Id = id;
this.quest3Available = e;
} else if (i == 3) {
this.quest4Id = id;
this.quest4Available = e;
}
}
}
public void removeQuest(int i) {
if (i < 0 && i > 3) {
throw new CustomNPCsException(i + " isnt between 0 and 3", new Object[0]);
} else {
if (i == 0) {
this.questId = -1;
this.questAvailable = EnumAvailabilityQuest.Always;
} else if (i == 1) {
this.quest2Id = -1;
this.quest2Available = EnumAvailabilityQuest.Always;
} else if (i == 2) {
this.quest3Id = -1;
this.quest3Available = EnumAvailabilityQuest.Always;
} else if (i == 3) {
this.quest4Id = -1;
this.quest4Available = EnumAvailabilityQuest.Always;
}
}
}
public void setFaction(int i, int id, int type, int stance) {
if (i < 0 && i > 1) {
throw new CustomNPCsException(i + " isnt between 0 and 1", new Object[0]);
} else {
EnumAvailabilityFactionType e = EnumAvailabilityFactionType.values()[MathHelper.clamp_int(type, 0, 2)];
EnumAvailabilityFaction ee = EnumAvailabilityFaction.values()[MathHelper.clamp_int(stance, 0, 2)];
if (i == 0) {
this.factionId = id;
this.factionAvailable = e;
this.factionStance = ee;
} else if (i == 1) {
this.faction2Id = id;
this.faction2Available = e;
this.faction2Stance = ee;
}
}
}
public void removeFaction(int i) {
if (i < 0 && i > 1) {
throw new CustomNPCsException(i + " isnt between 0 and 1", new Object[0]);
} else {
if (i == 0) {
this.factionId = -1;
this.factionAvailable = EnumAvailabilityFactionType.Always;
this.factionStance = EnumAvailabilityFaction.Friendly;
} else if (i == 1) {
this.faction2Id = -1;
this.faction2Available = EnumAvailabilityFactionType.Always;
this.faction2Stance = EnumAvailabilityFaction.Friendly;
}
}
}
}
@@ -1,6 +1,8 @@
package noppes.npcs.controllers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
@@ -8,8 +10,10 @@ import net.minecraft.nbt.NBTTagList;
import noppes.npcs.ICompatibilty;
import noppes.npcs.VersionCompatibility;
import noppes.npcs.constants.EnumOptionType;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.handler.data.*;
public class Dialog implements ICompatibilty {
public class Dialog implements ICompatibilty, IDialog {
public int version = VersionCompatibility.ModRev;
public int id = -1;
public String title = "";
@@ -108,9 +112,7 @@ public class Dialog implements ICompatibilty {
public boolean hasQuest() {
return getQuest() != null;
}
public Quest getQuest() {
return QuestController.instance.quests.get(quest);
}
public boolean hasOtherOptions() {
for(DialogOption option: options.values())
if(option != null && option.optionType != EnumOptionType.Disabled)
@@ -148,5 +150,74 @@ public class Dialog implements ICompatibilty {
public void setVersion(int version) {
this.version = version;
}
public int getId() {
return this.id;
}
public String getName() {
return this.title;
}
public List<IDialogOption> getOptions() {
return new ArrayList(this.options.values());
}
public IDialogOption getOption(int slot) {
IDialogOption option = (IDialogOption)this.options.get(slot);
if (option == null) {
throw new CustomNPCsException("There is no DialogOption for slot: " + slot, new Object[0]);
} else {
return option;
}
}
public IAvailability getAvailability() {
return this.availability;
}
public IDialogCategory getCategory() {
return this.category;
}
public void save() {
DialogController.instance.saveDialog(this.category.id, this);
}
public void setName(String name) {
this.title = name;
}
public String getText() {
return this.text;
}
public void setText(String text) {
this.text = text;
}
public void setQuest(IQuest quest) {
if (quest == null) {
this.quest = -1;
} else {
if (quest.getId() < 0) {
throw new CustomNPCsException("Quest id is lower than 0", new Object[0]);
}
this.quest = quest.getId();
}
}
public Quest getQuest() {
return QuestController.instance == null ? null : (Quest)QuestController.instance.quests.get(this.quest);
}
public String getCommand() {
return this.command;
}
public void setCommand(String command) {
this.command = command;
}
}
@@ -1,11 +1,15 @@
package noppes.npcs.controllers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.scripted.handler.data.IDialog;
import noppes.npcs.scripted.handler.data.IDialogCategory;
public class DialogCategory {
public class DialogCategory implements IDialogCategory {
public int id = -1;
public String title = "";
@@ -43,4 +47,18 @@ public class DialogCategory {
nbtfactions.setTag("Dialogs", dialogs);
return nbtfactions;
}
public List<IDialog> dialogs() {
return new ArrayList(this.dialogs.values());
}
public String getName() {
return this.title;
}
public IDialog create() {
Dialog dialog = new Dialog();
dialog.category = this;
return dialog;
}
}
@@ -2,9 +2,7 @@ package noppes.npcs.controllers;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.*;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
@@ -13,9 +11,12 @@ import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.constants.EnumOptionType;
import noppes.npcs.scripted.handler.IDialogHandler;
import noppes.npcs.scripted.handler.data.IDialog;
import noppes.npcs.scripted.handler.data.IDialogCategory;
import noppes.npcs.util.NBTJsonUtil;
public class DialogController {
public class DialogController implements IDialogHandler {
public HashMap<Integer,DialogCategory> categories = new HashMap<Integer, DialogCategory>();
public HashMap<Integer,Dialog> dialogs = new HashMap<Integer, Dialog>();
public static DialogController instance;
@@ -312,4 +313,12 @@ public class DialogController {
}
return map;
}
public List<IDialogCategory> categories() {
return new ArrayList(this.categories.values());
}
public IDialog get(int id) {
return (IDialog)this.dialogs.get(id);
}
}
@@ -1,13 +1,18 @@
package noppes.npcs.controllers;
import java.util.HashSet;
import java.util.Iterator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NBTTags;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.handler.data.IFaction;
import noppes.npcs.scripted.interfaces.ICustomNpc;
import noppes.npcs.scripted.interfaces.IPlayer;
public class Faction {
public class Faction implements IFaction {
public String name = "";
public int color = Integer.parseInt("FF00", 16);
@@ -85,4 +90,90 @@ public class Faction {
public boolean isAggressiveToNpc(EntityNPCInterface entity) {
return attackFactions.contains(entity.faction.id);
}
public int getId() {
return this.id;
}
public String getName() {
return this.name;
}
public int getDefaultPoints() {
return this.defaultPoints;
}
public int getColor() {
return this.color;
}
public int playerStatus(IPlayer player) {
PlayerFactionData data = PlayerData.get((EntityPlayer) player.getMCEntity()).factionData;
int points = data.getFactionPoints(this.id);
if (points >= this.friendlyPoints) {
return 1;
} else {
return points < this.neutralPoints ? -1 : 0;
}
}
public boolean hostileToNpc(ICustomNpc npc) {
return this.attackFactions.contains(npc.getFaction().getId());
}
public void setDefaultPoints(int points) {
this.defaultPoints = points;
}
public boolean hostileToFaction(int factionId) {
return this.attackFactions.contains(factionId);
}
public int[] getHostileList() {
int[] a = new int[this.attackFactions.size()];
int i = 0;
Integer val;
for(Iterator var3 = this.attackFactions.iterator(); var3.hasNext(); a[i++] = val) {
val = (Integer)var3.next();
}
return a;
}
public void addHostile(int id) {
if (this.attackFactions.contains(id)) {
throw new CustomNPCsException("Faction " + this.id + " is already hostile to " + id, new Object[0]);
} else {
this.attackFactions.add(id);
}
}
public void removeHostile(int id) {
this.attackFactions.remove(id);
}
public boolean hasHostile(int id) {
return this.attackFactions.contains(id);
}
public boolean getIsHidden() {
return this.hideFaction;
}
public void setIsHidden(boolean bo) {
this.hideFaction = bo;
}
public boolean getAttackedByMobs() {
return this.getsAttacked;
}
public void setAttackedByMobs(boolean bo) {
this.getsAttacked = bo;
}
public void save() {
FactionController.getInstance().saveFaction(this);
}
}
@@ -6,7 +6,9 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
@@ -15,8 +17,12 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.Server;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.scripted.handler.IFactionHandler;
import noppes.npcs.scripted.handler.data.IFaction;
public class FactionController {
public class FactionController implements IFactionHandler {
public HashMap<Integer,Faction> factions;
private static FactionController instance;
@@ -124,10 +130,14 @@ public class FactionController {
}
}
public Faction getFaction(int faction) {
public Faction get(int faction) {
return factions.get(faction);
}
public List<IFaction> list() {
return new ArrayList(this.factions.values());
}
public void saveFaction(Faction faction) {
if(faction.id < 0){
@@ -145,6 +155,30 @@ public class FactionController {
factions.put(faction.id, faction);
saveFactions();
}
public Faction create(Faction faction) {
String name = faction.getName();
int color = faction.getColor();
for(faction = new Faction(); this.hasName(name); name = name + "_") {
}
faction.name = name;
faction.color = color;
this.saveFaction(faction);
return faction;
}
public Faction create(String name, int color) {
Faction faction;
for(faction = new Faction(); this.hasName(name); name = name + "_") {
}
faction.name = name;
faction.color = color;
this.saveFaction(faction);
return faction;
}
public int getUnusedId(){
if(lastUsedID == 0){
@@ -155,11 +189,20 @@ public class FactionController {
lastUsedID++;
return lastUsedID;
}
public void removeFaction(int id) {
if(id < 0 || factions.size() <= 1)
return;
factions.remove(id);
saveFactions();
public IFaction delete(int id) {
if (id >= 0 && this.factions.size() > 1) {
Faction faction = (Faction)this.factions.remove(id);
saveFactions();
if (faction == null) {
return null;
} else {
this.saveFactions();
faction.id = -1;
return faction;
}
} else {
return null;
}
}
public int getFirstFactionId() {
@@ -52,7 +52,7 @@ public class FactionOptions {
addPoints(player, data, faction2Id, decreaseFaction2Points, faction2Points);
}
private void addPoints(EntityPlayer player, PlayerFactionData data, int factionId, boolean decrease, int points) {
Faction faction = FactionController.getInstance().getFaction(factionId);
Faction faction = FactionController.getInstance().get(factionId);
if(faction == null)
return;
@@ -39,7 +39,7 @@ public class PlayerFactionData {
public int getFactionPoints(int id) {
if(!factionData.containsKey(id)){
Faction faction = FactionController.getInstance().getFaction(id);
Faction faction = FactionController.getInstance().get(id);
factionData.put(id, faction == null? -1 : faction.defaultPoints);
}
return factionData.get(id);
@@ -47,7 +47,7 @@ public class PlayerFactionData {
public void increasePoints(int factionId, int points) {
if(!factionData.containsKey(factionId)){
Faction faction = FactionController.getInstance().getFaction(factionId);
Faction faction = FactionController.getInstance().get(factionId);
factionData.put(factionId, faction == null? -1 : faction.defaultPoints);
}
factionData.put(factionId, factionData.get(factionId) + points);
@@ -59,7 +59,7 @@ public class PlayerFactionData {
NBTTagList list = new NBTTagList();
for(int id : factionData.keySet()){
Faction faction = FactionController.getInstance().getFaction(id);
Faction faction = FactionController.getInstance().get(id);
if(faction == null || faction.hideFaction)
continue;
NBTTagCompound com = new NBTTagCompound();
@@ -16,8 +16,15 @@ import noppes.npcs.quests.QuestInterface;
import noppes.npcs.quests.QuestItem;
import noppes.npcs.quests.QuestKill;
import noppes.npcs.quests.QuestLocation;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.handler.data.IQuest;
import noppes.npcs.scripted.handler.data.IQuestCategory;
import noppes.npcs.scripted.handler.data.IQuestObjective;
import noppes.npcs.scripted.interfaces.IContainer;
import noppes.npcs.scripted.interfaces.IPlayer;
public class Quest implements ICompatibilty {
public class Quest implements ICompatibilty, IQuest {
public int version = VersionCompatibility.ModRev;
public int id = -1;
public EnumQuestType type = EnumQuestType.Item;
@@ -148,4 +155,91 @@ public class Quest implements ICompatibilty {
public void setVersion(int version) {
this.version = version;
}
public int getId() {
return this.id;
}
public String getName() {
return this.title;
}
public int getType() {
return this.type.ordinal();
}
public void setType(int questType) {
if(questType < 0 || questType >= EnumQuestType.values().length)
return;
EnumQuestType type = EnumQuestType.values()[questType];
setType(type);
}
public IQuestCategory getCategory() {
return this.category;
}
public void save() {
QuestController.instance.saveQuest(this.category.id, this);
}
public void setName(String name) {
this.title = name;
}
public String getLogText() {
return this.logText;
}
public void setLogText(String text) {
this.logText = text;
}
public String getCompleteText() {
return this.completeText;
}
public void setCompleteText(String text) {
this.completeText = text;
}
public void setNextQuest(IQuest quest) {
if (quest == null) {
this.nextQuestid = -1;
this.nextQuestTitle = "";
} else {
if (quest.getId() < 0) {
throw new CustomNPCsException("Quest id is lower than 0", new Object[0]);
}
this.nextQuestid = quest.getId();
this.nextQuestTitle = quest.getName();
}
}
public String getNpcName() {
return this.completerNpc;
}
public void setNpcName(String name) {
this.completerNpc = name;
}
public IQuestObjective[] getObjectives(IPlayer player) {
if (!player.hasActiveQuest(this.id)) {
throw new CustomNPCsException("Player doesnt have this quest active.", new Object[0]);
} else {
return this.questInterface.getObjectives((EntityPlayer) player.getMCEntity());
}
}
public boolean getIsRepeatable() {
return this.repeat != EnumQuestRepeat.NONE;
}
public IContainer getRewards() {
return NpcAPI.Instance().getIContainer(this.rewardItems);
}
}
@@ -1,11 +1,15 @@
package noppes.npcs.controllers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.scripted.handler.data.IQuest;
import noppes.npcs.scripted.handler.data.IQuestCategory;
public class QuestCategory {
public class QuestCategory implements IQuestCategory {
public HashMap<Integer,Quest> quests;
public int id = -1;
public String title = "";
@@ -43,4 +47,18 @@ public class QuestCategory {
return nbttagcompound;
}
public List<IQuest> quests() {
return new ArrayList(this.quests.values());
}
public String getName() {
return this.title;
}
public IQuest create() {
Quest quest = new Quest();
quest.category = this;
return quest;
}
}
@@ -2,9 +2,7 @@ package noppes.npcs.controllers;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.*;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
@@ -12,9 +10,12 @@ import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.scripted.handler.IQuestHandler;
import noppes.npcs.scripted.handler.data.IQuest;
import noppes.npcs.scripted.handler.data.IQuestCategory;
import noppes.npcs.util.NBTJsonUtil;
public class QuestController {
public class QuestController implements IQuestHandler {
public HashMap<Integer,QuestCategory> categories = new HashMap<Integer, QuestCategory>();
public HashMap<Integer,Quest> quests = new HashMap<Integer, Quest>();
@@ -232,5 +233,12 @@ public class QuestController {
private File getDir(){
return new File(CustomNpcs.getWorldSaveDirectory(), "quests");
}
public List<IQuestCategory> categories() {
return new ArrayList(this.categories.values());
}
public IQuest get(int id) {
return (IQuest)this.quests.get(id);
}
}
@@ -1,20 +1,24 @@
package noppes.npcs.controllers;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import noppes.npcs.NBTTags;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.scripted.handler.data.IRecipe;
public class RecipeCarpentry extends ShapedRecipes{
public class RecipeCarpentry extends ShapedRecipes implements IRecipe {
public int id = -1;
public String name = "";
public Availability availability = new Availability();
@@ -222,4 +226,64 @@ public class RecipeCarpentry extends ShapedRecipes{
}
return false;
}
public String getName() {
return this.name;
}
public ItemStack getResult() {
return this.getRecipeOutput();
}
public boolean isGlobal() {
return this.isGlobal;
}
public void setIsGlobal(boolean bo) {
this.isGlobal = bo;
}
public boolean getIgnoreNBT() {
return this.ignoreNBT;
}
public void setIgnoreNBT(boolean bo) {
this.ignoreNBT = bo;
}
public boolean getIgnoreDamage() {
return this.ignoreDamage;
}
public void setIgnoreDamage(boolean bo) {
this.ignoreDamage = bo;
}
public int getWidth() {
return this.recipeWidth;
}
public int getHeight() {
return this.recipeHeight;
}
public void save() {
try {
RecipeController.instance.saveRecipe(this.writeNBT());
} catch (IOException var2) {
}
}
public void delete() {
RecipeController.instance.delete(this.id);
}
public ItemStack[] getRecipe() {
return this.recipeItems;
}
public int getId() {
return this.id;
}
}
@@ -4,10 +4,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.*;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
@@ -16,8 +13,10 @@ import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.scripted.handler.IRecipeHandler;
import noppes.npcs.scripted.handler.data.IRecipe;
public class RecipeController {
public class RecipeController implements IRecipeHandler {
private static Collection<RecipeCarpentry> prevRecipes;
public HashMap<Integer,RecipeCarpentry> globalRecipes = new HashMap<Integer, RecipeCarpentry>();
public HashMap<Integer,RecipeCarpentry> anvilRecipes = new HashMap<Integer, RecipeCarpentry>();
@@ -198,7 +197,7 @@ public class RecipeController {
return false;
}
public RecipeCarpentry removeRecipe(int id) {
public RecipeCarpentry delete(int id) {
RecipeCarpentry recipe = getRecipe(id);
globalRecipes.remove(recipe.id);
anvilRecipes.remove(recipe.id);
@@ -214,4 +213,46 @@ public class RecipeController {
RecipeController.instance.globalRecipes.put(recipeAnvil.id, recipeAnvil);
}
}
public List<IRecipe> getGlobalList() {
return new ArrayList(this.globalRecipes.values());
}
public List<IRecipe> getCarpentryList() {
return new ArrayList(this.anvilRecipes.values());
}
public void addRecipe(String name, boolean global, ItemStack result, Object... objects) {
RecipeCarpentry recipe = new RecipeCarpentry(name);
recipe.isGlobal = global;
recipe = RecipeCarpentry.saveRecipe(recipe, result, objects);
try {
this.saveRecipe(recipe.writeNBT());
} catch (Exception var7) {
var7.printStackTrace();
}
}
public void addRecipe(String name, boolean global, ItemStack result, int width, int height, ItemStack... objects) {
ArrayList<ItemStack> list = new ArrayList<>();
int var9 = objects.length;
for(int var10 = 0; var10 < var9; ++var10) {
ItemStack item = objects[var10];
if (item.stackSize > 0) {
list.add(item);
}
}
RecipeCarpentry recipe = new RecipeCarpentry(width, height, list.toArray(new ItemStack[0]), result);
recipe.isGlobal = global;
recipe.name = name;
try {
this.saveRecipe(recipe.writeNBT());
} catch (IOException var12) {
var12.printStackTrace();
}
}
}
@@ -13,6 +13,7 @@ import java.util.Map;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
@@ -20,11 +21,17 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ChatComponentText;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.controllers.LinkedNpcController.LinkedData;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.handler.ICloneHandler;
import noppes.npcs.scripted.interfaces.IEntity;
import noppes.npcs.scripted.interfaces.IWorld;
import noppes.npcs.util.JsonException;
import noppes.npcs.util.NBTJsonUtil;
public class ServerCloneController {
public class ServerCloneController implements ICloneHandler {
public static ServerCloneController Instance;
public ServerCloneController(){
@@ -193,4 +200,39 @@ public class ServerCloneController {
nbttagcompound.setTag("TransformAI", adv);
}
}
public IEntity spawn(double x, double y, double z, int tab, String name, IWorld world) {
NBTTagCompound compound = this.getCloneData((ICommandSender)null, name, tab);
if (compound == null) {
throw new CustomNPCsException("Unknown clone tab:" + tab + " name:" + name, new Object[0]);
} else {
Entity entity = NoppesUtilServer.spawnClone(compound, (int)x, (int)y, (int)z, world.getMCWorld());
return entity == null ? null : NpcAPI.Instance().getIEntity(entity);
}
}
public IEntity get(int tab, String name, IWorld world) {
NBTTagCompound compound = this.getCloneData((ICommandSender)null, name, tab);
if (compound == null) {
throw new CustomNPCsException("Unknown clone tab:" + tab + " name:" + name, new Object[0]);
} else {
Instance.cleanTags(compound);
Entity entity = EntityList.createEntityFromNBT(compound, world.getMCWorld());
return entity == null ? null : NpcAPI.Instance().getIEntity(entity);
}
}
public void set(int tab, String name, IEntity entity) {
NBTTagCompound compound = new NBTTagCompound();
if (!entity.getMCEntity().isEntityAlive()) {
throw new CustomNPCsException("Cannot save dead entities", new Object[0]);
} else {
this.cleanTags(compound);
this.saveClone(tab, name, compound);
}
}
public void remove(int tab, String name) {
this.removeClone(name, tab);
}
}