This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_VanishStatus.java
103 lines (82 loc) · 2.85 KB
/
mod_VanishStatus.java
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
package net.minecraft.src;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TimerTask;
import java.util.logging.Level;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
public class mod_VanishStatus extends BaseMod
{
boolean isVanished = false;
public mod_VanishStatus()
{
}
public String getName()
{
return "VanishStatus";
}
public String getVersion()
{
return "1.2";
}
public void load()
{
ModLoader.setInGameHook(this, true, false);
ModLoader.registerPacketChannel(this, "vanishStatus");
}
public boolean onTickInGame(float f, Minecraft mc)
{
if((mc.inGameHasFocus || mc.currentScreen == null) && !mc.gameSettings.showDebugInfo && !mc.gameSettings.keyBindPlayerList.pressed)
{
int potionFakeIndex = 1337;
boolean hasVanishPotion = mc.thePlayer.activePotionsMap.containsKey(potionFakeIndex);
if (isVanished && !hasVanishPotion)
{
mc.thePlayer.activePotionsMap.put(potionFakeIndex, new VanishPotionEffect());
}
else if (!isVanished && hasVanishPotion)
{
mc.thePlayer.activePotionsMap.remove(potionFakeIndex);
}
}
return true;
}
public static void sendMessage(String channel, String message, NetClientHandler netclienthandler) {
Packet250CustomPayload plugin = new Packet250CustomPayload();
plugin.channel = channel;
plugin.data = message.getBytes();
plugin.length = message.length();
netclienthandler.addToSendQueue(plugin);
}
// ModLoader @ MC 1.2.5
public void receiveCustomPacket(Packet250CustomPayload packet250custompayload)
{
if (packet250custompayload.channel.equalsIgnoreCase("vanishStatus"))
{
handleMCMessage(packet250custompayload.data);
}
}
// ModLoader @ MC 1.3+
public void clientCustomPayload(NetClientHandler clientHandler, Packet250CustomPayload packet250custompayload)
{
receiveCustomPacket(packet250custompayload);
}
private void handleMCMessage(byte[] message)
{
isVanished = message.length > 0 && message[0] == 0x01;
System.out.println("[VanishStatus] Got vanish status: " + (isVanished ? "vanished" : "visible") );
}
// ModLoader @ MC 1.2.5
public void serverConnect(NetClientHandler netclienthandler) {
sendMessage("vanishStatus", "check", netclienthandler);
}
// ModLoader @ MC 1.3+
public void clientConnect(NetClientHandler netclienthandler) {
serverConnect(netclienthandler);
}
}