use of net.minecraft.world.ChunkCoordIntPair in project ArsMagica2 by Mithion.
the class PowerNodeRegistry method saveAll.
public HashMap<ChunkCoordIntPair, NBTTagCompound> saveAll() {
HashMap<ChunkCoordIntPair, NBTTagCompound> allData = new HashMap<ChunkCoordIntPair, NBTTagCompound>();
for (ChunkCoordIntPair pair : this.powerNodes.keySet()) {
NBTTagCompound chunkCompound = new NBTTagCompound();
SaveChunkToNBT(pair, chunkCompound);
allData.put(pair, chunkCompound);
}
return allData;
}
use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.
the class RadarMap method remove.
public boolean remove(RadarObject object) {
ChunkCoordIntPair pair = getChunkValue((int) object.x(), (int) object.z());
allEntities.remove(object);
if (chunk_to_entities.containsKey(pair)) {
List<RadarObject> list = chunk_to_entities.get(pair);
boolean b = list.remove(object);
//TODO fire map update event
if (list.isEmpty()) {
chunk_to_entities.remove(pair);
}
return b;
}
return false;
}
use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.
the class RadarMap method update.
/**
* Called at the end of every world tick to do checks on
* data stored.
*/
public void update() {
debug.start("Update", "Objects: " + allEntities.size() + " Chunks: " + chunk_to_entities.size());
if (ticks++ >= UPDATE_DELAY && chunk_to_entities.size() > 0) {
ticks = 0;
//TODO consider multi-threading if number of entries is too high (need to ensure runs in less than 10ms~)
debug.start("Looking for invalid radar objects and updating position data");
HashMap<RadarObject, ChunkCoordIntPair> removeList = new HashMap();
List<RadarObject> addList = new ArrayList();
for (Map.Entry<ChunkCoordIntPair, List<RadarObject>> entry : chunk_to_entities.entrySet()) {
if (entry.getValue() != null) {
for (RadarObject object : entry.getValue()) {
if (entry.getKey() != object.getChunkCoordIntPair()) {
debug.log("Removed from map: " + object);
removeList.put(object, entry.getKey());
if (object.isValid()) {
addList.add(object);
debug.log("Queued for re-add");
}
}
}
}
}
debug.end();
debug.start("Removing objects from map");
for (Map.Entry<RadarObject, ChunkCoordIntPair> entry : removeList.entrySet()) {
allEntities.remove(entry.getKey());
List<RadarObject> list = chunk_to_entities.get(entry.getValue());
if (list != null) {
list.remove(entry.getKey());
if (list.size() > 0) {
chunk_to_entities.put(entry.getValue(), list);
} else {
chunk_to_entities.remove(entry.getValue());
}
} else {
chunk_to_entities.remove(entry.getValue());
}
}
debug.end();
debug.start("Adding entries: " + addList.size());
addList.forEach(this::add);
debug.end();
debug.start("Removing invalid objects");
Iterator<RadarObject> it = allEntities.iterator();
while (it.hasNext()) {
RadarObject object = it.next();
if (!object.isValid()) {
debug.log("Removed: " + object);
it.remove();
}
}
debug.end();
}
debug.end();
}
use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.
the class RadioMap method remove.
public boolean remove(IRadioWaveReceiver receiver) {
if (fullMapRangeReceives.contains(receiver)) {
fullMapRangeReceives.remove(receiver);
}
if (receive_to_chunks.containsKey(receiver)) {
//Clear cached chunk positions
for (ChunkCoordIntPair pair : receive_to_chunks.get(receiver)) {
if (chunk_to_entities.containsKey(pair)) {
chunk_to_entities.get(pair).remove(receiver);
}
}
//Clear entry in receiver map
receive_to_chunks.remove(receiver);
//Update sender cache
for (IRadioWaveSender sender : sender_to_receivers_cache.keySet()) {
List<IRadioWaveReceiver> receivers = sender_to_receivers_cache.get(sender);
if (receivers == null) {
receivers = new ArrayList();
}
if (receivers.contains(receiver)) {
receivers.remove(receiver);
}
sender_to_receivers_cache.put(sender, receivers);
}
return true;
}
return false;
}
use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.
the class ChunkMap method onChunkLoaded.
@SubscribeEvent
public void onChunkLoaded(ChunkEvent.Load event) {
Chunk chunk = event.getChunk();
ChunkCoordIntPair coords = chunk.getChunkCoordIntPair();
if (chunks.containsKey(coords)) {
//TODO load data into existing object
} else {
//TODO load object
}
}
Aggregations