[fix] Freecam chunk rendering (#1644)

* [fix] Appropriately modify `renderChunksMany` when toggling Freecam

To optimise chunk rendering, minecraft tries to omit (normally) invisible chunks from chunk rendering. However, when the player's head is in an opaque block AND the classic 'block in head' overlay is not drawn, the player should see a sort of x-ray like view of the world. This happens in e.g. spectator mode. The `renderChunksMany` field in Minecraft also controls this behaviour, allowing modders to turn off the optimisation.

* [cleanup] Extract Freecam camera entity ID to constant field
This commit is contained in:
Ridan Vandenbergh 2020-11-29 14:30:49 +01:00 committed by GitHub
parent 526d603ad9
commit 0a80613f9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -41,19 +41,26 @@ object Freecam : Module() {
var cameraGuy: EntityPlayer? = null; private set
var resetInput = false
private const val ENTITY_ID = -6969420
override fun onDisable() {
mc.renderChunksMany = true
if (mc.player == null) return
mc.world.removeEntityFromWorld(-6969420)
mc.world.removeEntityFromWorld(ENTITY_ID)
mc.setRenderViewEntity(mc.player)
cameraGuy = null
if (prevThirdPersonViewSetting != -1) mc.gameSettings.thirdPersonView = prevThirdPersonViewSetting
}
override fun onEnable() {
mc.renderChunksMany = false
}
init {
listener<ConnectionEvent.Disconnect> {
prevThirdPersonViewSetting = -1
cameraGuy = null
mc.renderChunksMany = true
if (disableOnDisconnect.value) disable()
}
@ -95,7 +102,7 @@ object Freecam : Module() {
// Create a cloned player
cameraGuy = FakeCamera(mc.player).also {
// Add it to the world
mc.world.addEntityToWorld(-6969420, it)
mc.world.addEntityToWorld(ENTITY_ID, it)
// Set the render view entity to our camera guy
mc.setRenderViewEntity(it)