summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-22 19:22:27 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-22 19:22:35 +0100
commit70025ec140144173754cfc15dc22c4dccdbe74fc (patch)
treec506bc5aa74f2d27fb45781cdf7669719cad99de
parent4fd73294077a84ceed6e50be7569c83d6917866d (diff)
downloadnoctis-70025ec140144173754cfc15dc22c4dccdbe74fc.tar.bz2
Add support for sky access in catalytic recipes
-rw-r--r--src/main/java/net/flarn/noctis/init/Recipes.java3
-rw-r--r--src/main/java/net/flarn/noctis/item/ItemCatalyst.java17
-rw-r--r--src/main/java/net/flarn/noctis/recipes/CatalysedRecipe.java20
-rw-r--r--src/main/java/net/flarn/noctis/utils/SkyAccess.java40
-rw-r--r--src/main/java/net/flarn/noctis/utils/TimeHelper.java3
5 files changed, 72 insertions, 11 deletions
diff --git a/src/main/java/net/flarn/noctis/init/Recipes.java b/src/main/java/net/flarn/noctis/init/Recipes.java
index 225c547..b183473 100644
--- a/src/main/java/net/flarn/noctis/init/Recipes.java
+++ b/src/main/java/net/flarn/noctis/init/Recipes.java
@@ -4,6 +4,7 @@ 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.SkyAccess;
import net.flarn.noctis.utils.TimeHelper;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@@ -29,6 +30,6 @@ 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);
+ new ItemStack[] { new ItemStack(Blocks.glass, 2, 0), new ItemStack(Items.stick) }, 10, TimeHelper.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 16fb289..8f9e247 100644
--- a/src/main/java/net/flarn/noctis/item/ItemCatalyst.java
+++ b/src/main/java/net/flarn/noctis/item/ItemCatalyst.java
@@ -22,6 +22,7 @@ import java.util.UUID;
public class ItemCatalyst extends ItemNoctisBase {
public static enum CatalystType {
+ ANY(-1),
LIGHT(0),
DARK(1),
MIXED(2);
@@ -45,6 +46,12 @@ public class ItemCatalyst extends ItemNoctisBase {
return LIGHT;
}
+ public boolean meetsNeeds(CatalystType goal) {
+ if (goal == ANY) { return true; }
+ if (goal == this) { return true; }
+ return this == MIXED;
+ }
+
}
@SideOnly(Side.CLIENT)
@@ -114,7 +121,7 @@ public class ItemCatalyst extends ItemNoctisBase {
}
ItemStack s = entityItem.getEntityItem();
TimeHelper.Times nowTime = TimeHelper.Times.fromCelestialAngle(entityItem.worldObj.getCelestialAngle(0F));
- boolean canSeeSky = entityItem.worldObj.canBlockSeeTheSky((int) entityItem.posX, (int) entityItem.posY, (int) entityItem.posZ);
+ 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)) {
@@ -123,11 +130,11 @@ public class ItemCatalyst extends ItemNoctisBase {
entityItem.age = 0;
}
/* Charge us up a little */
- if (!entityItem.worldObj.isRemote && canSeeSky) {
+ if (!entityItem.worldObj.isRemote && skyAccess == SkyAccess.SKY) {
adjustEnergy(s, 1);
}
} else {
- if (!entityItem.worldObj.isRemote && canSeeSky) {
+ if (!entityItem.worldObj.isRemote && skyAccess == SkyAccess.SKY) {
adjustEnergy(s, -20);
}
}
@@ -135,7 +142,7 @@ public class ItemCatalyst extends ItemNoctisBase {
AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(entityItem.posX - 0.5, entityItem.posY, entityItem.posZ - 0.5,
entityItem.posX + 0.5, entityItem.posY + 1.0, entityItem.posZ + 0.5);
List entities = entityItem.worldObj.getEntitiesWithinAABB(EntityItem.class, axisalignedbb);
- List recipes = CatalysedRecipe.getPossibleRecipes(entities, getCatalystType(s), nowTime, getEnergy(s));
+ List recipes = CatalysedRecipe.getPossibleRecipes(entities, getCatalystType(s), nowTime, getEnergy(s), skyAccess);
if (!recipes.isEmpty()) {
/* Something could be crafted, so craft the first thing returned */
if (!entityItem.worldObj.isRemote) {
@@ -147,7 +154,7 @@ public class ItemCatalyst extends ItemNoctisBase {
}
}
- return false;
+ return super.onEntityItemUpdate(entityItem);
}
public static int getEnergy(ItemStack s) {
diff --git a/src/main/java/net/flarn/noctis/recipes/CatalysedRecipe.java b/src/main/java/net/flarn/noctis/recipes/CatalysedRecipe.java
index 8b3bb6a..a2c4fb8 100644
--- a/src/main/java/net/flarn/noctis/recipes/CatalysedRecipe.java
+++ b/src/main/java/net/flarn/noctis/recipes/CatalysedRecipe.java
@@ -1,6 +1,8 @@
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.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
@@ -14,6 +16,7 @@ public class CatalysedRecipe {
public final ItemStack output;
public final int energy;
public final TimeHelper.Times timeNeeded;
+ public final SkyAccess skyAccess;
private static List<CatalysedRecipe> recipes = new LinkedList();
@@ -21,20 +24,23 @@ public class CatalysedRecipe {
ItemStack _output,
ItemStack[] _ingredients,
int _energy,
- TimeHelper.Times _timeNeeded) {
+ TimeHelper.Times _timeNeeded,
+ SkyAccess _skyAccess) {
catalyst = _catalyst;
ingredients = _ingredients;
output = _output;
energy = _energy;
timeNeeded = _timeNeeded;
+ skyAccess = _skyAccess;
}
public static void newRecipe(ItemCatalyst.CatalystType _catalyst,
ItemStack _output,
ItemStack[] _ingredients,
int _energy,
- TimeHelper.Times _timeNeeded) {
- recipes.add(new CatalysedRecipe(_catalyst, _output, _ingredients, _energy, _timeNeeded));
+ TimeHelper.Times _timeNeeded,
+ SkyAccess _skyAccess) {
+ recipes.add(new CatalysedRecipe(_catalyst, _output, _ingredients, _energy, _timeNeeded, _skyAccess));
}
public boolean areIngredientsPresent(List entities) {
@@ -78,12 +84,16 @@ public class CatalysedRecipe {
}
public static List<CatalysedRecipe> getPossibleRecipes(List entities, ItemCatalyst.CatalystType catalyst,
- TimeHelper.Times now, int energyavailable) {
+ TimeHelper.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) &&
- r.catalyst == catalyst &&
+ catalyst.meetsNeeds(r.catalyst) &&
+ skyAccessNow.meetsNeed(r.skyAccess) &&
r.areIngredientsPresent(entities)) {
ret.add(r);
}
diff --git a/src/main/java/net/flarn/noctis/utils/SkyAccess.java b/src/main/java/net/flarn/noctis/utils/SkyAccess.java
new file mode 100644
index 0000000..ba1f050
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/utils/SkyAccess.java
@@ -0,0 +1,40 @@
+package net.flarn.noctis.utils;
+
+import net.minecraft.world.World;
+
+public enum SkyAccess {
+ ANY(-1),
+ SKY(0),
+ NOSKY(1);
+
+ private int accessType;
+
+ private SkyAccess(int _accessType) {
+ accessType = _accessType;
+ }
+
+ public int getAccessType() { return accessType; }
+ public static SkyAccess fromInt(int accessType) {
+ switch (accessType) {
+ case 0:
+ return SKY;
+ case 1:
+ return NOSKY;
+ }
+ return SKY;
+ }
+
+ public boolean meetsNeed(SkyAccess goal) {
+ if (goal == ANY) {
+ return true;
+ }
+ return goal == this;
+ }
+
+ public static SkyAccess fromWorldLocation(World world, int x, int y, int z) {
+ if (world.canBlockSeeTheSky(x, y, z)) {
+ return SKY;
+ }
+ return NOSKY;
+ }
+}
diff --git a/src/main/java/net/flarn/noctis/utils/TimeHelper.java b/src/main/java/net/flarn/noctis/utils/TimeHelper.java
index b688f46..356fefb 100644
--- a/src/main/java/net/flarn/noctis/utils/TimeHelper.java
+++ b/src/main/java/net/flarn/noctis/utils/TimeHelper.java
@@ -3,6 +3,7 @@ package net.flarn.noctis.utils;
public class TimeHelper {
public static enum Times {
+ ANY(-1),
DAY(0),
NIGHT(1),
DUSKISH(2),
@@ -12,6 +13,7 @@ public class TimeHelper {
DAWNISH(6),
DAWN(7);
+
private int timeOfDay;
private Times(int t) {
timeOfDay = t;
@@ -70,6 +72,7 @@ public class TimeHelper {
}
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; }