fixed energy re-eval position collisions

This commit is contained in:
Boblet 2022-07-06 16:43:53 +02:00
parent 7777fdb32a
commit 810f5d2680
3 changed files with 46 additions and 1 deletions

View File

@ -30,7 +30,7 @@ public interface IEnergyConductor extends IEnergyConnector {
}
public static int getIdentityFromPos(int x, int y, int z) {
final int prime = 31;
final int prime = 27644437; // must be this large to minimize localized collisions
int result = 1;
result = prime * result + x;
result = prime * result + y;

View File

@ -72,6 +72,7 @@ import com.hbm.lib.RefStrings;
import com.hbm.packet.PacketDispatcher;
import com.hbm.potion.HbmPotion;
import com.hbm.saveddata.satellites.Satellite;
import com.hbm.test.ReEvalTest;
import com.hbm.tileentity.TileMappings;
import com.hbm.tileentity.bomb.TileEntityNukeCustom;
import com.hbm.tileentity.machine.*;

View File

@ -0,0 +1,44 @@
package com.hbm.test;
import java.util.HashMap;
import com.hbm.main.MainRegistry;
import api.hbm.energy.IEnergyConductor;
public class ReEvalTest {
/**
* Runs a collision test on a relatively large scale. So large in fact that it will most certainly OOM.
* Not an issue, since by that point we will already have our results.
* @throws OutOfMemoryError
*/
public static void runTest() throws OutOfMemoryError {
HashMap<Integer, int[]> collisions = new HashMap();
int minX = -130;
int maxX = 140;
int minZ = 300;
int maxZ = 520;
MainRegistry.logger.info("Starting collision test...");
for(int x = minX; x <= maxX; x++) {
for(int y = 1; y <= 255; y++) {
for(int z = minZ; z <= maxZ; z++) {
int identity = IEnergyConductor.getIdentityFromPos(x, y, z);
if(collisions.containsKey(identity)) {
int[] collision = collisions.get(identity);
MainRegistry.logger.info("Position " + x + "/" + y + "/" + z + " collides with " + collision[0] + "/" + collision[1] + "/" + collision[2] + "!");
} else {
collisions.put(identity, new int[] {x, y, z});
}
}
}
}
MainRegistry.logger.info("Collision test complete!");
}
}