summaryrefslogtreecommitdiff
path: root/src/main/java/fyresmodjam/handlers/ClientTickHandler.java
blob: c3950f7749a864ed8092629cdabaf5a61b211eb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package fyresmodjam.handlers;

import java.io.File;

import fyresmodjam.ModjamMod;
import fyresmodjam.misc.ItemStatHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;

public class ClientTickHandler {

	public static long time = System.currentTimeMillis();

	@SubscribeEvent
	public void clientTick(ClientTickEvent event) {
		EntityPlayer player = Minecraft.getMinecraft().player;

		if (System.currentTimeMillis() - time > 200
				&& player != null) {
			if (player.openContainer != null) {
				boolean sendPacket = false;

				for (Object object : player.inventory.mainInventory) {
					if (object == null
							|| !(object instanceof ItemStack)) {
						continue;
					}

					ItemStack stack = (ItemStack) object;

					if (stack.getItem() != null
							&& !ItemStatHelper.skip
									.contains(stack.getItem()
											.getClass())
							&& (stack.getTagCompound() == null
									|| !stack.getTagCompound()
											.hasKey("processed")
									|| stack.getTagCompound()
											.getString("processed")
											.equals("false"))) {
						sendPacket = true;
					}
				}

				if (sendPacket) {
					NewPacketHandler.UPDATE_PLAYER_ITEMS
							.sendToServer((Object) null);
					time = System.currentTimeMillis();
				}
			}

			// TODO move to an advancement
			//player.triggerAchievement(ModjamMod.startTheGame);
		}

		if (FyresKeyHandler.examine
				.getKeyCode() != ModjamMod.examineKey
				|| FyresKeyHandler.activateBlessing
						.getKeyCode() != ModjamMod.blessingKey) {
			ModjamMod.examineKey = FyresKeyHandler.examine
					.getKeyCode();
			ModjamMod.blessingKey = FyresKeyHandler.activateBlessing
					.getKeyCode();

			Configuration config = new Configuration(
					new File(ModjamMod.configPath));
			config.load();
			config.get("Keybindings", "examine_key",
					ModjamMod.examineKey)
					.set(ModjamMod.examineKey);
			config.get("Keybindings", "blessing_key",
					ModjamMod.blessingKey)
					.set(ModjamMod.blessingKey);
			config.save();
		}
	}

}