mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 01:04:30 +00:00
Added handler support to NPC API.
This commit is contained in:
1 parent
69f96519dc
commit
d50f51e208
40 files changed
+1471
-56
No files matched your search
@@ -1,13 +1,16 @@
|
||||
package noppes.npcs.quests;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Vector;
|
||||
import java.util.*;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.NpcMiscInventory;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
import noppes.npcs.scripted.handler.data.IQuestObjective;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
|
||||
public class QuestItem extends QuestInterface{
|
||||
public NpcMiscInventory items = new NpcMiscInventory(3);
|
||||
@@ -119,5 +122,59 @@ public class QuestItem extends QuestInterface{
|
||||
return vec;
|
||||
}
|
||||
|
||||
public IQuestObjective[] getObjectives(EntityPlayer player) {
|
||||
List<IQuestObjective> list = new ArrayList();
|
||||
List<ItemStack> questItems = NoppesUtilPlayer.countStacks(this.items, this.ignoreDamage, this.ignoreNBT);
|
||||
Iterator var4 = questItems.iterator();
|
||||
|
||||
while(var4.hasNext()) {
|
||||
ItemStack stack = (ItemStack)var4.next();
|
||||
if (stack.stackSize > 0) {
|
||||
list.add(new noppes.npcs.quests.QuestItem.QuestItemObjective(this, player, stack));
|
||||
}
|
||||
}
|
||||
|
||||
return (IQuestObjective[])list.toArray(new IQuestObjective[list.size()]);
|
||||
}
|
||||
|
||||
class QuestItemObjective implements IQuestObjective {
|
||||
private final QuestItem parent;
|
||||
private final EntityPlayer player;
|
||||
private final ItemStack questItem;
|
||||
|
||||
public QuestItemObjective(QuestItem this$0, EntityPlayer player, ItemStack item) {
|
||||
this.parent = this$0;
|
||||
this.player = player;
|
||||
this.questItem = item;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
int count = 0;
|
||||
|
||||
for(int i = 0; i < this.player.inventory.getSizeInventory(); ++i) {
|
||||
ItemStack item = this.player.inventory.getStackInSlot(i);
|
||||
if (!NoppesUtilServer.IsItemStackNull(item) && NoppesUtilPlayer.compareItems(this.questItem, item, this.parent.ignoreDamage, this.parent.ignoreNBT)) {
|
||||
count += item.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
return ValueUtil.CorrectInt(count, 0, this.questItem.stackSize);
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
throw new CustomNPCsException("Cant set the progress of ItemQuests", new Object[0]);
|
||||
}
|
||||
|
||||
public int getMaxProgress() {
|
||||
return this.questItem.stackSize;
|
||||
}
|
||||
|
||||
public boolean isCompleted() {
|
||||
return NoppesUtilPlayer.compareItems(this.player, this.questItem, this.parent.ignoreDamage, this.parent.ignoreNBT);
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.questItem.getDisplayName() + ": " + this.getProgress() + "/" + this.getMaxProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user