-
Notifications
You must be signed in to change notification settings - Fork 50
/
WorldExtension.java
100 lines (79 loc) · 2.22 KB
/
WorldExtension.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
package codechicken.lib.world;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import java.util.HashMap;
public abstract class WorldExtension
{
public final World world;
public HashMap<Chunk, ChunkExtension> chunkMap = new HashMap<Chunk, ChunkExtension>();
public WorldExtension(World world)
{
this.world = world;
}
public void load()
{
}
public void unload()
{
}
public void save()
{
}
public void preTick()
{
}
public void postTick()
{
}
protected final void addChunk(ChunkExtension extension)
{
chunkMap.put(extension.chunk, extension);
}
protected final void loadChunk(Chunk chunk)
{
chunkMap.get(chunk).load();
}
protected final void unloadChunk(Chunk chunk)
{
chunkMap.get(chunk).unload();
}
protected final void loadChunkData(Chunk chunk, NBTTagCompound tag)
{
chunkMap.get(chunk).loadData(tag);
}
protected final void saveChunkData(Chunk chunk, NBTTagCompound tag)
{
chunkMap.get(chunk).saveData(tag);
}
protected final void remChunk(Chunk chunk)
{
chunkMap.remove(chunk);
}
protected final void watchChunk(Chunk chunk, EntityPlayerMP player)
{
chunkMap.get(chunk).watchPlayer(player);
}
protected final void unwatchChunk(Chunk chunk, EntityPlayerMP player)
{
ChunkExtension extension = chunkMap.get(chunk);
if(extension != null)
extension.unwatchPlayer(player);
}
protected final void sendChunkUpdates(Chunk chunk)
{
chunkMap.get(chunk).sendUpdatePackets();
}
public boolean containsChunk(Chunk chunk)
{
return chunkMap.containsKey(chunk);
}
public ChunkExtension getChunkExtension(int chunkXPos, int chunkZPos)
{
if(!world.isBlockLoaded(new BlockPos(chunkXPos<<4, 128, chunkZPos<<4)))
return null;
return chunkMap.get(world.getChunkFromChunkCoords(chunkXPos, chunkZPos));
}
}