-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PatchPlayerInstance.java
61 lines (51 loc) · 2.3 KB
/
PatchPlayerInstance.java
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
package me.nallar.tickthreading.minecraft.patched;
import me.nallar.tickthreading.patcher.Declare;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.packet.Packet51MapChunk;
import net.minecraft.server.management.PlayerInstance;
import net.minecraft.server.management.PlayerManager;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.ChunkWatchEvent;
public abstract class PatchPlayerInstance extends PlayerInstance {
private static byte[] unloadSequence;
public PatchPlayerInstance(PlayerManager par1PlayerManager, int par2, int par3) {
super(par1PlayerManager, par2, par3);
}
@Override
@Declare
public ChunkCoordIntPair getLocation() {
return chunkLocation;
}
public static void staticConstruct() {
unloadSequence = new byte[]{0x78, (byte) 0x9C, 0x63, 0x64, 0x1C, (byte) 0xD9, 0x00, 0x00, (byte) 0x81, (byte) 0x80, 0x01, 0x01};
}
@Override
public void sendThisChunkToPlayer(EntityPlayerMP par1EntityPlayerMP) {
if (this.playersInChunk.remove(par1EntityPlayerMP)) {
Packet51MapChunk packet51MapChunk = new Packet51MapChunk();
packet51MapChunk.includeInitialize = true;
packet51MapChunk.xCh = chunkLocation.chunkXPos;
packet51MapChunk.zCh = chunkLocation.chunkZPos;
packet51MapChunk.yChMax = 0;
packet51MapChunk.yChMin = 0;
packet51MapChunk.setData(unloadSequence);
par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(packet51MapChunk);
par1EntityPlayerMP.loadedChunks.remove(this.chunkLocation);
MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.UnWatch(chunkLocation, par1EntityPlayerMP));
if (this.playersInChunk.isEmpty()) {
long var2 = (long) this.chunkLocation.chunkXPos + 2147483647L | (long) this.chunkLocation.chunkZPos + 2147483647L << 32;
this.myManager.getChunkWatchers().remove(var2);
if (this.numberOfTilesToUpdate > 0) {
this.myManager.playerUpdateLock.lock();
try {
this.myManager.getChunkWatcherWithPlayers().remove(this);
} finally {
this.myManager.playerUpdateLock.unlock();
}
}
this.myManager.getWorldServer().theChunkProviderServer.unloadChunksIfNotNearSpawn(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos);
}
}
}
}