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;
|
2025-02-03 03:41:01 +01:00
|
|
|
import kamkeel.npcs.network.PacketClient;
|
2025-02-03 03:57:40 +01:00
|
|
|
import kamkeel.npcs.network.packets.player.CheckPlayerValue;
|
2025-02-03 01:32:49 +01:00
|
|
|
import kamkeel.npcs.network.packets.player.InputDevicePacket;
|
2025-02-03 03:41:01 +01:00
|
|
|
import kamkeel.npcs.network.packets.player.ScreenSizePacket;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.client.Minecraft;
|
2024-05-14 18:32:30 -05:00
|
|
|
import net.minecraft.entity.Entity;
|
2025-02-23 06:29:53 -05:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.inventory.ContainerPlayer;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import noppes.npcs.CustomNpcs;
|
|
|
|
|
import noppes.npcs.client.controllers.MusicController;
|
2022-07-13 19:27:27 -05:00
|
|
|
import noppes.npcs.client.controllers.ScriptSoundController;
|
2025-02-23 06:29:53 -05:00
|
|
|
import noppes.npcs.client.gui.hud.ClientHudManager;
|
|
|
|
|
import noppes.npcs.client.gui.hud.CompassHudComponent;
|
|
|
|
|
import noppes.npcs.client.gui.hud.EnumHudComponent;
|
|
|
|
|
import noppes.npcs.client.gui.hud.HudComponent;
|
2025-02-20 21:40:39 -05:00
|
|
|
import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.client.renderer.RenderNPCInterface;
|
2025-02-23 06:29:53 -05:00
|
|
|
import noppes.npcs.constants.MarkType;
|
|
|
|
|
import noppes.npcs.controllers.data.MarkData;
|
|
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
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;
|
2025-02-18 18:48:56 -05:00
|
|
|
import tconstruct.client.tabs.InventoryTabCustomNpc;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2025-02-23 06:29:53 -05:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
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;
|
2024-01-05 16:31:57 +03:00
|
|
|
private int prevWidth = 0;
|
|
|
|
|
private int prevHeight = 0;
|
2018-09-13 12:03:28 -04:00
|
|
|
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};
|
2024-03-04 23:14:41 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
@SubscribeEvent(priority = EventPriority.LOWEST)
|
|
|
|
|
public void onClientTick(TickEvent.ClientTickEvent event){
|
|
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
2024-08-22 16:47:45 -04:00
|
|
|
if ((this.prevWorld == null || mc.theWorld == null) && this.prevWorld != mc.theWorld) {
|
2025-02-12 13:16:39 -06:00
|
|
|
if (mc.theWorld == null) {
|
|
|
|
|
ClientCacheHandler.clearCache();
|
|
|
|
|
}
|
2023-06-05 18:50:41 -05:00
|
|
|
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){
|
2025-02-03 03:57:40 +01:00
|
|
|
PacketClient.sendClient(new CheckPlayerValue(CheckPlayerValue.Type.CheckQuestCompletion));
|
2018-09-13 12:03:28 -04:00
|
|
|
otherContainer = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
otherContainer = true;
|
|
|
|
|
CustomNpcs.ticks++;
|
|
|
|
|
RenderNPCInterface.LastTextureTick++;
|
|
|
|
|
if(prevWorld != mc.theWorld){
|
|
|
|
|
prevWorld = mc.theWorld;
|
2024-05-16 02:01:04 -05:00
|
|
|
MusicController.Instance.stopAllSounds();
|
2024-05-14 18:32:30 -05:00
|
|
|
} else if (MusicController.Instance.isPlaying() && MusicController.Instance.getEntity() != null) {
|
|
|
|
|
Entity entity = MusicController.Instance.getEntity();
|
|
|
|
|
if (MusicController.Instance.getOffRange() > 0 &&
|
2024-08-22 13:42:12 -04:00
|
|
|
(Minecraft.getMinecraft().thePlayer == null ||
|
|
|
|
|
Minecraft.getMinecraft().thePlayer.getDistanceToEntity(entity) > MusicController.Instance.getOffRange() ||
|
|
|
|
|
entity.dimension != Minecraft.getMinecraft().thePlayer.dimension)) {
|
2024-05-14 18:32:30 -05:00
|
|
|
MusicController.Instance.stopMusic();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-15 03:35:39 -05:00
|
|
|
MusicController.Instance.onUpdate();
|
2022-07-13 19:27:27 -05:00
|
|
|
ScriptSoundController.Instance.onUpdate();
|
2024-01-05 16:31:57 +03:00
|
|
|
if(Minecraft.getMinecraft().thePlayer!=null && (prevWidth!=mc.displayWidth || prevHeight!=mc.displayHeight)){
|
|
|
|
|
prevWidth = mc.displayWidth;
|
|
|
|
|
prevHeight = mc.displayHeight;
|
2025-02-03 03:41:01 +01:00
|
|
|
PacketClient.sendClient(new ScreenSizePacket(mc.displayWidth,mc.displayHeight));
|
2024-01-05 16:31:57 +03:00
|
|
|
}
|
2025-02-23 06:29:53 -05:00
|
|
|
|
|
|
|
|
if(mc.theWorld == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(mc.theWorld.getTotalWorldTime() % 20 == 0) { // Update every second
|
|
|
|
|
updateCompassMarks();
|
|
|
|
|
}
|
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;
|
|
|
|
|
|
2025-02-03 01:32:49 +01:00
|
|
|
InputDevicePacket.sendMouse(Mouse.getEventButton(),Mouse.getEventDWheel(),Mouse.isButtonDown(Mouse.getEventButton()));
|
2021-10-12 02:57:32 -05:00
|
|
|
}
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onKey(InputEvent.KeyInputEvent event){
|
2024-03-17 16:09:31 -04:00
|
|
|
if(ClientProxy.NPCButton.isPressed()){
|
2018-09-13 12:03:28 -04:00
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
2024-03-04 23:14:41 -05:00
|
|
|
if(mc.currentScreen == null){
|
2025-02-18 18:48:56 -05:00
|
|
|
InventoryTabCustomNpc.tabHelper();
|
2024-03-04 23:14:41 -05:00
|
|
|
}
|
2024-04-17 03:20:30 -04:00
|
|
|
else if(mc.currentScreen instanceof GuiCNPCInventory)
|
2018-09-13 12:03:28 -04:00
|
|
|
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 keyDown = Keyboard.isKeyDown(key);
|
2021-11-13 13:32:33 -06:00
|
|
|
|
2025-02-03 01:32:49 +01:00
|
|
|
InputDevicePacket.sendKeyboard(key, keyDown);
|
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;
|
|
|
|
|
}
|
2025-02-23 06:29:53 -05:00
|
|
|
|
|
|
|
|
private final int SCAN_RANGE = 128;
|
|
|
|
|
private void updateCompassMarks() {
|
|
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
|
|
|
|
EntityPlayer player = mc.thePlayer;
|
2025-02-23 15:38:42 -05:00
|
|
|
|
|
|
|
|
// Update compass
|
|
|
|
|
HudComponent compass = ClientHudManager.getInstance()
|
|
|
|
|
.getHudComponents().get(EnumHudComponent.QuestCompass);
|
|
|
|
|
|
|
|
|
|
if(!compass.enabled || mc.thePlayer == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-02-23 06:29:53 -05:00
|
|
|
ArrayList<CompassHudComponent.MarkTargetEntry> marks = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// Scan entities in loaded chunks
|
|
|
|
|
for(Object entity : mc.theWorld.loadedEntityList) {
|
|
|
|
|
if(entity instanceof EntityNPCInterface) {
|
|
|
|
|
EntityNPCInterface npc = (EntityNPCInterface) entity;
|
|
|
|
|
|
2025-02-23 15:38:42 -05:00
|
|
|
if(npc.dimension != player.dimension)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-02-23 06:29:53 -05:00
|
|
|
// Check distance
|
|
|
|
|
if(player.getDistanceToEntity(npc) > SCAN_RANGE)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Get marks
|
|
|
|
|
MarkData markData = MarkData.get(npc);
|
|
|
|
|
for(MarkData.Mark mark : markData.marks) {
|
|
|
|
|
if(mark.getType() != MarkType.NONE &&
|
|
|
|
|
mark.availability.isAvailable(player)) {
|
|
|
|
|
marks.add(new CompassHudComponent.MarkTargetEntry(
|
|
|
|
|
(int)npc.posX,
|
|
|
|
|
(int)npc.posZ,
|
|
|
|
|
mark.getType(),
|
|
|
|
|
mark.color
|
|
|
|
|
));
|
|
|
|
|
break; // Only show first valid mark per NPC
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-23 15:38:42 -05:00
|
|
|
((CompassHudComponent) compass).updateMarkTargets(marks);
|
2025-02-23 06:29:53 -05:00
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|