A few fixes, please update!
This commit is contained in:
parent
f7f9da8ae9
commit
9ed16f3006
3 changed files with 190 additions and 0 deletions
|
@ -12,6 +12,7 @@ import mekanism.api.EnumColor;
|
|||
import mekanism.api.IClientTicker;
|
||||
import mekanism.client.sound.GasMaskSound;
|
||||
import mekanism.client.sound.JetpackSound;
|
||||
import mekanism.common.HolidayManager;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.ObfuscatedNames;
|
||||
import mekanism.common.PacketHandler;
|
||||
|
@ -55,6 +56,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
public class ClientTickHandler implements ITickHandler
|
||||
{
|
||||
public boolean hasNotified = false;
|
||||
public boolean initHoliday = false;
|
||||
|
||||
public boolean preloadedSounds = false;
|
||||
|
||||
|
@ -112,6 +114,12 @@ public class ClientTickHandler implements ITickHandler
|
|||
|
||||
if(mc.theWorld != null)
|
||||
{
|
||||
if((!initHoliday || MekanismClient.ticksPassed % 1200 == 0) && mc.thePlayer != null)
|
||||
{
|
||||
HolidayManager.check();
|
||||
initHoliday = true;
|
||||
}
|
||||
|
||||
for(EntityPlayer entityPlayer : (List<EntityPlayer>)mc.theWorld.playerEntities)
|
||||
{
|
||||
if(entityPlayer instanceof AbstractClientPlayer)
|
||||
|
|
179
common/mekanism/common/HolidayManager.java
Normal file
179
common/mekanism/common/HolidayManager.java
Normal file
|
@ -0,0 +1,179 @@
|
|||
package mekanism.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
public final class HolidayManager
|
||||
{
|
||||
private static Calendar calendar = Calendar.getInstance();
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
public static List<Holiday> holidays = new ArrayList<Holiday>();
|
||||
private static List<Holiday> holidaysNotified = new ArrayList<Holiday>();
|
||||
|
||||
public static void init()
|
||||
{
|
||||
holidays.add(new Christmas());
|
||||
holidays.add(new NewYear());
|
||||
|
||||
System.out.println("[Mekanism] Initialized HolidayManager.");
|
||||
}
|
||||
|
||||
public static void check()
|
||||
{
|
||||
try {
|
||||
YearlyDate date = getDate();
|
||||
|
||||
for(Holiday holiday : holidays)
|
||||
{
|
||||
if(!holidaysNotified.contains(holiday))
|
||||
{
|
||||
if(holiday.getDate().equals(date))
|
||||
{
|
||||
holiday.onEvent(mc.thePlayer);
|
||||
holidaysNotified.add(holiday);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
private static YearlyDate getDate()
|
||||
{
|
||||
return new YearlyDate(calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH));
|
||||
}
|
||||
|
||||
public static abstract class Holiday
|
||||
{
|
||||
public abstract YearlyDate getDate();
|
||||
|
||||
public abstract void onEvent(EntityPlayer player);
|
||||
}
|
||||
|
||||
private static class Christmas extends Holiday
|
||||
{
|
||||
@Override
|
||||
public YearlyDate getDate()
|
||||
{
|
||||
return new YearlyDate(12, 25);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(EntityPlayer player)
|
||||
{
|
||||
String themedLines = getThemedLines(new EnumColor[] {EnumColor.DARK_GREEN, EnumColor.DARK_RED}, 13);
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(themedLines + EnumColor.DARK_BLUE + "[Mekanism]" + themedLines));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.RED + "Merry Christmas, " + EnumColor.DARK_BLUE + player.username + EnumColor.RED + "!"));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.RED + "May you have plenty of Christmas cheer"));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.RED + "and have a relaxing holiday with your"));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.RED + "family :)"));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.DARK_GREY + "-aidancbrady"));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(themedLines + EnumColor.DARK_BLUE + "[=======]" + themedLines));
|
||||
}
|
||||
}
|
||||
|
||||
private static class NewYear extends Holiday
|
||||
{
|
||||
@Override
|
||||
public YearlyDate getDate()
|
||||
{
|
||||
return new YearlyDate(1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(EntityPlayer player)
|
||||
{
|
||||
String themedLines = getThemedLines(new EnumColor[] {EnumColor.WHITE, EnumColor.YELLOW}, 13);
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(themedLines + EnumColor.DARK_BLUE + "[Mekanism]" + themedLines));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.AQUA + "Happy New Year, " + EnumColor.DARK_BLUE + player.username + EnumColor.RED + "!"));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.AQUA + "Best wishes to you as we enter this"));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.AQUA + "new and exciting year of 2014! :)"));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.DARK_GREY + "-aidancbrady"));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(themedLines + EnumColor.DARK_BLUE + "[=======]" + themedLines));
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Month
|
||||
{
|
||||
JANUARY("January"),
|
||||
FEBRUARY("February"),
|
||||
MARCH("March"),
|
||||
APRIL("April"),
|
||||
MAY("May"),
|
||||
JUNE("June"),
|
||||
JULY("July"),
|
||||
AUGUST("August"),
|
||||
SEPTEMBER("September"),
|
||||
OCTOBER("October"),
|
||||
NOVEMBER("November"),
|
||||
DECEMBER("December");
|
||||
|
||||
private final String name;
|
||||
|
||||
private Month(String n)
|
||||
{
|
||||
name = n;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public int month()
|
||||
{
|
||||
return ordinal()+1;
|
||||
}
|
||||
}
|
||||
|
||||
public static class YearlyDate
|
||||
{
|
||||
public Month month;
|
||||
|
||||
public int day;
|
||||
|
||||
public YearlyDate(Month m, int d)
|
||||
{
|
||||
month = m;
|
||||
day = d;
|
||||
}
|
||||
|
||||
public YearlyDate(int m, int d)
|
||||
{
|
||||
this(Month.values()[m-1], d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof YearlyDate && ((YearlyDate)obj).month == month && ((YearlyDate)obj).day == day;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int code = 1;
|
||||
code = 31 * code + month.ordinal();
|
||||
code = 31 * code + day;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getThemedLines(EnumColor[] colors, int amount)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
{
|
||||
builder.append(colors[i%colors.length] + "-");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
|
@ -1174,6 +1174,9 @@ public class Mekanism
|
|||
//Get data from server.
|
||||
new ThreadGetData();
|
||||
|
||||
//Initiate the HolidayManager for seasonal greetings.
|
||||
HolidayManager.init();
|
||||
|
||||
//Register to receive subscribed events
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
|
|
Loading…
Reference in a new issue