Added MultiBlock packet.

Tweaked performance for chunks that are < 64 changes for HungerGames.
This commit is contained in:
Jonathan Williams 2013-11-24 04:54:41 -08:00
parent 0a1f4ecfd5
commit e2646a982f
3 changed files with 38 additions and 2 deletions

View File

@ -14,6 +14,8 @@ import net.minecraft.server.v1_6_R3.ChunkCoordIntPair;
import net.minecraft.server.v1_6_R3.ChunkSection; import net.minecraft.server.v1_6_R3.ChunkSection;
import net.minecraft.server.v1_6_R3.IContainer; import net.minecraft.server.v1_6_R3.IContainer;
import net.minecraft.server.v1_6_R3.MinecraftServer; import net.minecraft.server.v1_6_R3.MinecraftServer;
import net.minecraft.server.v1_6_R3.Packet52MultiBlockChange;
import net.minecraft.server.v1_6_R3.PlayerChunkMap;
import net.minecraft.server.v1_6_R3.RegionFile; import net.minecraft.server.v1_6_R3.RegionFile;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -188,9 +190,17 @@ public class MapUtil
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void SendChunkForPlayer(int x, int z, Player player) public static void SendChunkForPlayer(int x, int z, Player player)
{ {
System.out.println("Sending Chunk " + x + ", " + z);
((CraftPlayer)player).getHandle().chunkCoordIntPairQueue.add(new ChunkCoordIntPair(x, z)); ((CraftPlayer)player).getHandle().chunkCoordIntPairQueue.add(new ChunkCoordIntPair(x, z));
} }
@SuppressWarnings("unchecked")
public static void SendMultiBlockForPlayer(int x, int z, short[] dirtyBlocks, int dirtyCount, World world, Player player)
{
System.out.println("Sending MultiBlockChunk " + x + ", " + z);
((CraftPlayer)player).getHandle().playerConnection.sendPacket(new Packet52MultiBlockChange(x, z, dirtyBlocks, dirtyCount, ((CraftWorld)world).getHandle()));
}
public static void UnloadWorld(JavaPlugin plugin, World world) public static void UnloadWorld(JavaPlugin plugin, World world)
{ {
world.setAutoSave(false); world.setAutoSave(false);

View File

@ -2,6 +2,8 @@ package nautilus.game.arcade.game.games.hungergames;
import java.util.ArrayList; import java.util.ArrayList;
import net.minecraft.server.v1_6_R3.PlayerChunkMap;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
@ -10,6 +12,8 @@ public class ChunkChange
public Chunk Chunk; public Chunk Chunk;
public long Time; public long Time;
public ArrayList<BlockChange> Changes; public ArrayList<BlockChange> Changes;
public short[] DirtyBlocks = new short[64];
public short DirtyCount = 0;
public ChunkChange(Location loc, int id, byte data) public ChunkChange(Location loc, int id, byte data)
{ {
@ -25,5 +29,24 @@ public class ChunkChange
public void AddChange(Location loc, int id, byte data) public void AddChange(Location loc, int id, byte data)
{ {
Changes.add(new BlockChange(loc, id, data)); Changes.add(new BlockChange(loc, id, data));
if (DirtyCount < 63)
{
short short1 = (short)((loc.getBlockX() & 0xF) << 12 | (loc.getBlockZ() & 0xF) << 8 | loc.getBlockY());
for (int l = 0; l < DirtyCount; l++)
{
if (DirtyBlocks[l] == short1)
{
return;
}
}
DirtyBlocks[(DirtyCount++)] = short1;
}
else
{
DirtyCount++;
}
} }
} }

View File

@ -770,7 +770,10 @@ public class HungerGames extends SoloGame
//change.Changes contains Location/Id/Data for all pending changes in this chunk //change.Changes contains Location/Id/Data for all pending changes in this chunk
//XXX Simply replace this line with the the Multiblocks packet. //XXX Simply replace this line with the the Multiblocks packet.
MapUtil.SendChunkForPlayer(change.Chunk.getX(), change.Chunk.getZ(), player); if (change.DirtyCount >= 63)
MapUtil.SendChunkForPlayer(change.Chunk.getX(), change.Chunk.getZ(), player);
else
MapUtil.SendMultiBlockForPlayer(change.Chunk.getX(), change.Chunk.getZ(), change.DirtyBlocks, change.DirtyCount, change.Chunk.getWorld(), player);
} }
} }