summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-22 19:39:59 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-22 19:39:59 +0100
commitaf76e6f1cdc1ca4663d0ac58f069aec2a7b56f94 (patch)
tree122f8fc6180cd3cf4687f67b3f0ea46133d94411
parent70025ec140144173754cfc15dc22c4dccdbe74fc (diff)
downloadnoctis-af76e6f1cdc1ca4663d0ac58f069aec2a7b56f94.tar.bz2
Various refactoring
-rw-r--r--src/main/java/net/flarn/noctis/init/Recipes.java9
-rw-r--r--src/main/java/net/flarn/noctis/item/ItemCatalyst.java39
-rw-r--r--src/main/java/net/flarn/noctis/recipes/CatalysedRecipe.java23
-rw-r--r--src/main/java/net/flarn/noctis/utils/CatalystType.java39
-rw-r--r--src/main/java/net/flarn/noctis/utils/TimeHelper.java80
-rw-r--r--src/main/java/net/flarn/noctis/utils/Times.java85
6 files changed, 140 insertions, 135 deletions
diff --git a/src/main/java/net/flarn/noctis/init/Recipes.java b/src/main/java/net/flarn/noctis/init/Recipes.java
index b183473..630cd11 100644
--- a/src/main/java/net/flarn/noctis/init/Recipes.java
+++ b/src/main/java/net/flarn/noctis/init/Recipes.java
@@ -2,13 +2,12 @@ package net.flarn.noctis.init;
import cpw.mods.fml.common.registry.GameRegistry;
import net.flarn.noctis.handler.ConfigHandler;
-import net.flarn.noctis.item.ItemCatalyst;
import net.flarn.noctis.recipes.CatalysedRecipe;
+import net.flarn.noctis.utils.CatalystType;
import net.flarn.noctis.utils.SkyAccess;
-import net.flarn.noctis.utils.TimeHelper;
+import net.flarn.noctis.utils.Times;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.oredict.ShapedOreRecipe;
@@ -29,7 +28,7 @@ public class Recipes {
}
public static void initCatalysedRecipes() {
- CatalysedRecipe.newRecipe(ItemCatalyst.CatalystType.LIGHT, new ItemStack(ModItems.glassSword),
- new ItemStack[] { new ItemStack(Blocks.glass, 2, 0), new ItemStack(Items.stick) }, 10, TimeHelper.Times.NIGHT, SkyAccess.SKY);
+ CatalysedRecipe.newRecipe(CatalystType.LIGHT, new ItemStack(ModItems.glassSword),
+ new ItemStack[] { new ItemStack(Blocks.glass, 2, 0), new ItemStack(Items.stick) }, 10, Times.NIGHT, SkyAccess.SKY);
}
}
diff --git a/src/main/java/net/flarn/noctis/item/ItemCatalyst.java b/src/main/java/net/flarn/noctis/item/ItemCatalyst.java
index 8f9e247..368dd59 100644
--- a/src/main/java/net/flarn/noctis/item/ItemCatalyst.java
+++ b/src/main/java/net/flarn/noctis/item/ItemCatalyst.java
@@ -21,39 +21,6 @@ import java.util.UUID;
public class ItemCatalyst extends ItemNoctisBase {
- public static enum CatalystType {
- ANY(-1),
- LIGHT(0),
- DARK(1),
- MIXED(2);
-
- private final int typeIndex;
- private CatalystType(int idx) {
- this.typeIndex = idx;
- }
-
- public int getIndex() { return this.typeIndex; }
-
- public static CatalystType fromIndex(int idx) {
- switch (idx) {
- case 0:
- return LIGHT;
- case 1:
- return DARK;
- case 2:
- return MIXED;
- }
- return LIGHT;
- }
-
- public boolean meetsNeeds(CatalystType goal) {
- if (goal == ANY) { return true; }
- if (goal == this) { return true; }
- return this == MIXED;
- }
-
- }
-
@SideOnly(Side.CLIENT)
private IIcon[] icons;
@@ -120,11 +87,11 @@ public class ItemCatalyst extends ItemNoctisBase {
return false;
}
ItemStack s = entityItem.getEntityItem();
- TimeHelper.Times nowTime = TimeHelper.Times.fromCelestialAngle(entityItem.worldObj.getCelestialAngle(0F));
- SkyAccess skyAccess = SkyAccess.fromWorldLocation(entityItem.worldObj,(int) entityItem.posX, (int) entityItem.posY + 1, (int) entityItem.posZ);
+ Times nowTime = Times.fromCelestialAngle(entityItem.worldObj.getCelestialAngle(0F));
+ SkyAccess skyAccess = SkyAccess.fromWorldLocation(entityItem.worldObj, (int) entityItem.posX, (int) entityItem.posY + 1, (int) entityItem.posZ);
LogHelper.warn("It is currently: " + nowTime);
- if (nowTime.meetsNeed(TimeHelper.Times.NIGHT)) {
+ if (nowTime.meetsNeed(Times.NIGHT)) {
/* Reduce our age if it's getting high */
if (entityItem.age >= Numbers.CATALYST_AGE_RESET) {
entityItem.age = 0;
diff --git a/src/main/java/net/flarn/noctis/recipes/CatalysedRecipe.java b/src/main/java/net/flarn/noctis/recipes/CatalysedRecipe.java
index a2c4fb8..a80de5b 100644
--- a/src/main/java/net/flarn/noctis/recipes/CatalysedRecipe.java
+++ b/src/main/java/net/flarn/noctis/recipes/CatalysedRecipe.java
@@ -1,9 +1,6 @@
package net.flarn.noctis.recipes;
-import net.flarn.noctis.item.ItemCatalyst;
-import net.flarn.noctis.utils.LogHelper;
-import net.flarn.noctis.utils.SkyAccess;
-import net.flarn.noctis.utils.TimeHelper;
+import net.flarn.noctis.utils.*;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
@@ -11,20 +8,20 @@ import java.util.LinkedList;
import java.util.List;
public class CatalysedRecipe {
- public final ItemCatalyst.CatalystType catalyst;
+ public final CatalystType catalyst;
public final ItemStack ingredients[];
public final ItemStack output;
public final int energy;
- public final TimeHelper.Times timeNeeded;
+ public final Times timeNeeded;
public final SkyAccess skyAccess;
private static List<CatalysedRecipe> recipes = new LinkedList();
- private CatalysedRecipe(ItemCatalyst.CatalystType _catalyst,
+ private CatalysedRecipe(CatalystType _catalyst,
ItemStack _output,
ItemStack[] _ingredients,
int _energy,
- TimeHelper.Times _timeNeeded,
+ Times _timeNeeded,
SkyAccess _skyAccess) {
catalyst = _catalyst;
ingredients = _ingredients;
@@ -34,11 +31,11 @@ public class CatalysedRecipe {
skyAccess = _skyAccess;
}
- public static void newRecipe(ItemCatalyst.CatalystType _catalyst,
+ public static void newRecipe(CatalystType _catalyst,
ItemStack _output,
ItemStack[] _ingredients,
int _energy,
- TimeHelper.Times _timeNeeded,
+ Times _timeNeeded,
SkyAccess _skyAccess) {
recipes.add(new CatalysedRecipe(_catalyst, _output, _ingredients, _energy, _timeNeeded, _skyAccess));
}
@@ -83,13 +80,11 @@ public class CatalysedRecipe {
return checkForIngredientsAndConsume(entities, true);
}
- public static List<CatalysedRecipe> getPossibleRecipes(List entities, ItemCatalyst.CatalystType catalyst,
- TimeHelper.Times now, int energyavailable,
+ public static List<CatalysedRecipe> getPossibleRecipes(List entities, CatalystType catalyst,
+ Times now, int energyavailable,
SkyAccess skyAccessNow) {
List<CatalysedRecipe> ret = new LinkedList();
- LogHelper.warn("Scanning for recipes meeting " + skyAccessNow + " and " + now);
for (CatalysedRecipe r : recipes) {
- LogHelper.warn("Considering " + r);
if (r.energy <= energyavailable &&
now.meetsNeed(r.timeNeeded) &&
catalyst.meetsNeeds(r.catalyst) &&
diff --git a/src/main/java/net/flarn/noctis/utils/CatalystType.java b/src/main/java/net/flarn/noctis/utils/CatalystType.java
new file mode 100644
index 0000000..efac7ed
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/utils/CatalystType.java
@@ -0,0 +1,39 @@
+package net.flarn.noctis.utils;
+
+import net.flarn.noctis.item.ItemCatalyst;
+
+/**
+* Created by dsilvers on 22/10/14.
+*/
+public enum CatalystType {
+ ANY(-1),
+ LIGHT(0),
+ DARK(1),
+ MIXED(2);
+
+ private final int typeIndex;
+ CatalystType(int idx) {
+ this.typeIndex = idx;
+ }
+
+ public int getIndex() { return this.typeIndex; }
+
+ public static CatalystType fromIndex(int idx) {
+ switch (idx) {
+ case 0:
+ return LIGHT;
+ case 1:
+ return DARK;
+ case 2:
+ return MIXED;
+ }
+ return LIGHT;
+ }
+
+ public boolean meetsNeeds(CatalystType goal) {
+ if (goal == ANY) { return true; }
+ if (goal == this) { return true; }
+ return this == MIXED;
+ }
+
+}
diff --git a/src/main/java/net/flarn/noctis/utils/TimeHelper.java b/src/main/java/net/flarn/noctis/utils/TimeHelper.java
index 356fefb..ab08186 100644
--- a/src/main/java/net/flarn/noctis/utils/TimeHelper.java
+++ b/src/main/java/net/flarn/noctis/utils/TimeHelper.java
@@ -2,84 +2,4 @@ package net.flarn.noctis.utils;
public class TimeHelper {
- public static enum Times {
- ANY(-1),
- 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 == ANY) { return true; }
- 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;
- }
- }
}
diff --git a/src/main/java/net/flarn/noctis/utils/Times.java b/src/main/java/net/flarn/noctis/utils/Times.java
new file mode 100644
index 0000000..91ba29f
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/utils/Times.java
@@ -0,0 +1,85 @@
+package net.flarn.noctis.utils;
+
+/**
+* Created by dsilvers on 22/10/14.
+*/
+public enum Times {
+ ANY(-1),
+ DAY(0),
+ NIGHT(1),
+ DUSKISH(2),
+ DUSK(3),
+ MIDNIGHTISH(4),
+ MIDNIGHT(5),
+ DAWNISH(6),
+ DAWN(7);
+
+
+ private int timeOfDay;
+ 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 == ANY) { return true; }
+ 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;
+ }
+}