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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
package fyresmodjam.handlers;
import org.lwjgl.input.Keyboard;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
import fyresmodjam.ModjamMod;
import fyresmodjam.blessings.Blessing;
import fyresmodjam.blessings.BlessingUtils;
import fyresmodjam.blocks.BlockTrap;
import fyresmodjam.items.ItemTrap;
import fyresmodjam.tileentities.TileEntityPillar;
import fyresmodjam.tileentities.TileEntityTrap;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
public class FyresKeyHandler {
public static KeyBinding examine = new KeyBinding("Examine", Keyboard.KEY_X, "YWD");
public static KeyBinding activateBlessing = new KeyBinding("Activate Blessing", Keyboard.KEY_K, "YWD");
public static KeyBinding[] keyBindings = new KeyBinding[] { examine, activateBlessing };
public FyresKeyHandler() {
for (KeyBinding k : keyBindings) {
ClientRegistry.registerKeyBinding(k);
}
}
@SubscribeEvent
public void keyInput(KeyInputEvent event) {
if (Minecraft.getMinecraft().inGameHasFocus) {
Minecraft minecraft = Minecraft.getMinecraft();
EntityPlayer player = minecraft.thePlayer;
if (player != null) {
if (examine.isPressed()) {
doExamine(minecraft, player);
}
if (activateBlessing.isPressed()) {
doActivateBlessing(minecraft, player);
}
}
}
}
private void doActivateBlessing(Minecraft minecraft, EntityPlayer player) {
String blessing = player.getEntityData().getString("Blessing");
if (blessing != null) {
FMLLog.info("Triggering blessing");
if (minecraft.objectMouseOver != null) {
MovingObjectPosition o = minecraft.objectMouseOver;
if (o.typeOfHit == MovingObjectType.BLOCK) {
NewPacketHandler.ACTIVATE_BLESSING.sendToServer(minecraft.objectMouseOver.blockX,
minecraft.objectMouseOver.blockY, minecraft.objectMouseOver.blockZ);
}
} else {
NewPacketHandler.ACTIVATE_BLESSING.sendToServer(player.chunkCoordX, player.chunkCoordY,
player.chunkCoordZ);
}
}
}
private void doExamine(Minecraft minecraft, EntityPlayer player) {
if (minecraft.objectMouseOver != null) {
MovingObjectPosition o = minecraft.objectMouseOver;
if (o.typeOfHit == MovingObjectType.BLOCK) {
int x = minecraft.objectMouseOver.blockX;
int y = minecraft.objectMouseOver.blockY;
int z = minecraft.objectMouseOver.blockZ;
if (minecraft.theWorld.getBlock(x, y, z) == ModjamMod.blockPillar
&& (minecraft.theWorld.getBlockMetadata(x, y, z) % 2) == 1) {
y--;
}
TileEntity te = minecraft.theWorld.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityPillar) {
Blessing bless = BlessingUtils.getBlessingInstance(((TileEntityPillar) te).blessing);
String s = "@\u00A7e " + bless.customName() + "\n" + bless.description() + ".";
for (String s2 : s.split("@")) {
NewPacketHandler.SEND_MESSAGE.data = new Object[] { s2 };
NewPacketHandler.SEND_MESSAGE.executeClient(Minecraft.getMinecraft().thePlayer);
}
} else if (te != null && te instanceof TileEntityTrap) {
String placedBy = ((TileEntityTrap) te).placedBy;
String s = (placedBy != null
? "\u00A7eThis " + ItemTrap.names[te.getBlockMetadata() % BlockTrap.trapTypes].toLowerCase()
+ " was placed by "
+ (placedBy.equals(player.getCommandSenderName()) ? "you" : placedBy) + "."
: "\u00A7eThis " + ItemTrap.names[te.getBlockMetadata() % BlockTrap.trapTypes].toLowerCase()
+ " doesn't seem to have been placed by anyone.");
s += " \u00A7eTrap is set to " + TileEntityTrap.settings[((TileEntityTrap) te).setting] + ".";
NewPacketHandler.SEND_MESSAGE.data = new Object[] { s };
NewPacketHandler.SEND_MESSAGE.executeClient(Minecraft.getMinecraft().thePlayer);
} else {
String name = minecraft.theWorld.getBlock(x, y, z).getLocalizedName().toLowerCase();
NewPacketHandler.SEND_MESSAGE.data = new Object[] {
"\u00A7eIt's a " + name + (!name.contains("block") ? " block." : ".") };
NewPacketHandler.SEND_MESSAGE.executeClient(Minecraft.getMinecraft().thePlayer);
}
} else if (o.typeOfHit == MovingObjectType.ENTITY && o.entityHit != null) {
NewPacketHandler.EXAMINE_MOB.sendToServer(o.entityHit.dimension, o.entityHit.getEntityId());
}
}
}
}
|