Files
MagicBees/magicbees_src/magicbees/main/utils/MoonPhase.java
T
MysteriousAges 406132babc Adding Wither Skull crafting, sort of.
Loc string fixes
Escritoire work

... I really need to commit more often. :x
2013-06-04 13:26:44 -07:00

60 lines
1.3 KiB
Java

package magicbees.main.utils;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.world.World;
/**
* Class to abstract the moon phase from the world time a bit.
*/
public enum MoonPhase
{
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;
}
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;
}
public String getLocalizedName()
{
return LocalizationManager.getLocalizedString("moon." + this.phaseName);
}
public static MoonPhase getMoonPhase(World w)
{
return getMoonPhaseFromTime(w.getWorldTime());
}
public static MoonPhase getMoonPhaseFromTime(long time)
{
return MoonPhase.values()[(int)((time - 6000) / 24000L) % 8];
}
}