forked from NegaNote/GregTech-Modern-Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientTickHandler.java
More file actions
84 lines (66 loc) · 3.29 KB
/
ClientTickHandler.java
File metadata and controls
84 lines (66 loc) · 3.29 KB
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
package net.neganote.gtutilities.client.event;
import net.minecraft.client.Minecraft;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.neganote.gtutilities.GregTechModernUtilities;
import net.neganote.gtutilities.client.gui.screen.ColorRadialMenuScreen;
import net.neganote.gtutilities.client.keybind.UtilKeybinds;
import net.neganote.gtutilities.common.item.InfiniteSprayCanItem;
import net.neganote.gtutilities.network.UtilsNetwork;
import net.neganote.gtutilities.network.packet.SelectColorPacket;
@Mod.EventBusSubscriber(modid = GregTechModernUtilities.MOD_ID,
bus = Mod.EventBusSubscriber.Bus.FORGE,
value = Dist.CLIENT)
public class ClientTickHandler {
@SubscribeEvent
public static void onClientTick(TickEvent.ClientTickEvent event) {
if (event.phase != TickEvent.Phase.END) return;
Minecraft mc = Minecraft.getInstance();
if (mc.player == null || mc.level == null) return;
if (UtilKeybinds.SPRAY_CAN_MENU.consumeClick()) {
ItemStack stack = mc.player.getMainHandItem();
if (stack.getItem() instanceof InfiniteSprayCanItem) {
mc.setScreen(new ColorRadialMenuScreen(InteractionHand.MAIN_HAND));
}
}
}
@SubscribeEvent
public static void onMouseScroll(InputEvent.MouseScrollingEvent event) {
Minecraft mc = Minecraft.getInstance();
if (mc.player == null || mc.screen != null) return;
if (mc.options.keyShift.isDown()) {
ItemStack stack = mc.player.getMainHandItem();
if (stack.getItem() instanceof InfiniteSprayCanItem) {
double scrollDelta = event.getScrollDelta();
event.setCanceled(true);
int currentColor = stack.getOrCreateTag().getInt("color");
if (!stack.getOrCreateTag().contains("color")) currentColor = -1;
int direction = scrollDelta > 0 ? 1 : -1;
int nextColor = currentColor + direction;
if (nextColor < -1) nextColor = 15;
if (nextColor > 15) nextColor = -1;
UtilsNetwork.CHANNEL.sendToServer(new SelectColorPacket(InteractionHand.MAIN_HAND, nextColor));
mc.player.playSound(SoundEvents.UI_BUTTON_CLICK.value(), 0.1f, 1.5f + (nextColor * 0.05f));
}
}
}
@SubscribeEvent
public static void onRightClick(InputEvent.InteractionKeyMappingTriggered event) {
Minecraft mc = Minecraft.getInstance();
if (mc.player == null) return;
if (!event.isUseItem()) return;
ItemStack stack = mc.player.getMainHandItem();
if (!(stack.getItem() instanceof InfiniteSprayCanItem)) return;
if (!mc.player.isShiftKeyDown()) return;
if (mc.hitResult == null || mc.hitResult.getType() != HitResult.Type.MISS) return;
event.setCanceled(true);
mc.setScreen(new ColorRadialMenuScreen(InteractionHand.MAIN_HAND));
}
}