-
Notifications
You must be signed in to change notification settings - Fork 9
/
ClientProxy.java
83 lines (67 loc) · 3.22 KB
/
ClientProxy.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
package dmillerw.ping.proxy;
import dmillerw.ping.client.KeyHandler;
import dmillerw.ping.data.PingType;
import dmillerw.ping.data.PingWrapper;
import dmillerw.ping.network.PacketHandler;
import dmillerw.ping.network.packet.ClientSendPing;
import dmillerw.ping.util.RaytraceHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.RayTraceResult;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import java.awt.*;
public class ClientProxy extends CommonProxy {
public static int pingR;
public static int pingG;
public static int pingB;
public static boolean blockOverlay;
public static boolean menuBackground;
public static boolean sound;
public static double pingAcceptDistance;
public static int pingDuration;
public static Configuration configuration;
public static void sendPing(PingType type) {
RayTraceResult mob = RaytraceHelper.raytrace(Minecraft.getMinecraft().player, 50);
if (mob != null && mob.typeOfHit == RayTraceResult.Type.BLOCK) {
sendPing(mob, new Color(ClientProxy.pingR, ClientProxy.pingG, ClientProxy.pingB).getRGB(), type);
}
}
private static void sendPing(RayTraceResult mob, int color, PingType type) {
PacketHandler.INSTANCE.sendToServer(new ClientSendPing(new PingWrapper(mob.getBlockPos(), color, type)));
}
@Override
public void preInit(FMLPreInitializationEvent event) {
super.preInit(event);
ClientRegistry.registerKeyBinding(KeyHandler.KEY_BINDING);
configuration = new Configuration(event.getSuggestedConfigurationFile());
configuration.load();
}
@Override
public void syncConfig() {
Property p_pingR = configuration.get("visual", "red", 255, "Value from 0 - 255");
Property p_pingG = configuration.get("visual", "green", 0, "Value from 0 - 255");
Property p_pingB = configuration.get("visual", "blue", 0, "Value from 0 - 255");
pingR = verify(p_pingR);
pingG = verify(p_pingG);
pingB = verify(p_pingB);
blockOverlay = configuration.get("visual", "blockOverlay", true, "Whether to render a colored overlay on the Pinged block").getBoolean();
menuBackground = configuration.get("visual", "backgroundMenu", true, "Whether to render the Ping Menu background").getBoolean();
sound = configuration.get("general", "sound", true, "Whether to play a sound when a Ping is received").getBoolean();
pingAcceptDistance = configuration.get("general", "pingAcceptDistance", 64D, "Maximum distance a Ping can be from you and still be received").getDouble();
pingDuration = configuration.get("general", "pingDuration", 125, "How long a Ping should remain active before disappearing").getInt();
if (configuration.hasChanged()) {
configuration.save();
}
}
private int verify(Property property) {
int value = property.getInt();
if (value < 0) {
value = 0;
} else if (value > 255) {
value = 255;
}
return value;
}
}