mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 17:44:46 +00:00
Scripted player tick events are functional, GUI for player events is complete. Global player events run as they should now, just need to start implementing more of them.
This commit is contained in:
1 parent
6aa98aecf3
commit
1ee14920ff
26 files changed
+1223
-1091
No files matched your search
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package noppes.npcs.entity.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.scripted.ITimers;
|
||||
import noppes.npcs.controllers.PlayerData;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
|
||||
public class DataTimers implements ITimers {
|
||||
private Object parent;
|
||||
private Map<Integer, DataTimers.Timer> timers = new HashMap();
|
||||
|
||||
public DataTimers(Object parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void start(int id, int ticks, boolean repeat) {
|
||||
if(this.timers.containsKey(Integer.valueOf(id))) {
|
||||
throw new CustomNPCsException("There is already a timer with id: " + id, new Object[0]);
|
||||
} else {
|
||||
this.timers.put(Integer.valueOf(id), new DataTimers.Timer(id, ticks, repeat));
|
||||
}
|
||||
}
|
||||
|
||||
public void forceStart(int id, int ticks, boolean repeat) {
|
||||
this.timers.put(Integer.valueOf(id), new DataTimers.Timer(id, ticks, repeat));
|
||||
}
|
||||
|
||||
public boolean has(int id) {
|
||||
return this.timers.containsKey(Integer.valueOf(id));
|
||||
}
|
||||
|
||||
public boolean stop(int id) {
|
||||
return this.timers.remove(Integer.valueOf(id)) != null;
|
||||
}
|
||||
|
||||
public void reset(int id) {
|
||||
DataTimers.Timer timer = (DataTimers.Timer)this.timers.get(Integer.valueOf(id));
|
||||
if(timer == null) {
|
||||
throw new CustomNPCsException("There is no timer with id: " + id, new Object[0]);
|
||||
} else {
|
||||
timer.ticks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
Iterator var3 = this.timers.values().iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
DataTimers.Timer timer = (DataTimers.Timer)var3.next();
|
||||
NBTTagCompound c = new NBTTagCompound();
|
||||
c.setInteger("ID", timer.id);
|
||||
c.setInteger("TimerTicks", timer.id);
|
||||
c.setBoolean("Repeat", timer.repeat);
|
||||
c.setInteger("Ticks", timer.ticks);
|
||||
list.appendTag(c);
|
||||
}
|
||||
|
||||
compound.setTag("NpcsTimers", list);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
HashMap timers = new HashMap();
|
||||
NBTTagList list = compound.getTagList("NpcsTimers", 10);
|
||||
|
||||
for(int i = 0; i < list.tagCount(); ++i) {
|
||||
NBTTagCompound c = list.getCompoundTagAt(i);
|
||||
DataTimers.Timer t = new DataTimers.Timer(c.getInteger("ID"), c.getInteger("TimerTicks"), c.getBoolean("Repeat"));
|
||||
t.ticks = c.getInteger("Ticks");
|
||||
timers.put(Integer.valueOf(t.id), t);
|
||||
}
|
||||
|
||||
this.timers = timers;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
Iterator var1 = (new ArrayList(this.timers.values())).iterator();
|
||||
|
||||
while(var1.hasNext()) {
|
||||
DataTimers.Timer timer = (DataTimers.Timer)var1.next();
|
||||
timer.update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.timers = new HashMap();
|
||||
}
|
||||
|
||||
class Timer {
|
||||
public int id;
|
||||
private boolean repeat;
|
||||
private int timerTicks;
|
||||
private int ticks = 0;
|
||||
|
||||
public Timer(int id, int ticks, boolean repeat) {
|
||||
this.id = id;
|
||||
this.repeat = repeat;
|
||||
this.timerTicks = ticks;
|
||||
this.ticks = ticks;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if(this.ticks-- <= 0) {
|
||||
if(this.repeat) {
|
||||
this.ticks = this.timerTicks;
|
||||
} else {
|
||||
DataTimers.this.stop(this.id);
|
||||
}
|
||||
|
||||
Object ob = DataTimers.this.parent;
|
||||
if(ob instanceof PlayerData) {
|
||||
EventHooks.onPlayerTimer((PlayerData)ob, this.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user