use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.
the class ChunkMap method onChunkUnloaded.
@SubscribeEvent
public void onChunkUnloaded(ChunkEvent.Unload event) {
Chunk chunk = event.getChunk();
ChunkCoordIntPair coords = chunk.getChunkCoordIntPair();
if (chunks.containsKey(coords)) {
//TODO save data
chunks.remove(coords);
}
}
use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.
the class RadarMap method add.
public boolean add(RadarObject object) {
if (!allEntities.contains(object) && object.isValid()) {
allEntities.add(object);
ChunkCoordIntPair pair = getChunkValue((int) object.x(), (int) object.z());
List<RadarObject> list;
//Get list or make new
if (chunk_to_entities.containsKey(pair)) {
list = chunk_to_entities.get(pair);
} else {
list = new ArrayList();
}
//Check if object is not already added
if (!list.contains(object)) {
list.add(object);
//TODO fire map update event
//TODO fire map add event
//Update map
chunk_to_entities.put(pair, list);
return true;
}
}
return false;
}
use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.
the class RadioMap method popMessage.
/**
* Called to send a message over the network
*
* @param sender - object that sent the message
* @param hz - frequency of the message
* @param header - descriptive header of the message, mainly an ID system
* @param data - data being sent in the message
*/
public void popMessage(IRadioWaveSender sender, float hz, String header, Object[] data) {
//Cache for senders that know they will be active
if (sender_to_receivers_cache.containsKey(sender)) {
for (IRadioWaveReceiver receiver : sender_to_receivers_cache.get(sender)) {
receiver.receiveRadioWave(hz, sender, header, data);
}
return;
}
//Receivers that have full map range, used for legacy systems mainly
for (IRadioWaveReceiver receiver : fullMapRangeReceives) {
receiver.receiveRadioWave(hz, sender, header, data);
}
//Slow way to update receives with messages
Cube range = sender.getRadioSenderRange();
if (range != null) {
//Use simpler method if the range of number of entries is small
if (//20 chunks
receive_to_chunks.size() < 200 || range.getSizeX() > 320 || range.getSizeY() > 320) {
for (IRadioWaveReceiver receiver : receive_to_chunks.keySet()) {
if (receiver != null && receiver != sender) {
Cube receiverRange = receiver.getRadioReceiverRange();
if (range.doesOverlap(receiverRange) || receiverRange.doesOverlap(range)) {
receiver.receiveRadioWave(hz, sender, header, data);
}
}
}
} else //Complex method only used if number of receive is very high, e.g. is faster~ish than the above method
{
List<ChunkCoordIntPair> coords = range.getChunkCoords();
List<IRadioWaveReceiver> receivers = new ArrayList();
for (ChunkCoordIntPair pair : coords) {
List<IRadioWaveReceiver> l = chunk_to_entities.get(pair);
if (l != null && l.size() > 0) {
for (IRadioWaveReceiver r : l) {
if (r != null && r != sender && !receivers.contains(r)) {
receivers.add(r);
}
}
}
}
for (IRadioWaveReceiver receiver : receivers) {
receiver.receiveRadioWave(hz, sender, header, data);
}
}
}
}
use of net.minecraft.world.ChunkCoordIntPair in project Engine by VoltzEngine-Project.
the class RadioMap method updateChunkCache.
protected void updateChunkCache(IRadioWaveReceiver receiver, Cube range) {
List<ChunkCoordIntPair> list = range.getChunkCoords();
//Update chunk position map
for (ChunkCoordIntPair pair : list) {
List<IRadioWaveReceiver> receivers = chunk_to_entities.get(pair);
if (receivers == null) {
receivers = new ArrayList();
}
if (!receivers.contains(receiver)) {
receivers.add(receiver);
}
chunk_to_entities.put(pair, receivers);
}
//Update receiver map
receive_to_chunks.put(receiver, list);
}
Aggregations