2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs.client;
|
|
|
|
|
|
2023-01-12 21:33:06 -05:00
|
|
|
import cpw.mods.fml.common.eventhandler.EventPriority;
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
|
import cpw.mods.fml.common.gameevent.InputEvent;
|
|
|
|
|
import cpw.mods.fml.common.gameevent.TickEvent;
|
|
|
|
|
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
import net.minecraft.inventory.ContainerPlayer;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import noppes.npcs.CustomNpcs;
|
|
|
|
|
import noppes.npcs.NoppesUtilPlayer;
|
|
|
|
|
import noppes.npcs.client.controllers.MusicController;
|
2022-07-13 19:27:27 -05:00
|
|
|
import noppes.npcs.client.controllers.ScriptSoundController;
|
2024-01-11 03:50:10 -05:00
|
|
|
import noppes.npcs.client.gui.player.inventory.GuiQuestLog;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.client.renderer.RenderNPCInterface;
|
|
|
|
|
import noppes.npcs.constants.EnumPlayerPacket;
|
2021-10-11 07:16:10 -05:00
|
|
|
import org.lwjgl.input.Keyboard;
|
2021-10-12 02:57:32 -05:00
|
|
|
import org.lwjgl.input.Mouse;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2022-08-31 07:53:35 -05:00
|
|
|
import static noppes.npcs.client.ClientEventHandler.renderCNPCPlayer;
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public class ClientTickHandler{
|
|
|
|
|
private World prevWorld;
|
|
|
|
|
private boolean otherContainer = false;
|
2021-10-11 07:16:10 -05:00
|
|
|
private int buttonPressed = -1;
|
|
|
|
|
private long buttonTime = 0L;
|
|
|
|
|
private final int[] ignoreKeys = new int[]{157, 29, 54, 42, 184, 56, 220, 219};
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
@SubscribeEvent(priority = EventPriority.LOWEST)
|
|
|
|
|
public void onClientTick(TickEvent.ClientTickEvent event){
|
|
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
2023-06-05 18:50:41 -05:00
|
|
|
if ((this.prevWorld == null || mc.theWorld == null) && this.prevWorld != mc.theWorld) {
|
|
|
|
|
ClientCacheHandler.clearCache();
|
|
|
|
|
this.prevWorld = mc.theWorld;
|
|
|
|
|
}
|
2022-08-31 07:53:35 -05:00
|
|
|
if(event.phase == Phase.END) {
|
|
|
|
|
if (mc.thePlayer != null && mc.theWorld != null && !mc.isGamePaused() && ClientEventHandler.hasOverlays(mc.thePlayer)) {
|
|
|
|
|
renderCNPCPlayer.itemRenderer.updateEquippedItem();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
if(mc.thePlayer != null && mc.thePlayer.openContainer instanceof ContainerPlayer){
|
|
|
|
|
if(otherContainer){
|
|
|
|
|
NoppesUtilPlayer.sendData(EnumPlayerPacket.CheckQuestCompletion);
|
|
|
|
|
otherContainer = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
otherContainer = true;
|
|
|
|
|
CustomNpcs.ticks++;
|
|
|
|
|
RenderNPCInterface.LastTextureTick++;
|
|
|
|
|
if(prevWorld != mc.theWorld){
|
|
|
|
|
prevWorld = mc.theWorld;
|
|
|
|
|
MusicController.Instance.stopMusic();
|
|
|
|
|
}
|
2022-07-13 19:27:27 -05:00
|
|
|
ScriptSoundController.Instance.onUpdate();
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
2021-10-12 02:57:32 -05:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onMouse(InputEvent.MouseInputEvent event){
|
2022-07-17 16:41:52 -05:00
|
|
|
if(Mouse.getEventButton() == -1 && Mouse.getEventDWheel() == 0)
|
2021-10-12 02:57:32 -05:00
|
|
|
return;
|
|
|
|
|
|
2022-07-06 18:41:39 -05:00
|
|
|
boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29);
|
|
|
|
|
boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42);
|
|
|
|
|
boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56);
|
|
|
|
|
boolean isMetaPressed = Keyboard.isKeyDown(220) || Keyboard.isKeyDown(219);
|
|
|
|
|
|
2022-07-18 01:03:22 -05:00
|
|
|
StringBuilder keysDownString = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < Keyboard.getKeyCount(); i++) {//Creates a comma separated string of the integer IDs of held keys
|
|
|
|
|
if (Keyboard.isKeyDown(i)) {
|
|
|
|
|
keysDownString.append(Integer.valueOf(i)).append(",");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (keysDownString.length() > 0) {//Removes last comma for later parsing
|
|
|
|
|
keysDownString.deleteCharAt(keysDownString.length() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NoppesUtilPlayer.sendData(EnumPlayerPacket.MouseClicked, Mouse.getEventButton(),Mouse.getEventDWheel(),Mouse.isButtonDown(Mouse.getEventButton()), isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, keysDownString.toString());
|
2021-10-12 02:57:32 -05:00
|
|
|
}
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onKey(InputEvent.KeyInputEvent event){
|
2024-01-11 03:51:02 -05:00
|
|
|
if(ClientProxy.CNPCButton.isPressed()){
|
2018-09-13 12:03:28 -04:00
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
|
|
|
|
if(mc.currentScreen == null)
|
|
|
|
|
NoppesUtil.openGUI(mc.thePlayer, new GuiQuestLog(mc.thePlayer));
|
|
|
|
|
else if(mc.currentScreen instanceof GuiQuestLog)
|
|
|
|
|
mc.setIngameFocus();
|
|
|
|
|
}
|
2021-10-11 07:16:10 -05:00
|
|
|
|
2022-05-03 13:34:56 -05:00
|
|
|
if(!Keyboard.isRepeatEvent()) {
|
|
|
|
|
int key = Keyboard.getEventKey();
|
|
|
|
|
boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29);
|
|
|
|
|
boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42);
|
|
|
|
|
boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56);
|
|
|
|
|
boolean isMetaPressed = Keyboard.isKeyDown(220) || Keyboard.isKeyDown(219);
|
|
|
|
|
boolean keyDown = Keyboard.isKeyDown(key);
|
2021-11-13 13:32:33 -06:00
|
|
|
|
2022-05-03 13:34:56 -05:00
|
|
|
StringBuilder keysDownString = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < Keyboard.getKeyCount(); i++) {//Creates a comma separated string of the integer IDs of held keys
|
|
|
|
|
if (Keyboard.isKeyDown(i)) {
|
|
|
|
|
keysDownString.append(Integer.valueOf(i)).append(",");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (keysDownString.length() > 0) {//Removes last comma for later parsing
|
|
|
|
|
keysDownString.deleteCharAt(keysDownString.length() - 1);
|
2021-10-11 07:16:10 -05:00
|
|
|
}
|
2022-05-02 23:11:45 -05:00
|
|
|
|
2022-07-18 01:03:22 -05:00
|
|
|
NoppesUtilPlayer.sendData(EnumPlayerPacket.KeyPressed, key, isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, keyDown, keysDownString.toString());
|
2022-05-03 13:34:56 -05:00
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
2021-10-11 07:16:10 -05:00
|
|
|
private boolean isIgnoredKey(int key) {
|
|
|
|
|
int[] var2 = this.ignoreKeys;
|
|
|
|
|
int var3 = var2.length;
|
|
|
|
|
|
|
|
|
|
for(int var4 = 0; var4 < var3; ++var4) {
|
|
|
|
|
int i = var2[var4];
|
|
|
|
|
if(i == key) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|