summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-20 22:12:57 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-20 22:12:57 +0100
commita054e659fc612aa721c7ca060a35e4ea33a3b42f (patch)
tree8a0ef67fefb70f1aaaafb6f024fac7349f472db0
parentb12bbd5abd3af86b5247084b159cb241e7fb9835 (diff)
downloadnoctis-a054e659fc612aa721c7ca060a35e4ea33a3b42f.tar.bz2
Add a bunch of stuff, charging now works \o/
-rw-r--r--src/main/java/net/flarn/noctis/item/ItemCatalyst.java33
-rw-r--r--src/main/java/net/flarn/noctis/refs/Numbers.java9
-rw-r--r--src/main/java/net/flarn/noctis/utils/MathsUtil.java9
-rw-r--r--src/main/java/net/flarn/noctis/utils/TimeHelper.java82
4 files changed, 123 insertions, 10 deletions
diff --git a/src/main/java/net/flarn/noctis/item/ItemCatalyst.java b/src/main/java/net/flarn/noctis/item/ItemCatalyst.java
index bb60094..f8e27c0 100644
--- a/src/main/java/net/flarn/noctis/item/ItemCatalyst.java
+++ b/src/main/java/net/flarn/noctis/item/ItemCatalyst.java
@@ -2,13 +2,8 @@ package net.flarn.noctis.item;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
-import net.flarn.noctis.refs.Names;
-import net.flarn.noctis.refs.Strings;
-import net.flarn.noctis.refs.Tags;
-import net.flarn.noctis.refs.Textures;
-import net.flarn.noctis.utils.LogHelper;
-import net.flarn.noctis.utils.NBTHelper;
-import net.flarn.noctis.utils.PlayerHelper;
+import net.flarn.noctis.refs.*;
+import net.flarn.noctis.utils.*;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityItem;
@@ -55,9 +50,8 @@ public class ItemCatalyst extends ItemNoctisBase {
public ItemCatalyst() {
super();
- this.setHasSubtypes(true);
+ this.setMaxDamage(Numbers.MAX_CATALYST_POWER);
this.setUnlocalizedName(Names.Items.CATALYST);
-
}
@Override
@@ -76,6 +70,7 @@ public class ItemCatalyst extends ItemNoctisBase {
for (int meta = 0; meta < Names.Items.CATALYSTS.length; ++meta) {
ItemStack s = new ItemStack(this, 1, 0);
NBTHelper.setInt(s, Tags.General.TYPE, meta);
+ s.setItemDamage(Numbers.MAX_CATALYST_POWER);
list.add(s);
}
}
@@ -111,7 +106,25 @@ public class ItemCatalyst extends ItemNoctisBase {
if (!NBTHelper.hasEntry(entityItem.getEntityItem(), Tags.General.OWNER)) {
return false;
}
- LogHelper.warn("Ruhroh, we're on the ground!");
+ ItemStack s = entityItem.getEntityItem();
+ TimeHelper.Times nowTime = TimeHelper.Times.fromCelestialAngle(entityItem.worldObj.getCelestialAngle(0F));
+ LogHelper.warn("It is currently: " + nowTime);
+
+ if (nowTime.meetsNeed(TimeHelper.Times.NIGHT)) {
+ /* Reduce our age if it's getting high */
+ if (entityItem.age == Numbers.CATALYST_AGE_RESET) {
+ entityItem.age = 0;
+ }
+ /* Charge us up a little */
+ if (!entityItem.worldObj.isRemote) {
+ s.setItemDamage(MathsUtil.clampInt(0, Numbers.MAX_CATALYST_POWER, s.getItemDamage() - 1));
+ }
+ } else {
+ if (!entityItem.worldObj.isRemote) {
+ s.setItemDamage(MathsUtil.clampInt(0, Numbers.MAX_CATALYST_POWER, s.getItemDamage() + 20));
+ }
+ }
+ LogHelper.warn("Stack is " + s);
return false;
}
diff --git a/src/main/java/net/flarn/noctis/refs/Numbers.java b/src/main/java/net/flarn/noctis/refs/Numbers.java
new file mode 100644
index 0000000..690bed5
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/refs/Numbers.java
@@ -0,0 +1,9 @@
+package net.flarn.noctis.refs;
+
+public class Numbers {
+ public static final int TICKS_PER_DAY = 24000;
+ public static final int TICKS_PER_NIGHT = TICKS_PER_DAY / 2;
+ public static final int MAX_CATALYST_POWER = (TICKS_PER_NIGHT * 7) / 20;
+ public static final int CATALYST_AGE_RESET = 1000;
+
+}
diff --git a/src/main/java/net/flarn/noctis/utils/MathsUtil.java b/src/main/java/net/flarn/noctis/utils/MathsUtil.java
new file mode 100644
index 0000000..23992f9
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/utils/MathsUtil.java
@@ -0,0 +1,9 @@
+package net.flarn.noctis.utils;
+
+
+public class MathsUtil {
+
+ public static int clampInt(int min, int max, int value) {
+ return Math.min(Math.max(min, value), max);
+ }
+}
diff --git a/src/main/java/net/flarn/noctis/utils/TimeHelper.java b/src/main/java/net/flarn/noctis/utils/TimeHelper.java
new file mode 100644
index 0000000..b688f46
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/utils/TimeHelper.java
@@ -0,0 +1,82 @@
+package net.flarn.noctis.utils;
+
+public class TimeHelper {
+
+ public static enum Times {
+ DAY(0),
+ NIGHT(1),
+ DUSKISH(2),
+ DUSK(3),
+ MIDNIGHTISH(4),
+ MIDNIGHT(5),
+ DAWNISH(6),
+ DAWN(7);
+
+ private int timeOfDay;
+ private Times(int t) {
+ timeOfDay = t;
+ }
+
+ public int asInt() { return timeOfDay; }
+ public static Times fromInt(int t) {
+ switch(t) {
+ case 0:
+ return DAY;
+ case 1:
+ return NIGHT;
+ case 2:
+ return DUSKISH;
+ case 3:
+ return DUSK;
+ case 4:
+ return MIDNIGHTISH;
+ case 5:
+ return MIDNIGHT;
+ case 6:
+ return DAWNISH;
+ case 7:
+ return DAWN;
+ }
+ return DAY;
+ }
+
+ private static boolean between(float a1, float a2, float a) {
+ return (a >= a1 && a <= a2);
+ }
+
+ public static Times fromCelestialAngle(float angle) {
+ if (angle < 0.25F || angle > 0.75F) {
+ return DAY;
+ }
+ if (between(0.25F, 0.3F, angle)) {
+ return DUSK;
+ }
+ if (between(0.3F, 0.325F, angle)) {
+ return DUSKISH;
+ }
+ if (between(0.475F, 0.525F, angle)) {
+ return MIDNIGHT;
+ }
+ if (between(0.45F, 0.55F, angle)) {
+ return MIDNIGHTISH;
+ }
+ if (between(0.7F, 0.75F, angle)) {
+ return DAWN;
+ }
+ if (between(0.675F, 0.7F, angle)) {
+ return DAWNISH;
+ }
+ return NIGHT;
+ }
+
+ public boolean meetsNeed(Times goal) {
+ if (goal == DAY && this == DAY) { return true; }
+ if (this == DAY) { return false; }
+ if (goal == NIGHT) { return true; }
+ if (goal == DUSKISH && (this == DUSK || this == DUSKISH)) { return true; }
+ if (goal == DAWNISH && (this == DAWN || this == DAWNISH)) { return true; }
+ if (goal == MIDNIGHTISH && (this == MIDNIGHT || this == MIDNIGHTISH)) { return true; }
+ return goal == this;
+ }
+ }
+}