Files
MagicBees/magicbees_src/magicbees/main/utils/MoonPhase.java
T

59 lines
1.3 KiB
Java
Raw Normal View History

2013-05-23 21:07:28 -07:00
package magicbees.main.utils;
2013-01-19 03:29:47 -08:00
2013-03-06 19:33:09 -08:00
import cpw.mods.fml.common.registry.LanguageRegistry;
2013-01-19 03:29:47 -08:00
import net.minecraft.world.World;
/**
* Class to abstract the moon phase from the world time a bit.
*/
public enum MoonPhase
{
2013-03-06 19:33:09 -08:00
FULL("full"),
WANING_GIBBOUS("gibbousWaning"),
WANING_HALF("halfWaning"),
WANING_CRESCENT("crescentWaning"),
NEW("new"),
WAXING_CRESCENT("crecentWaxing"),
WAXING_HALF("halfWaxing"),
WAXING_GIBBOUS("gibbousWaxing");
private String phaseName;
private MoonPhase(String name)
{
this.phaseName = name;
}
2013-01-19 03:29:47 -08:00
public boolean isBetween(MoonPhase first, MoonPhase second)
{
boolean flag = false;
if (first.ordinal() <= second.ordinal())
{
// Straightforward.
flag = first.ordinal() <= this.ordinal() && this.ordinal() <= second.ordinal();
}
else
{
// Wraps around the boundary.
flag = (first.ordinal() <= this.ordinal() && this.ordinal() <= WAXING_GIBBOUS.ordinal()) ||
(FULL.ordinal() <= this.ordinal() && this.ordinal() <= second.ordinal());
}
return flag;
}
2013-04-15 02:27:33 -07:00
public String getLocalizedName()
2013-03-06 19:33:09 -08:00
{
2013-06-04 13:26:44 -07:00
return LocalizationManager.getLocalizedString("moon." + this.phaseName);
2013-03-06 19:33:09 -08:00
}
2013-01-19 03:29:47 -08:00
public static MoonPhase getMoonPhase(World w)
{
2013-04-15 02:27:33 -07:00
return getMoonPhaseFromTime(w.getWorldTime());
}
public static MoonPhase getMoonPhaseFromTime(long time)
{
return MoonPhase.values()[(int)((time - 6000) / 24000L) % 8];
2013-01-19 03:29:47 -08:00
}
}