blob: 8ef5ed5d4e630b5b1a0b362edf9aac49c4d85464 (
plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
package me.djtheredstoner.perspectivemod;
import me.djtheredstoner.perspectivemod.commands.PerspectiveModCommand;
import me.djtheredstoner.perspectivemod.config.PerspectiveModConfig;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
@Mod(modid = "djperspectivemod", name = "Perspective Mod v4", version = "4.5", acceptedMinecraftVersions = "[1.8.9]", clientSideOnly = true)
public class PerspectiveMod {
@Mod.Instance
public static PerspectiveMod instance;
public final PerspectiveModConfig config = new PerspectiveModConfig();
public boolean perspectiveToggled = false;
public float cameraYaw = 0F;
public float cameraPitch = 0F;
private int previousPerspective = 0;
private boolean prevState = false;
private final Minecraft mc = Minecraft.getMinecraft();
private final KeyBinding perspectiveKey = new KeyBinding("Perspective", Keyboard.KEY_LMENU, "Perspective Mod");
private final Logger logger = LogManager.getLogger("Perspective Mod v4");
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
config.preload();
ClientRegistry.registerKeyBinding(perspectiveKey);
new PerspectiveModCommand("perspectivemod").register();
new PerspectiveModCommand("pmod").register();
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void tick(TickEvent.RenderTickEvent event) {
boolean down = GameSettings.isKeyDown(perspectiveKey);
if(down != prevState && mc.currentScreen == null && mc.theWorld != null && mc.thePlayer != null) {
prevState = down;
onPressed(down);
}
}
@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
if (event.gui != null && perspectiveToggled && config.holdMode) {
resetPerspective();
}
}
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event) {
if (perspectiveToggled) {
resetPerspective();
}
}
public void onPressed(boolean state) {
if (config.modEnabled) {
if (state) {
cameraYaw = mc.thePlayer.rotationYaw;
cameraPitch = mc.thePlayer.rotationPitch;
if (perspectiveToggled) {
resetPerspective();
} else {
enterPerspective();
}
mc.renderGlobal.setDisplayListEntitiesDirty();
} else if (config.holdMode) {
resetPerspective();
}
} else if (perspectiveToggled) {
resetPerspective();
}
}
public void enterPerspective() {
perspectiveToggled = true;
previousPerspective = mc.gameSettings.thirdPersonView;
mc.gameSettings.thirdPersonView = 1;
}
public void resetPerspective() {
perspectiveToggled = false;
mc.gameSettings.thirdPersonView = previousPerspective;
mc.renderGlobal.setDisplayListEntitiesDirty();
}
public boolean overrideMouse() {
if (mc.inGameHasFocus && Display.isActive()) {
if (!perspectiveToggled) {
return true;
}
// CODE
mc.mouseHelper.mouseXYChange();
float f1 = mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
float f2 = f1 * f1 * f1 * 8.0F;
float f3 = (float) mc.mouseHelper.deltaX * f2;
float f4 = (float) mc.mouseHelper.deltaY * f2;
if(config.invertPitch) {
f4 = -f4;
}
cameraYaw += f3 * 0.15F;
cameraPitch += f4 * 0.15F;
if (cameraPitch > 90) cameraPitch = 90;
if (cameraPitch < -90) cameraPitch = -90;
mc.renderGlobal.setDisplayListEntitiesDirty();
}
return false;
}
}
|