From 403738262cefeb1c0d5d65391eab4a97f0bcbec3 Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 27 Feb 2022 23:08:24 -0600 Subject: [PATCH] Added timer functions. ticks(int id): Gets the remaining ticks in the timer that matches this id. setTicks(int id, int ticks): Sets the remaining ticks in the timer that matches this id. maxTicks(int id): Gets the maximum ticks that must elapse for the timer that matches this id to finish. setMaxTicks(int id, int ticks): Sets the maximum ticks that must elapse for the timer that matches this id to finish. repeats(int id): Returns true if the timer with the given id is set to repeat, false otherwise. setRepeats(int id, bool repeat): Sets whether the timer with the given id should repeat. If true, the timer will repeat, and not repeat otherwise. --- .../noppes/npcs/entity/data/DataTimers.java | 34 +++++++++++++++++++ .../npcs/scripted/interfaces/ITimers.java | 12 +++++++ 2 files changed, 46 insertions(+) diff --git a/src/main/java/noppes/npcs/entity/data/DataTimers.java b/src/main/java/noppes/npcs/entity/data/DataTimers.java index 58378e07a..76550f747 100644 --- a/src/main/java/noppes/npcs/entity/data/DataTimers.java +++ b/src/main/java/noppes/npcs/entity/data/DataTimers.java @@ -55,6 +55,40 @@ public class DataTimers implements ITimers { } } + public int ticks(int id){ + return this.timers.get(Integer.valueOf(id)).ticks; + } + + public void setTicks(int id, int ticks){ + DataTimers.Timer timer = (DataTimers.Timer)this.timers.get(Integer.valueOf(id)); + if(ticks < 0) + ticks = 0; + if(ticks > timer.timerTicks) + ticks = timer.timerTicks; + + timer.ticks = ticks; + } + + public int maxTicks(int id){ + return this.timers.get(Integer.valueOf(id)).timerTicks; + } + + public void setMaxTicks(int id, int maxTicks){ + DataTimers.Timer timer = (DataTimers.Timer)this.timers.get(Integer.valueOf(id)); + if(maxTicks < 0) + maxTicks = 0; + + timer.timerTicks = maxTicks; + } + + public boolean repeats(int id){ + return this.timers.get(Integer.valueOf(id)).repeat; + } + + public void setRepeats(int id, boolean repeat){ + this.timers.get(Integer.valueOf(id)).repeat = repeat; + } + public void writeToNBT(NBTTagCompound compound) { NBTTagList list = new NBTTagList(); Iterator var3 = this.timers.values().iterator(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ITimers.java b/src/main/java/noppes/npcs/scripted/interfaces/ITimers.java index f69b93032..df3623e97 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ITimers.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ITimers.java @@ -18,5 +18,17 @@ public interface ITimers { void clear(); + int ticks(int id); + + void setTicks(int id, int ticks); + + int maxTicks(int id); + + void setMaxTicks(int id, int maxTicks); + + boolean repeats(int id); + + void setRepeats(int id, boolean repeat); + int size(); }