-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PatchPlayerInstance.java
102 lines (87 loc) · 3.17 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
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
package me.nallar.patched;
import java.util.ArrayList;
import java.util.List;
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.tileentity.TileEntity;
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;
private List<TileEntity> tilesToUpdate;
public PatchPlayerInstance(PlayerManager par1PlayerManager, int par2, int par3) {
super(par1PlayerManager, par2, par3);
}
public void construct() {
tilesToUpdate = new ArrayList<TileEntity>();
}
@Override
@Declare
public void updateTile(TileEntity tileEntity) {
if (numberOfTilesToUpdate == 0) {
this.myManager.playerUpdateLock.lock();
try {
this.myManager.getChunkWatcherWithPlayers().add(this);
} finally {
this.myManager.playerUpdateLock.unlock();
}
numberOfTilesToUpdate++;
}
if (!tilesToUpdate.contains(tileEntity)) {
tilesToUpdate.add(tileEntity);
}
}
@Override
@Declare
public void sendTiles() {
for (TileEntity tileEntity : tilesToUpdate) {
sendTileToAllPlayersWatchingChunk(tileEntity);
}
tilesToUpdate.clear();
}
@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
@Declare
public void clearTileCount() {
this.numberOfTilesToUpdate = 0;
}
@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 (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);
}
}
}
}