use of net.minecraft.util.RegistryKey in project AgriCraft by AgriCraft.
the class BlockUpdateHandler method addListener.
public void addListener(World world, BlockPos pos, IListener listener) {
if (world instanceof ServerWorld) {
RegistryKey<World> dimension = world.getDimensionKey();
this.listeners.computeIfAbsent(dimension, key -> Maps.newHashMap()).computeIfAbsent(new ChunkPos(pos), chunkPos -> Maps.newHashMap()).computeIfAbsent(pos, aPos -> Sets.newIdentityHashSet()).add(listener);
}
}
use of net.minecraft.util.RegistryKey in project AgriCraft by AgriCraft.
the class BlockUpdateHandler method onChunkUnloaded.
@SubscribeEvent
@SuppressWarnings("unused")
public void onChunkUnloaded(ChunkEvent.Unload event) {
if (event.getWorld() instanceof ServerWorld) {
ServerWorld world = (ServerWorld) event.getWorld();
RegistryKey<World> dimension = world.getDimensionKey();
if (listeners.containsKey(dimension)) {
listeners.computeIfPresent(dimension, (dim, chunkMap) -> {
if (chunkMap.containsKey(event.getChunk().getPos())) {
chunkMap.remove(event.getChunk().getPos()).forEach((pos, set) -> set.forEach(listener -> listener.onChunkUnloaded(world, pos)));
}
return chunkMap;
});
listeners.get(dimension).remove(event.getChunk().getPos());
}
}
}
Aggregations