Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Commit

Permalink
Fix hash stuff...
Browse files Browse the repository at this point in the history
  • Loading branch information
robotia committed Mar 5, 2016
1 parent 9579d64 commit 50706e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/bukkit/craftbukkit/CraftWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public boolean loadChunk(int x, int z, boolean generate) {

private void chunkLoadPostProcess(net.minecraft.world.chunk.Chunk chunk, int x, int z) {
if (chunk != null) {
world.theChunkProviderServer.loadedChunkHashMap_KC.add(LongHash.toLong(x, z), chunk); // Passes to chunkt_TH
world.theChunkProviderServer.loadedChunkHashMap_KC.add(ChunkCoordIntPair.chunkXZ2Int(x, z), chunk); // Passes to chunkt_TH
world.theChunkProviderServer.loadedChunks.add(chunk); // Cauldron - vanilla compatibility
chunk.onChunkLoad();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/bukkit/craftbukkit/util/LongHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class LongHash {
public static long toLong(int msw, int lsw) {
return ((long) msw << 32) + lsw - Integer.MIN_VALUE;
return (long)msw & 4294967295L | ((long)lsw & 4294967295L) << 32;
}

public static int msw(long l) {
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/thermos/wrapper/VanillaChunkHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

public class VanillaChunkHashMap extends LongHashMap {
private final ChunkBlockHashMap chunkt_TH;
private final ConcurrentHashMap<Long,Chunk> vanilla = new ConcurrentHashMap<Long,Chunk>();
private final HashMap<Integer,Chunk> vanilla = new HashMap<Integer,Chunk>();
public VanillaChunkHashMap(ChunkBlockHashMap chunkt_TH) {
this.chunkt_TH = chunkt_TH;
}

private static long V2B(long key) {
/*private static long V2B(long key) {
return LongHash.toLong((int) (key & 0xFFFFFFFFL), (int) (key >>> 32));
}
}*/

public ConcurrentHashMap<Long,Chunk> rawVanilla()
public HashMap<Integer,Chunk> rawVanilla()
{
return vanilla;
}
Expand All @@ -41,30 +41,35 @@ public void add(long key, Object value) {
{
Chunk c = (Chunk) value;
chunkt_TH.put(c);
vanilla.put(V2B(key), c);
vanilla.put(super.getHashedKey(key), c);
}
}


@Override
public boolean containsItem(long key) {
return vanilla.containsKey(V2B(key));
return vanilla.containsKey(super.getHashedKey(key));
}

@Override
public Object getValueByKey(long key) {
return vanilla.get(V2B(key));
return vanilla.get(super.getHashedKey(key));
}

@Override
public Object remove(long key) {
Object o = vanilla.remove(V2B(key));
Object o = vanilla.remove(super.getHashedKey(key));
if(o instanceof Chunk) // Thermos - Use our special map
{
Chunk c = (Chunk)o;
chunkt_TH.remove(c);
}
return o;
}


@Override
public int getNumHashElements()
{
return this.vanilla.size();
}
}

0 comments on commit 50706e7

Please sign in to comment.